1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/codec/bytes/marshaler.go
Asim Aslam d94936f6c9
v3 (#2104)
* v3

* revert plugins

* fixup some issues
2021-01-20 13:54:31 +00:00

39 lines
620 B
Go

package bytes
import (
"github.com/asim/go-micro/v3/codec"
)
type Marshaler struct{}
type Message struct {
Header map[string]string
Body []byte
}
func (n Marshaler) Marshal(v interface{}) ([]byte, error) {
switch ve := v.(type) {
case *[]byte:
return *ve, nil
case []byte:
return ve, nil
case *Message:
return ve.Body, nil
}
return nil, codec.ErrInvalidMessage
}
func (n Marshaler) Unmarshal(d []byte, v interface{}) error {
switch ve := v.(type) {
case *[]byte:
*ve = d
case *Message:
ve.Body = d
}
return codec.ErrInvalidMessage
}
func (n Marshaler) String() string {
return "bytes"
}