2016-12-06 21:37:35 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2016-12-06 21:59:41 +03:00
|
|
|
"github.com/micro/go-micro/broker/codec"
|
2016-12-06 21:37:35 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type jsonCodec struct{}
|
|
|
|
|
|
|
|
func (j jsonCodec) Marshal(v interface{}) ([]byte, error) {
|
|
|
|
return json.Marshal(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j jsonCodec) Unmarshal(d []byte, v interface{}) error {
|
|
|
|
return json.Unmarshal(d, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j jsonCodec) String() string {
|
|
|
|
return "json"
|
|
|
|
}
|
|
|
|
|
2016-12-06 21:59:41 +03:00
|
|
|
func NewCodec() codec.Codec {
|
2016-12-06 21:37:35 +03:00
|
|
|
return jsonCodec{}
|
|
|
|
}
|