{"action":"created","issue":{"url":"https://api.github.com/repos/gogo/protobuf/issues/116","labels_url":"https://api.github.com/repos/gogo/protobuf/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/gogo/protobuf/issues/116/comments","events_url":"https://api.github.com/repos/gogo/protobuf/issues/116/events","html_url":"https://github.com/gogo/protobuf/issues/116","id":117928295,"number":116,"title":"casttype ignored when generating maps in proto2?","user":{"login":"smarterclayton","id":1163175,"avatar_url":"https://avatars.githubusercontent.com/u/1163175?v=3","gravatar_id":"","url":"https://api.github.com/users/smarterclayton","html_url":"https://github.com/smarterclayton","followers_url":"https://api.github.com/users/smarterclayton/followers","following_url":"https://api.github.com/users/smarterclayton/following{/other_user}","gists_url":"https://api.github.com/users/smarterclayton/gists{/gist_id}","starred_url":"https://api.github.com/users/smarterclayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smarterclayton/subscriptions","organizations_url":"https://api.github.com/users/smarterclayton/orgs","repos_url":"https://api.github.com/users/smarterclayton/repos","events_url":"https://api.github.com/users/smarterclayton/events{/privacy}","received_events_url":"https://api.github.com/users/smarterclayton/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-19T22:59:02Z","updated_at":"2015-11-20T14:27:12Z","closed_at":null,"body":"The following proto2 IDL\r\n\r\n```\r\n// LimitRangeItem defines a min/max usage limit for any resource that matches on kind.\r\nmessage LimitRangeItem {\r\n  ...\r\n\r\n  // Max usage constraints on this kind by resource name.\r\n  map<string, k8s.io.kubernetes.pkg.api.resource.Quantity> max = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = \"Max\", (gogoproto.casttype) = \"ResourceList\"];\r\n\r\n  ...\r\n}\r\n```\r\n\r\nwhere `ResourceList` is `map[string]*resource.Quantity`.  That results in the following Go code:\r\n\r\n```\r\n// LimitRangeItem defines a min/max usage limit for any resource that matches on kind.\r\ntype LimitRangeItem struct {\r\n\t// Max usage constraints on this kind by resource name.\r\n\tMax map[string]*k8s_io_kubernetes_pkg_api_resource.Quantity `protobuf:\"bytes,2,rep,name=max,casttype=ResourceList\" json:\"max\" protobuf_key:\"bytes,1,opt,name=key\" protobuf_val:\"bytes,2,opt,name=value\"`\r\n}\r\n```\r\n\r\nwith protoc 3.0.0 and gogoprotobuf 2093b57\r\n\r\nI would assume that the map type in the Go struct should be using the alias - and that the generated unmarshaller would cast to it, but that is not the case:\r\n\r\n```\r\n// unmarshal\r\nmapvalue := &k8s_io_kubernetes_pkg_api_resource.Quantity{}\r\nif err := mapvalue.Unmarshal(data[iNdEx:postmsgIndex]); err != nil {\r\n\treturn err\r\n}\r\niNdEx = postmsgIndex\r\nif m.Max == nil {\r\n\tm.Max = make(map[string]*k8s_io_kubernetes_pkg_api_resource.Quantity)\r\n}\r\nm.Max[mapkey] = mapvalue\r\niNdEx = postIndex\r\n```\r\n\r\nPerhaps I should not be attempting to use map with proto2 (although I noticed that there is a test for it in proto2 syntax, so I was unsure what the exact support was)."},"comment":{"url":"https://api.github.com/repos/gogo/protobuf/issues/comments/158414874","html_url":"https://github.com/gogo/protobuf/issues/116#issuecomment-158414874","issue_url":"https://api.github.com/repos/gogo/protobuf/issues/116","id":158414874,"user":{"login":"awalterschulze","id":1829933,"avatar_url":"https://avatars.githubusercontent.com/u/1829933?v=3","gravatar_id":"","url":"https://api.github.com/users/awalterschulze","html_url":"https://github.com/awalterschulze","followers_url":"https://api.github.com/users/awalterschulze/followers","following_url":"https://api.github.com/users/awalterschulze/following{/other_user}","gists_url":"https://api.github.com/users/awalterschulze/gists{/gist_id}","starred_url":"https://api.github.com/users/awalterschulze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awalterschulze/subscriptions","organizations_url":"https://api.github.com/users/awalterschulze/orgs","repos_url":"https://api.github.com/users/awalterschulze/repos","events_url":"https://api.github.com/users/awalterschulze/events{/privacy}","received_events_url":"https://api.github.com/users/awalterschulze/received_events","type":"User","site_admin":false},"created_at":"2015-11-20T14:27:12Z","updated_at":"2015-11-20T14:27:12Z","body":"Sorry for not supporting this already.  I took a bit of a shortcut with maps and oneof."}}