Skip to content

Commit

Permalink
feat: add more marshaler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 22, 2022
1 parent 1246581 commit 41a2d95
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions marshaler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
package gsr

// Marshaler interface for Marshal/Unmarshal data
// Marshaler interface
type Marshaler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, ptr interface{}) error
}

// Unmarshaler interface
type Unmarshaler interface {
Unmarshal(v []byte, ptr interface{}) error
}

// DataMarshaler interface for Marshal/Unmarshal data
type DataMarshaler interface {
Marshaler
Unmarshaler
}

// MarshalFunc define
type MarshalFunc func(v interface{}) ([]byte, error)

// Marshal implements the Marshaler
func (m MarshalFunc) Marshal(v interface{}) ([]byte, error) {
return m(v)
}

// UnmarshalFunc define
type UnmarshalFunc func(v []byte, ptr interface{}) error

// Unmarshal implements the Unmarshaler
func (u UnmarshalFunc) Unmarshal(v []byte, ptr interface{}) error {
return u(v, ptr)
}

0 comments on commit 41a2d95

Please sign in to comment.