16 lines
304 B
Go
16 lines
304 B
Go
package codec
|
|
|
|
type Codec interface {
|
|
Decode(data []byte, out any) error
|
|
Encode(data any) ([]byte, error)
|
|
}
|
|
|
|
func Decode[T any](c Codec, data []byte) (T, error) {
|
|
var out T
|
|
err := c.Decode(data, &out)
|
|
return out, err
|
|
}
|
|
|
|
func Encode[T any](c Codec, data T) ([]byte, error) {
|
|
return c.Encode(data)
|
|
}
|