{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/protobuf/issues/20","labels_url":"https://api.github.com/repos/golang/protobuf/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/golang/protobuf/issues/20/comments","events_url":"https://api.github.com/repos/golang/protobuf/issues/20/events","html_url":"https://github.com/golang/protobuf/issues/20","id":62034545,"number":20,"title":"proto3 map empty bytes","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},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-16T10:15:56Z","updated_at":"2015-03-16T10:15:56Z","closed_at":null,"body":"Add this to proto3.proto in proto/proto3_proto\r\n\r\n```\r\nmessage MessageWithMappy {\r\n  map<bool, bytes> byte_mapping = 3;\r\n}\r\n```\r\n\r\nand run the Makefile in proto/proto3_proto\r\n\r\nThen add this to size_test.go\r\n\r\n```\r\n{\"map field with zero bytes\", &proto3pb.MessageWithMappy{\r\n\t\tByteMapping: map[bool][]byte{\r\n\t\t\tfalse: []byte{},\r\n\t\t\ttrue:  []byte{0x84, 0x78, 0x8e, 0x33, 0xcd, 0x12, 0x65, 0xa0, 0xd2, 0xca, 0xc4, 0xcd, 0x12, 0xe2, 0xcf, 0xf1, 0xbf, 0xfa, 0xf7, 0x5a, 0x3c, 0x6d, 0xdc, 0xcf, 0x9c, 0x92, 0x94, 0x3f, 0x4f, 0xb6, 0x31, 0x77, 0xe3, 0xda, 0x3f, 0x1b, 0x8e, 0x39, 0xe6, 0xa, 0x81, 0x61, 0xf0, 0xba, 0x74, 0x6},\r\n\t\t},\r\n\t}},\r\n```\r\n\r\nThis gives the following failure\r\n\r\nsize_test.go:138: map field with zero bytes: Size(byte_mapping:<key:false value:\"\" > byte_mapping:<key:true value:\"\\204x\\2163\\315\\022e\\240\\322\\312\\304\\315\\022\\342\\317\\361\\277\\372\\367Z<m\\334\\317\\234\\222\\224?O\\2661w\\343\\332?\\033\\2169\\346\\n\\201a\\360\\272t\\006\" > ) = 56, want 7\r\n\tsize_test.go:139: map field with zero bytes: bytes: []byte{0x1a, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0}\r\n\r\nThe error only happens with an empty byte slice.\r\n\r\nThis is probably a mistake in the way the map values try to reuse the setEncAndDec function with a combination of the proto3 syntax\r\n\r\n```\r\ncase reflect.Uint8:\r\n\t\t\tp.enc = (*Buffer).enc_slice_byte\r\n\t\t\tp.dec = (*Buffer).dec_slice_byte\r\n\t\t\tp.size = size_slice_byte\r\n\t\t\tif p.proto3 {\r\n\t\t\t\tp.enc = (*Buffer).enc_proto3_slice_byte\r\n\t\t\t\tp.size = size_proto3_slice_byte\r\n\t\t\t}\r\n```\r\n\r\nMaybe this should be\r\n\r\n```\r\ncase reflect.Uint8:\r\n\t\t\tp.enc = (*Buffer).enc_slice_byte\r\n\t\t\tp.dec = (*Buffer).dec_slice_byte\r\n\t\t\tp.size = size_slice_byte\r\n\t\t\tif p.proto3 && notamapvalue {\r\n\t\t\t\tp.enc = (*Buffer).enc_proto3_slice_byte\r\n\t\t\t\tp.size = size_proto3_slice_byte\r\n\t\t\t}\r\n```"}}