You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in the process of upgrading from your now-deprecated go-msgpack library, where I was using the convenience methods Marshal and Unmarshal. Using this new library, Encode works as a perfect drop in replacement for Marshal, but when I try to decode I get the following runtime error:
"interface is []uint8, not string"
where casting to a string (as it was encoding as a string) worked before. Is this a bug, or has the usage changed?
Yes, previously RawToString was set to true when you created a new DecodeOptions. But I didn't like the automatic conversion.
So now, you have to set it directly (when decoding into a nil interface{}). In your code somewhere (init method, etc), set RawToString option on MsgpackHandle. E.g.
var mh = codec.MsgpackHandle{ RawToString: true }
OR
var mh codec.MsgpackHandle
mh.RawToString = true
Hi there--thanks for providing this library!
I'm in the process of upgrading from your now-deprecated go-msgpack library, where I was using the convenience methods Marshal and Unmarshal. Using this new library, Encode works as a perfect drop in replacement for Marshal, but when I try to decode I get the following runtime error:
"interface is []uint8, not string"
where casting to a string (as it was encoding as a string) worked before. Is this a bug, or has the usage changed?
My Marshal/Unmarshal replacement are:
var mh codec.MsgpackHandle
//Convenience methods for simple encoding/decoding
func MsgpackEncode(val interface{}) (packed []byte, err error) {
enc := codec.NewEncoderBytes(&packed, &mh)
err = enc.Encode(val)
return
}
func MsgpackDecode(packed []byte, val interface{}) (err error) {
dec := codec.NewDecoderBytes(packed, &mh)
err = dec.Decode(&val)
return
}
Appreciate the help.
The text was updated successfully, but these errors were encountered: