Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode issue: interface is []uint8, not string #1

Closed
finkel opened this issue Jun 4, 2013 · 2 comments
Closed

Decode issue: interface is []uint8, not string #1

finkel opened this issue Jun 4, 2013 · 2 comments

Comments

@finkel
Copy link

finkel commented Jun 4, 2013

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.

@ugorji
Copy link
Owner

ugorji commented Jun 4, 2013

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

@finkel
Copy link
Author

finkel commented Jun 4, 2013

Perfect! Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants