27 lines
398 B
Go
27 lines
398 B
Go
|
package database
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
type encoded_value interface {
|
||
|
MarshalBinary() ([]byte, error)
|
||
|
}
|
||
|
|
||
|
type decoded_value interface {
|
||
|
UnmarshalBinary(bs []byte) error
|
||
|
}
|
||
|
|
||
|
func handleValue(value any) ([]byte, error) {
|
||
|
var (
|
||
|
bs []byte
|
||
|
err error
|
||
|
)
|
||
|
|
||
|
if imp, ok := value.(encoded_value); ok {
|
||
|
bs, err = imp.MarshalBinary()
|
||
|
} else {
|
||
|
bs, err = json.Marshal(value)
|
||
|
}
|
||
|
|
||
|
return bs, err
|
||
|
}
|