{"action":"created","comment":{"url":"https://api.github.com/repos/tinylib/msgp/pulls/comments/71021287","id":71021287,"diff_hunk":"@@ -199,6 +224,176 @@ type traversal interface {\n \tgStruct(*Struct)\n }\n \n+type declarer interface {\n+\tdeclareOnce(p printer, name, typ string)\n+}\n+\n+type assigner interface {\n+\tassignAndCheck(name, base string)\n+\tnextTypeAndCheck(name string)\n+\tskipAndCheck()\n+}\n+\n+type fuser interface {\n+\tFuse([]byte)\n+}\n+\n+type traversalAssigner interface {\n+\ttraversal\n+\tassigner\n+\tdeclarer\n+}\n+\n+type traversalFuser interface {\n+\ttraversal\n+\tfuser\n+}\n+\n+func genStructFieldsSerializer(t traversalFuser, p printer, fields []StructField) {\n+\tdata := msgp.AppendMapHeader(nil, uint32(len(fields)))\n+\tp.printf(\"\\n// map header, size %d\", len(fields))\n+\tt.Fuse(data)\n+\tfor _, f := range fields {\n+\t\tif !p.ok() {\n+\t\t\treturn\n+\t\t}\n+\n+\t\tdata, p.err = msgp.AppendIntf(nil, f.FieldTag)\n+\t\tp.printf(\n+\t\t\t\"\\n// [field %q] write label `%v` as msgp.%s\",\n+\t\t\tf.FieldName, f.FieldTag, msgp.NextType(data),\n+\t\t)\n+\t\tt.Fuse(data)\n+\n+\t\tnext(t, f.FieldElem)\n+\t}\n+}\n+\n+func genStructFieldsParser(t traversalAssigner, p printer, fields []StructField) {\n+\tconst (\n+\t\tfieldBytes = \"field_b\"\n+\t\tfieldInt   = \"field_i\"\n+\t\tfieldUint  = \"field_u\"\n+\t\ttyp        = \"typ\"\n+\t)\n+\n+\tgroups := groupFieldsByType(fields)\n+\thasUint := len(groups[msgp.UintType]) > 0\n+\thasInt := len(groups[msgp.IntType]) > 0\n+\thasStr := len(groups[msgp.StrType]) > 0\n+\tsingleType := len(groups) == 1\n+\n+\tif hasStr {\n+\t\tt.declareOnce(p, fieldBytes, \"[]byte\")\n+\t}\n+\tif hasUint {\n+\t\tt.declareOnce(p, fieldUint, \"uint64\")\n+\n+\t\t// Append to int fields also uint fields that do not overflow int64.\n+\t\t// This is necessary because uint field with value <= (1<<7)-1 could be serialized as fixint.\n+\t\t// and become a msgp.IntType. This is done for best compatibility with other libraries\n+\t\t// (and with other languages). That is, some endpoint could serialize uint16 key with value <= (1<<7)-1 as\n+\t\t// real msgpack uint16, but also could serialize it like fixint.\n+\t\tfor _, f := range groups[msgp.UintType] {\n+\t\t\tv := f.FieldTag.(uint64)\n+\t\t\tif v <= math.MaxInt64 {\n+\t\t\t\tgroups[msgp.IntType] = append(groups[msgp.IntType], f)\n+\t\t\t\thasInt = true\n+\t\t\t}\n+\t\t}\n+\t}\n+\tif hasInt {\n+\t\tt.declareOnce(p, fieldInt, \"int64\")\n+\t}\n+\tif !singleType || hasUint {\n+\t\tt.declareOnce(p, typ, \"msgp.Type\")\n+\t}\n+\n+\tsz := randIdent()\n+\tp.declare(sz, u32)\n+\tt.assignAndCheck(sz, mapHeader)\n+\tp.printf(\"\\nfor %s > 0 {\\n%s--\", sz, sz)\n+\tswitch {\n+\tcase singleType && hasStr:\n+\t\tt.assignAndCheck(fieldBytes, mapKey)\n+\t\tswitchFieldKeysStr(t, p, fields, fieldBytes)\n+\tcase singleType && hasInt:\n+\t\tt.assignAndCheck(fieldInt, \"Int64\")\n+\t\tswitchFieldKeys(t, p, fields, fieldInt)\n+\tdefault:\n+\t\t// switch on inferred type of next field\n+\t\tt.nextTypeAndCheck(typ)\n+\t\tp.printf(\"\\nswitch %s {\", typ)\n+\t\tif hasUint {\n+\t\t\tp.print(\"\\ncase msgp.UintType:\")\n+\t\t\tt.assignAndCheck(fieldUint, \"Uint64\")\n+\t\t\tswitchFieldKeys(t, p, groups[msgp.UintType], fieldUint)\n+\t\t}\n+\t\tif hasInt {\n+\t\t\tp.print(\"\\ncase msgp.IntType:\")\n+\t\t\tt.assignAndCheck(fieldInt, \"Int64\")\n+\t\t\tswitchFieldKeys(t, p, groups[msgp.IntType], fieldInt)\n+\t\t}\n+\t\tif hasStr {\n+\t\t\t// double case is done for backward compatibility with previous implementation\n+\t\t\tp.print(\"\\ncase msgp.StrType, msgp.BinType:\")\n+\t\t\tt.assignAndCheck(fieldBytes, mapKey)\n+\t\t\tswitchFieldKeysStr(t, p, groups[msgp.StrType], fieldBytes)\n+\t\t}\n+\t\tp.print(\"\\ndefault:\")\n+\t\tt.skipAndCheck()\n+\t\tp.closeblock() // close switch\n+\t}\n+\tp.closeblock() // close loop\n+}\n+\n+func groupFieldsByType(fields []StructField) map[msgp.Type][]StructField {\n+\tgroups := make(map[msgp.Type][]StructField, len(fields))\n+\tfor _, f := range fields {\n+\t\tvar t msgp.Type\n+\t\tswitch f.FieldTag.(type) {\n+\t\tcase int, int8, int16, int32, int64:\n+\t\t\tt = msgp.IntType\n+\t\tcase uint, uint8, uint16, uint32, uint64:\n+\t\t\tt = msgp.UintType\n+\t\tcase string:\n+\t\t\tt = msgp.StrType\n+\t\tdefault:\n+\t\t\tpanic(fmt.Errorf(\"field %q has unknown tag type %T\", f.FieldName, f.FieldTag))","path":"gen/spec.go","position":187,"original_position":187,"commit_id":"f7c196e11b50d360ba131a4012b649acc64bf367","original_commit_id":"f7c196e11b50d360ba131a4012b649acc64bf367","user":{"login":"philhofer","id":2940902,"avatar_url":"https://avatars.githubusercontent.com/u/2940902?v=3","gravatar_id":"","url":"https://api.github.com/users/philhofer","html_url":"https://github.com/philhofer","followers_url":"https://api.github.com/users/philhofer/followers","following_url":"https://api.github.com/users/philhofer/following{/other_user}","gists_url":"https://api.github.com/users/philhofer/gists{/gist_id}","starred_url":"https://api.github.com/users/philhofer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philhofer/subscriptions","organizations_url":"https://api.github.com/users/philhofer/orgs","repos_url":"https://api.github.com/users/philhofer/repos","events_url":"https://api.github.com/users/philhofer/events{/privacy}","received_events_url":"https://api.github.com/users/philhofer/received_events","type":"User","site_admin":false},"body":"Don't panic here; print an error and exit. Same goes for field label parsing.","created_at":"2016-07-15T18:38:36Z","updated_at":"2016-07-15T18:38:36Z","html_url":"https://github.com/tinylib/msgp/pull/160#discussion_r71021287","pull_request_url":"https://api.github.com/repos/tinylib/msgp/pulls/160","_links":{"self":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/comments/71021287"},"html":{"href":"https://github.com/tinylib/msgp/pull/160#discussion_r71021287"},"pull_request":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/160"}}},"pull_request":{"url":"https://api.github.com/repos/tinylib/msgp/pulls/160","id":77605502,"html_url":"https://github.com/tinylib/msgp/pull/160","diff_url":"https://github.com/tinylib/msgp/pull/160.diff","patch_url":"https://github.com/tinylib/msgp/pull/160.patch","issue_url":"https://api.github.com/repos/tinylib/msgp/issues/160","number":160,"state":"open","locked":false,"title":"Struct fields numeric labels","user":{"login":"gobwas","id":675117,"avatar_url":"https://avatars.githubusercontent.com/u/675117?v=3","gravatar_id":"","url":"https://api.github.com/users/gobwas","html_url":"https://github.com/gobwas","followers_url":"https://api.github.com/users/gobwas/followers","following_url":"https://api.github.com/users/gobwas/following{/other_user}","gists_url":"https://api.github.com/users/gobwas/gists{/gist_id}","starred_url":"https://api.github.com/users/gobwas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gobwas/subscriptions","organizations_url":"https://api.github.com/users/gobwas/orgs","repos_url":"https://api.github.com/users/gobwas/repos","events_url":"https://api.github.com/users/gobwas/events{/privacy}","received_events_url":"https://api.github.com/users/gobwas/received_events","type":"User","site_admin":false},"body":"Hello! \r\n\r\nThis pull request is about [this issue](https://github.com/tinylib/msgp/issues/159).\r\n\r\nI think it could be useful. Some integration protocols use scheme, when map keys are numerical (`int` or `uint`), for example, to reduce network usage and other performance needs.\r\n\r\nRegards,\r\nSergey.\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/tinylib/msgp/160)\n<!-- Reviewable:end -->\n","created_at":"2016-07-15T12:06:48Z","updated_at":"2016-07-15T18:38:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f91a2dea90c772c2f32d86c0232302c3d5463219","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/tinylib/msgp/pulls/160/commits","review_comments_url":"https://api.github.com/repos/tinylib/msgp/pulls/160/comments","review_comment_url":"https://api.github.com/repos/tinylib/msgp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tinylib/msgp/issues/160/comments","statuses_url":"https://api.github.com/repos/tinylib/msgp/statuses/f7c196e11b50d360ba131a4012b649acc64bf367","head":{"label":"gobwas:feature/map_numeric_keys","ref":"feature/map_numeric_keys","sha":"f7c196e11b50d360ba131a4012b649acc64bf367","user":{"login":"gobwas","id":675117,"avatar_url":"https://avatars.githubusercontent.com/u/675117?v=3","gravatar_id":"","url":"https://api.github.com/users/gobwas","html_url":"https://github.com/gobwas","followers_url":"https://api.github.com/users/gobwas/followers","following_url":"https://api.github.com/users/gobwas/following{/other_user}","gists_url":"https://api.github.com/users/gobwas/gists{/gist_id}","starred_url":"https://api.github.com/users/gobwas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gobwas/subscriptions","organizations_url":"https://api.github.com/users/gobwas/orgs","repos_url":"https://api.github.com/users/gobwas/repos","events_url":"https://api.github.com/users/gobwas/events{/privacy}","received_events_url":"https://api.github.com/users/gobwas/received_events","type":"User","site_admin":false},"repo":{"id":63353930,"name":"msgp","full_name":"gobwas/msgp","owner":{"login":"gobwas","id":675117,"avatar_url":"https://avatars.githubusercontent.com/u/675117?v=3","gravatar_id":"","url":"https://api.github.com/users/gobwas","html_url":"https://github.com/gobwas","followers_url":"https://api.github.com/users/gobwas/followers","following_url":"https://api.github.com/users/gobwas/following{/other_user}","gists_url":"https://api.github.com/users/gobwas/gists{/gist_id}","starred_url":"https://api.github.com/users/gobwas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gobwas/subscriptions","organizations_url":"https://api.github.com/users/gobwas/orgs","repos_url":"https://api.github.com/users/gobwas/repos","events_url":"https://api.github.com/users/gobwas/events{/privacy}","received_events_url":"https://api.github.com/users/gobwas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gobwas/msgp","description":"A Go code generator for MessagePack / msgpack.org[Go]","fork":true,"url":"https://api.github.com/repos/gobwas/msgp","forks_url":"https://api.github.com/repos/gobwas/msgp/forks","keys_url":"https://api.github.com/repos/gobwas/msgp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gobwas/msgp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gobwas/msgp/teams","hooks_url":"https://api.github.com/repos/gobwas/msgp/hooks","issue_events_url":"https://api.github.com/repos/gobwas/msgp/issues/events{/number}","events_url":"https://api.github.com/repos/gobwas/msgp/events","assignees_url":"https://api.github.com/repos/gobwas/msgp/assignees{/user}","branches_url":"https://api.github.com/repos/gobwas/msgp/branches{/branch}","tags_url":"https://api.github.com/repos/gobwas/msgp/tags","blobs_url":"https://api.github.com/repos/gobwas/msgp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gobwas/msgp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gobwas/msgp/git/refs{/sha}","trees_url":"https://api.github.com/repos/gobwas/msgp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gobwas/msgp/statuses/{sha}","languages_url":"https://api.github.com/repos/gobwas/msgp/languages","stargazers_url":"https://api.github.com/repos/gobwas/msgp/stargazers","contributors_url":"https://api.github.com/repos/gobwas/msgp/contributors","subscribers_url":"https://api.github.com/repos/gobwas/msgp/subscribers","subscription_url":"https://api.github.com/repos/gobwas/msgp/subscription","commits_url":"https://api.github.com/repos/gobwas/msgp/commits{/sha}","git_commits_url":"https://api.github.com/repos/gobwas/msgp/git/commits{/sha}","comments_url":"https://api.github.com/repos/gobwas/msgp/comments{/number}","issue_comment_url":"https://api.github.com/repos/gobwas/msgp/issues/comments{/number}","contents_url":"https://api.github.com/repos/gobwas/msgp/contents/{+path}","compare_url":"https://api.github.com/repos/gobwas/msgp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gobwas/msgp/merges","archive_url":"https://api.github.com/repos/gobwas/msgp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gobwas/msgp/downloads","issues_url":"https://api.github.com/repos/gobwas/msgp/issues{/number}","pulls_url":"https://api.github.com/repos/gobwas/msgp/pulls{/number}","milestones_url":"https://api.github.com/repos/gobwas/msgp/milestones{/number}","notifications_url":"https://api.github.com/repos/gobwas/msgp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gobwas/msgp/labels{/name}","releases_url":"https://api.github.com/repos/gobwas/msgp/releases{/id}","deployments_url":"https://api.github.com/repos/gobwas/msgp/deployments","created_at":"2016-07-14T16:53:53Z","updated_at":"2016-07-14T16:53:55Z","pushed_at":"2016-07-15T12:02:37Z","git_url":"git://github.com/gobwas/msgp.git","ssh_url":"git@github.com:gobwas/msgp.git","clone_url":"https://github.com/gobwas/msgp.git","svn_url":"https://github.com/gobwas/msgp","homepage":"","size":8885,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tinylib:master","ref":"master","sha":"05e600edf28f1b907005ddf6b0488fe68b819971","user":{"login":"tinylib","id":10499993,"avatar_url":"https://avatars.githubusercontent.com/u/10499993?v=3","gravatar_id":"","url":"https://api.github.com/users/tinylib","html_url":"https://github.com/tinylib","followers_url":"https://api.github.com/users/tinylib/followers","following_url":"https://api.github.com/users/tinylib/following{/other_user}","gists_url":"https://api.github.com/users/tinylib/gists{/gist_id}","starred_url":"https://api.github.com/users/tinylib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tinylib/subscriptions","organizations_url":"https://api.github.com/users/tinylib/orgs","repos_url":"https://api.github.com/users/tinylib/repos","events_url":"https://api.github.com/users/tinylib/events{/privacy}","received_events_url":"https://api.github.com/users/tinylib/received_events","type":"Organization","site_admin":false},"repo":{"id":23944963,"name":"msgp","full_name":"tinylib/msgp","owner":{"login":"tinylib","id":10499993,"avatar_url":"https://avatars.githubusercontent.com/u/10499993?v=3","gravatar_id":"","url":"https://api.github.com/users/tinylib","html_url":"https://github.com/tinylib","followers_url":"https://api.github.com/users/tinylib/followers","following_url":"https://api.github.com/users/tinylib/following{/other_user}","gists_url":"https://api.github.com/users/tinylib/gists{/gist_id}","starred_url":"https://api.github.com/users/tinylib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tinylib/subscriptions","organizations_url":"https://api.github.com/users/tinylib/orgs","repos_url":"https://api.github.com/users/tinylib/repos","events_url":"https://api.github.com/users/tinylib/events{/privacy}","received_events_url":"https://api.github.com/users/tinylib/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tinylib/msgp","description":"A Go code generator for MessagePack / msgpack.org[Go]","fork":false,"url":"https://api.github.com/repos/tinylib/msgp","forks_url":"https://api.github.com/repos/tinylib/msgp/forks","keys_url":"https://api.github.com/repos/tinylib/msgp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tinylib/msgp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tinylib/msgp/teams","hooks_url":"https://api.github.com/repos/tinylib/msgp/hooks","issue_events_url":"https://api.github.com/repos/tinylib/msgp/issues/events{/number}","events_url":"https://api.github.com/repos/tinylib/msgp/events","assignees_url":"https://api.github.com/repos/tinylib/msgp/assignees{/user}","branches_url":"https://api.github.com/repos/tinylib/msgp/branches{/branch}","tags_url":"https://api.github.com/repos/tinylib/msgp/tags","blobs_url":"https://api.github.com/repos/tinylib/msgp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tinylib/msgp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tinylib/msgp/git/refs{/sha}","trees_url":"https://api.github.com/repos/tinylib/msgp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tinylib/msgp/statuses/{sha}","languages_url":"https://api.github.com/repos/tinylib/msgp/languages","stargazers_url":"https://api.github.com/repos/tinylib/msgp/stargazers","contributors_url":"https://api.github.com/repos/tinylib/msgp/contributors","subscribers_url":"https://api.github.com/repos/tinylib/msgp/subscribers","subscription_url":"https://api.github.com/repos/tinylib/msgp/subscription","commits_url":"https://api.github.com/repos/tinylib/msgp/commits{/sha}","git_commits_url":"https://api.github.com/repos/tinylib/msgp/git/commits{/sha}","comments_url":"https://api.github.com/repos/tinylib/msgp/comments{/number}","issue_comment_url":"https://api.github.com/repos/tinylib/msgp/issues/comments{/number}","contents_url":"https://api.github.com/repos/tinylib/msgp/contents/{+path}","compare_url":"https://api.github.com/repos/tinylib/msgp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tinylib/msgp/merges","archive_url":"https://api.github.com/repos/tinylib/msgp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tinylib/msgp/downloads","issues_url":"https://api.github.com/repos/tinylib/msgp/issues{/number}","pulls_url":"https://api.github.com/repos/tinylib/msgp/pulls{/number}","milestones_url":"https://api.github.com/repos/tinylib/msgp/milestones{/number}","notifications_url":"https://api.github.com/repos/tinylib/msgp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tinylib/msgp/labels{/name}","releases_url":"https://api.github.com/repos/tinylib/msgp/releases{/id}","deployments_url":"https://api.github.com/repos/tinylib/msgp/deployments","created_at":"2014-09-12T03:09:53Z","updated_at":"2016-07-15T15:27:00Z","pushed_at":"2016-07-15T15:55:59Z","git_url":"git://github.com/tinylib/msgp.git","ssh_url":"git@github.com:tinylib/msgp.git","clone_url":"https://github.com/tinylib/msgp.git","svn_url":"https://github.com/tinylib/msgp","homepage":"","size":9054,"stargazers_count":507,"watchers_count":507,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":28,"forks":50,"open_issues":28,"watchers":507,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/160"},"html":{"href":"https://github.com/tinylib/msgp/pull/160"},"issue":{"href":"https://api.github.com/repos/tinylib/msgp/issues/160"},"comments":{"href":"https://api.github.com/repos/tinylib/msgp/issues/160/comments"},"review_comments":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/160/comments"},"review_comment":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tinylib/msgp/pulls/160/commits"},"statuses":{"href":"https://api.github.com/repos/tinylib/msgp/statuses/f7c196e11b50d360ba131a4012b649acc64bf367"}}}}
{"actor":{"display_login":"philhofer"}}