msgpack
msgpack copied to clipboard
types: prefer TextUnmarshaler over BinaryUnmarshaler for str format
Fixes #370. For types implementing both BinaryUnmarshaler and TextUnmarshaler, peek at the wire format and use TextUnmarshaler for msgpack str and BinaryUnmarshaler for everything else.
Hi @alliasgher, nice fix. Heads up that this repo has been unmaintained for ~3 years and PRs have been piling up.
We maintain an active fork at github.com/Basekick-Labs/msgpack (v6) where we already handle this case — decode_value.go:269-281 peeks at the wire format and routes to TextUnmarshaler for str and BinaryUnmarshaler for everything else:
func unmarshalBinaryOrTextValue(d *Decoder, v reflect.Value) error {
c, err := d.PeekCode()
if err != nil {
return err
}
if msgpcode.IsString(c) {
return unmarshalTextValue(d, v)
}
return unmarshalBinaryValue(d, v)
}
If upstream doesn't pick this up, feel free to port it to the fork — contributions welcome.