cacheinterface/encoder/binary.go
Tyler 41d0ef3d97
Some checks failed
continuous-integration/drone Build is failing
Initial v2 version, better testing, updates
2023-02-04 20:22:41 -05:00

33 lines
497 B
Go

package encoder
func EncodeValue(encoder Encoder, val any) ([]byte, error) {
var v []byte
if b, ok := val.([]byte); ok {
v = b
} else if s, ok := val.(string); ok {
b = []byte(s)
} else {
return encoder.Marshal(val)
}
return v, nil
}
func DecodeValue(encoder Encoder, b []byte, v any) error {
switch v := v.(type) {
case *[]byte:
if v != nil {
*v = b
return nil
}
case *string:
if v != nil {
*v = string(b)
return nil
}
}
return encoder.Unmarshal(b, v)
}