24 lines
434 B
Go
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)
|
||
|
}
|