add transport codec

This commit is contained in:
Asim Aslam
2016-12-06 18:56:57 +00:00
parent bd3c798fd9
commit 49e5636bcd
4 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package noop
import (
"errors"
"github.com/micro/go-micro/transport"
"github.com/micro/go-micro/transport/codec"
)
type noopCodec struct{}
func (n noopCodec) Marshal(v interface{}) ([]byte, error) {
msg, ok := v.(*transport.Message)
if !ok {
return nil, errors.New("invalid message")
}
return msg.Body, nil
}
func (n noopCodec) Unmarshal(d []byte, v interface{}) error {
msg, ok := v.(*transport.Message)
if !ok {
return errors.New("invalid message")
}
msg.Body = d
return nil
}
func (n noopCodec) String() string {
return "noop"
}
func NewCodec() codec.Codec {
return noopCodec{}
}