ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.85k stars 295 forks source link

codec.MsgpackHandle.RawToString is confusingly named #387

Closed amnonbc closed 1 year ago

amnonbc commented 1 year ago

https://github.com/ugorji/go/blob/3cfaa077b94e38bae0008f229b2d7a565cc29e96/codec/decode.go#L316-L319 states

    // RawToString controls how raw bytes in a stream are decoded into a nil interface{}.
    // By default, they are decoded as []byte, but can be decoded as string (if configured).
    RawToString bool

But in the old msgpack spec the raw types have op-codes 0xda for raw 16, oxdb for raw 32, and anything starting with the binary prefix 101 for fix raw. These opcodes are equal to the corresponding string types in the new spec.

What the RawToString flag does is it forces Binary types bin8, bin16, bin32 to be decoded as the corresponding string type. It would be less confusing if RawToString was renamed BinToString. Changing the name at this point is probably not worth the pain. But It would be useful if the comment was updated.

ugorji commented 1 year ago

RawToString is a flag for every handle (including json, cbor, msgpack, etc). This is why it's under BasicHandle. We cannot add commentary that is specific to any one handle in there.

The msgpack specific flags will be under MsgpackHandle (eg WriteExt, NoFixedNum, etc)

ugorji commented 1 year ago

closing - see message above