Add base
This commit is contained in:
24
codec/json.go
Normal file
24
codec/json.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user