msgpack icon indicating copy to clipboard operation
msgpack copied to clipboard

types: prefer TextUnmarshaler over BinaryUnmarshaler for str format

Open alliasgher opened this issue 7 months ago • 1 comments

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.

alliasgher avatar Apr 14 '26 11:04 alliasgher

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.

xe-nvdk avatar Apr 14 '26 13:04 xe-nvdk