ceen/codec/json.go

25 lines
348 B
Go
Raw Normal View History

2022-06-16 22:19:06 +02:00
package codec
import "encoding/json"
var (
JSON Codec = &jsonCodec{}
)
type jsonCodec struct{}
func (*jsonCodec) Name() string {
return "json"
}
func (*jsonCodec) Marshal(v any) ([]byte, error) {
return json.Marshal(v)
}
func (*jsonCodec) Unmarshal(b []byte, v any) error {
if len(b) == 0 {
return nil
}
return json.Unmarshal(b, v)
}