2016-12-06 18:37:35 +00:00
|
|
|
package noop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/micro/go-micro/broker"
|
2016-12-06 18:59:41 +00:00
|
|
|
"github.com/micro/go-micro/broker/codec"
|
2016-12-06 18:37:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type noopCodec struct{}
|
|
|
|
|
|
|
|
func (n noopCodec) Marshal(v interface{}) ([]byte, error) {
|
|
|
|
msg, ok := v.(*broker.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.(*broker.Message)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("invalid message")
|
|
|
|
}
|
|
|
|
msg.Body = d
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n noopCodec) String() string {
|
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
2016-12-06 18:59:41 +00:00
|
|
|
func NewCodec() codec.Codec {
|
2016-12-06 18:37:35 +00:00
|
|
|
return noopCodec{}
|
|
|
|
}
|