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

Encode Decode map[string]interface{} type #35

Closed
Gohan opened this issue Sep 24, 2014 · 1 comment
Closed

Encode Decode map[string]interface{} type #35

Gohan opened this issue Sep 24, 2014 · 1 comment

Comments

@Gohan
Copy link

Gohan commented Sep 24, 2014

since this library support map[string]interface{} type, I tried to use it for pacakge struct, what I find is that decode/encode data dismatch, my test code:

func TestCodec(t *testing.T) {
    var (
        mh  codec.MsgpackHandle
        rw  bytes.Buffer
    )
    mh.MapType = reflect.TypeOf(map[string]interface{}(nil))
    enc := codec.NewEncoder(&rw, &mh)

    item := make(map[string]interface{})
    item["key"] = int32(123)
    item["key2"] = "string"

    err := enc.Encode(&item)
    if err == nil {
        t.Log("Encode OK", "type", reflect.TypeOf(item["key"]), reflect.TypeOf(item["key2"]))
    }

    var item_decoded map[string]interface{}

    dec := codec.NewDecoder(&rw, &mh)
    err = dec.Decode(&item_decoded)
    if err == nil {
        t.Log("Decode OK", "type", reflect.TypeOf(item_decoded["key"]), reflect.TypeOf(item_decoded["key2"]))
    }
}

the result:

proto_test.go:63: Encode OK type int32 string
proto_test.go:71: Decode OK type int64 []uint8

update:

I change the handle config mh.RawToString = true, now the int type still not match:

proto_test.go:64: Encode OK type int32 string
proto_test.go:72: Decode OK type int64 string

msgpack spec include int8 int16 int32 many int families, this result make me confuse.

@Gohan
Copy link
Author

Gohan commented Sep 24, 2014

It is my fault that I misunderstanding the encode decode process, msgpack don't distinguish source type is either int32 or int64. I'll close this issue

@Gohan Gohan closed this as completed Sep 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant