etcdb/codec.go
2022-12-05 11:11:22 +01:00

24 lines
434 B
Go

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)
}