package codec import ( "encoding/json" "github.com/noahlann/nnet/pkg/codec" ) // JSONCodec JSON编解码器 type JSONCodec struct{} // NewJSONCodec 创建JSON编解码器 func NewJSONCodec() codec.Codec { return &JSONCodec{} } // Encode 编码 func (c *JSONCodec) Encode(v interface{}) ([]byte, error) { return json.Marshal(v) } // Decode 解码 func (c *JSONCodec) Decode(data []byte, v interface{}) error { return json.Unmarshal(data, v) } // Name 获取编解码器名称 func (c *JSONCodec) Name() string { return "json" }