{"action":"created","issue":{"url":"https://api.github.com/repos/vmihailenco/msgpack/issues/182","repository_url":"https://api.github.com/repos/vmihailenco/msgpack","labels_url":"https://api.github.com/repos/vmihailenco/msgpack/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/vmihailenco/msgpack/issues/182/comments","events_url":"https://api.github.com/repos/vmihailenco/msgpack/issues/182/events","html_url":"https://github.com/vmihailenco/msgpack/issues/182","id":314404909,"number":182,"title":"type conversion problem on Map inside another Map","user":{"login":"LuttyYang","id":14296262,"avatar_url":"https://avatars0.githubusercontent.com/u/14296262?v=4","gravatar_id":"","url":"https://api.github.com/users/LuttyYang","html_url":"https://github.com/LuttyYang","followers_url":"https://api.github.com/users/LuttyYang/followers","following_url":"https://api.github.com/users/LuttyYang/following{/other_user}","gists_url":"https://api.github.com/users/LuttyYang/gists{/gist_id}","starred_url":"https://api.github.com/users/LuttyYang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LuttyYang/subscriptions","organizations_url":"https://api.github.com/users/LuttyYang/orgs","repos_url":"https://api.github.com/users/LuttyYang/repos","events_url":"https://api.github.com/users/LuttyYang/events{/privacy}","received_events_url":"https://api.github.com/users/LuttyYang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-15T10:49:18Z","updated_at":"2018-04-16T07:03:27Z","closed_at":null,"author_association":"NONE","body":"When I try this code, I found a error...\r\n\r\n```\r\n\tpacked, err := msgpack.Marshal(map[string]interface{}{\r\n\t\t\"test\": map[int]interface{}{\r\n\t\t\t1: \"one\",\r\n\t\t\t2: \"two\",\r\n\t\t},\r\n\t})\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\tvar test = make(map[string]interface{})\r\n\terr = msgpack.Unmarshal(packed, &test)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\tfmt.Printf(\"%#v\", test)\r\n```\r\n\r\nerror message:\r\n```\r\npanic: msgpack: invalid code=0 decoding bytes length\r\n```"},"comment":{"url":"https://api.github.com/repos/vmihailenco/msgpack/issues/comments/381499582","html_url":"https://github.com/vmihailenco/msgpack/issues/182#issuecomment-381499582","issue_url":"https://api.github.com/repos/vmihailenco/msgpack/issues/182","id":381499582,"user":{"login":"vmihailenco","id":290976,"avatar_url":"https://avatars2.githubusercontent.com/u/290976?v=4","gravatar_id":"","url":"https://api.github.com/users/vmihailenco","html_url":"https://github.com/vmihailenco","followers_url":"https://api.github.com/users/vmihailenco/followers","following_url":"https://api.github.com/users/vmihailenco/following{/other_user}","gists_url":"https://api.github.com/users/vmihailenco/gists{/gist_id}","starred_url":"https://api.github.com/users/vmihailenco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmihailenco/subscriptions","organizations_url":"https://api.github.com/users/vmihailenco/orgs","repos_url":"https://api.github.com/users/vmihailenco/repos","events_url":"https://api.github.com/users/vmihailenco/events{/privacy}","received_events_url":"https://api.github.com/users/vmihailenco/received_events","type":"User","site_admin":false},"created_at":"2018-04-16T07:03:27Z","updated_at":"2018-04-16T07:03:27Z","author_association":"OWNER","body":"By default this lib decodes map as `map[string]interface{}`, but you have `map[int]interface{}`. As the fix you can try to decode into `map[interface{}]interface{}`\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"bytes\"\r\n\t\"fmt\"\r\n\r\n\t\"github.com/vmihailenco/msgpack\"\r\n)\r\n\r\nfunc main() {\r\n\tpacked, err := msgpack.Marshal(map[string]interface{}{\r\n\t\t\"test\": map[int]interface{}{\r\n\t\t\t1: \"one\",\r\n\t\t\t2: \"two\",\r\n\t\t},\r\n\t})\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\tvar test = make(map[interface{}]interface{})\r\n\tdec := newDecoder(bytes.NewBuffer(packed))\r\n\terr = dec.Decode(&test)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\tfmt.Printf(\"%#v\", test)\r\n}\r\n\r\nfunc newDecoder(buf *bytes.Buffer) *msgpack.Decoder {\r\n\tdec := msgpack.NewDecoder(buf)\r\n\r\n\t// Causes decoder to produce map[string]string instead of map[string]interface{}.\r\n\tdec.SetDecodeMapFunc(func(d *msgpack.Decoder) (interface{}, error) {\r\n\t\tn, err := d.DecodeMapLen()\r\n\t\tif err != nil {\r\n\t\t\treturn nil, err\r\n\t\t}\r\n\r\n\t\tm := make(map[interface{}]interface{}, n)\r\n\t\tfor i := 0; i < n; i++ {\r\n\t\t\tmk, err := d.DecodeInterface()\r\n\t\t\tif err != nil {\r\n\t\t\t\treturn nil, err\r\n\t\t\t}\r\n\r\n\t\t\tmv, err := d.DecodeInterface()\r\n\t\t\tif err != nil {\r\n\t\t\t\treturn nil, err\r\n\t\t\t}\r\n\r\n\t\t\tm[mk] = mv\r\n\t\t}\r\n\t\treturn m, nil\r\n\t})\r\n\r\n\treturn dec\r\n}\r\n```"}}
{"actor":{"display_login":"vmihailenco"}}