etcdb/codec.go

24 lines
434 B
Go
Raw Normal View History

2022-12-05 09:26:49 +00:00
package etcdb
import (
"encoding/json"
)
type Codec interface {
Encode(v any) ([]byte, error)
Decode(raw []byte, v any) error
}
// ------------------------------------------------------------------------
type jsonCodec struct{}
var JSONCodec Codec = jsonCodec{}
func (_ jsonCodec) Encode(v any) ([]byte, error) {
return json.Marshal(v)
}
func (_ jsonCodec) Decode(raw []byte, v any) error {
return json.Unmarshal(raw, v)
}