ugorji/go

codec.MsgpackHandle.RawToString is confusingly named

amnonbc opened this issue · 2 comments

go/codec/decode.go

Lines 316 to 319 in 3cfaa07

// 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

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.

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)

closing - see message above