{"action":"created","comment":{"url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/comments/50525047","id":50525047,"diff_hunk":"@@ -0,0 +1,597 @@\n+package cbor\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"log\"\n+\t\"math\"\n+\t\"math/big\"\n+\t\"reflect\"\n+\t\"strings\"\n+)\n+\n+type TagDecoder interface {\n+\t// Handle things which match this.\n+\t//\n+\t// Setup like this:\n+\t// var dec Decoder\n+\t// var myTagDec TagDecoder\n+\t// dec.TagDecoders[myTagDec.GetTag()] = myTagDec\n+\tGetTag() uint64\n+\n+\t// Sub-object will be decoded onto the returned object.\n+\tDecodeTarget() interface{}\n+\n+\t// Run after decode onto DecodeTarget has happened.\n+\t// The return value from this is returned in place of the\n+\t// raw decoded object.\n+\tPostDecode(interface{}) (interface{}, error)\n+}\n+\n+type Decoder struct {\n+\trin io.Reader\n+\n+\t// tag byte\n+\tc []byte\n+\n+\t// many values fit within the next 8 bytes\n+\tb8 []byte\n+\n+\t// Extra processing for CBOR TAG objects.\n+\tTagDecoders map[uint64]TagDecoder\n+}\n+\n+func NewDecoder(r io.Reader) *Decoder {\n+\treturn &Decoder{\n+\t\trin:         r,\n+\t\tc:           make([]byte, 1),\n+\t\tb8:          make([]byte, 8),\n+\t\tTagDecoders: make(map[uint64]TagDecoder),\n+\t}\n+}\n+func (dec *Decoder) Decode(v interface{}) error {\n+\trv := reflect.ValueOf(v)\n+\n+\treturn dec.DecodeAny(newReflectValue(rv))\n+}\n+\n+func (dec *Decoder) DecodeAny(v DecodeValue) error {\n+\tvar didread int\n+\tvar err error\n+\n+\t_, err = io.ReadFull(dec.rin, dec.c)\n+\n+\tif didread == 1 {\n+\t\t/* log.Printf(\"got one %x\\n\", dec.c[0]) */\n+\t}\n+\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tif err := v.Prepare(); err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn dec.innerDecodeC(v, dec.c[0])\n+}\n+\n+func (dec *Decoder) handleInfoBits(cborInfo byte) (uint64, error) {\n+\tvar aux uint64\n+\n+\tif cborInfo <= 23 {\n+\t\taux = uint64(cborInfo)\n+\t\treturn aux, nil\n+\t} else if cborInfo == int8Follows {\n+\t\tdidread, err := io.ReadFull(dec.rin, dec.b8[:1])\n+\t\tif didread == 1 {\n+\t\t\taux = uint64(dec.b8[0])\n+\t\t}\n+\t\treturn aux, err\n+\t} else if cborInfo == int16Follows {\n+\t\tdidread, err := io.ReadFull(dec.rin, dec.b8[:2])\n+\t\tif didread == 2 {\n+\t\t\taux = (uint64(dec.b8[0]) << 8) | uint64(dec.b8[1])\n+\t\t}\n+\t\treturn aux, err\n+\t} else if cborInfo == int32Follows {\n+\t\tdidread, err := io.ReadFull(dec.rin, dec.b8[:4])\n+\t\tif didread == 4 {\n+\t\t\taux = (uint64(dec.b8[0]) << 24) |\n+\t\t\t\t(uint64(dec.b8[1]) << 16) |\n+\t\t\t\t(uint64(dec.b8[2]) << 8) |\n+\t\t\t\tuint64(dec.b8[3])\n+\t\t}\n+\t\treturn aux, err\n+\t} else if cborInfo == int64Follows {\n+\t\tdidread, err := io.ReadFull(dec.rin, dec.b8)\n+\t\tif didread == 8 {\n+\t\t\tvar shift uint = 56\n+\t\t\ti := 0\n+\t\t\taux = uint64(dec.b8[i]) << shift\n+\t\t\tfor i < 7 {\n+\t\t\t\ti += 1\n+\t\t\t\tshift -= 8\n+\t\t\t\taux |= uint64(dec.b8[i]) << shift\n+\t\t\t}\n+\t\t}\n+\t\treturn aux, err\n+\t}\n+\treturn 0, nil\n+}\n+\n+func (dec *Decoder) innerDecodeC(rv DecodeValue, c byte) error {\n+\tcborType := c & typeMask\n+\tcborInfo := c & infoBits\n+\n+\taux, err := dec.handleInfoBits(cborInfo)\n+\tif err != nil {\n+\t\tlog.Printf(\"error in handleInfoBits: %v\", err)\n+\t\treturn err\n+\t}\n+\t//log.Printf(\"cborType %x cborInfo %d aux %x\", cborType, cborInfo, aux)\n+\n+\tif cborType == cborUint {","path":"go/decoder.go","position":135,"original_position":135,"commit_id":"dcaf805916c171db179473fe9eb7bca4aa25bf59","original_commit_id":"dcaf805916c171db179473fe9eb7bca4aa25bf59","user":{"login":"whyrusleeping","id":1243164,"avatar_url":"https://avatars.githubusercontent.com/u/1243164?v=3","gravatar_id":"","url":"https://api.github.com/users/whyrusleeping","html_url":"https://github.com/whyrusleeping","followers_url":"https://api.github.com/users/whyrusleeping/followers","following_url":"https://api.github.com/users/whyrusleeping/following{/other_user}","gists_url":"https://api.github.com/users/whyrusleeping/gists{/gist_id}","starred_url":"https://api.github.com/users/whyrusleeping/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whyrusleeping/subscriptions","organizations_url":"https://api.github.com/users/whyrusleeping/orgs","repos_url":"https://api.github.com/users/whyrusleeping/repos","events_url":"https://api.github.com/users/whyrusleeping/events{/privacy}","received_events_url":"https://api.github.com/users/whyrusleeping/received_events","type":"User","site_admin":false},"body":"switch statements","created_at":"2016-01-22T11:00:02Z","updated_at":"2016-01-22T11:00:02Z","html_url":"https://github.com/whyrusleeping/cbor/pull/3#discussion_r50525047","pull_request_url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/comments/50525047"},"html":{"href":"https://github.com/whyrusleeping/cbor/pull/3#discussion_r50525047"},"pull_request":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3","id":55817126,"html_url":"https://github.com/whyrusleeping/cbor/pull/3","diff_url":"https://github.com/whyrusleeping/cbor/pull/3.diff","patch_url":"https://github.com/whyrusleeping/cbor/pull/3.patch","issue_url":"https://api.github.com/repos/whyrusleeping/cbor/issues/3","number":3,"state":"open","locked":false,"title":"Allow streaming interface to CBOR","user":{"login":"mildred","id":33804,"avatar_url":"https://avatars.githubusercontent.com/u/33804?v=3","gravatar_id":"","url":"https://api.github.com/users/mildred","html_url":"https://github.com/mildred","followers_url":"https://api.github.com/users/mildred/followers","following_url":"https://api.github.com/users/mildred/following{/other_user}","gists_url":"https://api.github.com/users/mildred/gists{/gist_id}","starred_url":"https://api.github.com/users/mildred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildred/subscriptions","organizations_url":"https://api.github.com/users/mildred/orgs","repos_url":"https://api.github.com/users/mildred/repos","events_url":"https://api.github.com/users/mildred/events{/privacy}","received_events_url":"https://api.github.com/users/mildred/received_events","type":"User","site_admin":false},"body":"See #2 for rationale.","created_at":"2016-01-12T21:08:21Z","updated_at":"2016-01-22T11:00:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bfcce938e14503cd3e520e0ec977ba3cd8bca54d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3/commits","review_comments_url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3/comments","review_comment_url":"https://api.github.com/repos/whyrusleeping/cbor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/whyrusleeping/cbor/issues/3/comments","statuses_url":"https://api.github.com/repos/whyrusleeping/cbor/statuses/dcaf805916c171db179473fe9eb7bca4aa25bf59","head":{"label":"mildred:master","ref":"master","sha":"dcaf805916c171db179473fe9eb7bca4aa25bf59","user":{"login":"mildred","id":33804,"avatar_url":"https://avatars.githubusercontent.com/u/33804?v=3","gravatar_id":"","url":"https://api.github.com/users/mildred","html_url":"https://github.com/mildred","followers_url":"https://api.github.com/users/mildred/followers","following_url":"https://api.github.com/users/mildred/following{/other_user}","gists_url":"https://api.github.com/users/mildred/gists{/gist_id}","starred_url":"https://api.github.com/users/mildred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildred/subscriptions","organizations_url":"https://api.github.com/users/mildred/orgs","repos_url":"https://api.github.com/users/mildred/repos","events_url":"https://api.github.com/users/mildred/events{/privacy}","received_events_url":"https://api.github.com/users/mildred/received_events","type":"User","site_admin":false},"repo":{"id":49528420,"name":"cbor","full_name":"mildred/cbor","owner":{"login":"mildred","id":33804,"avatar_url":"https://avatars.githubusercontent.com/u/33804?v=3","gravatar_id":"","url":"https://api.github.com/users/mildred","html_url":"https://github.com/mildred","followers_url":"https://api.github.com/users/mildred/followers","following_url":"https://api.github.com/users/mildred/following{/other_user}","gists_url":"https://api.github.com/users/mildred/gists{/gist_id}","starred_url":"https://api.github.com/users/mildred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildred/subscriptions","organizations_url":"https://api.github.com/users/mildred/orgs","repos_url":"https://api.github.com/users/mildred/repos","events_url":"https://api.github.com/users/mildred/events{/privacy}","received_events_url":"https://api.github.com/users/mildred/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mildred/cbor","description":null,"fork":true,"url":"https://api.github.com/repos/mildred/cbor","forks_url":"https://api.github.com/repos/mildred/cbor/forks","keys_url":"https://api.github.com/repos/mildred/cbor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mildred/cbor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mildred/cbor/teams","hooks_url":"https://api.github.com/repos/mildred/cbor/hooks","issue_events_url":"https://api.github.com/repos/mildred/cbor/issues/events{/number}","events_url":"https://api.github.com/repos/mildred/cbor/events","assignees_url":"https://api.github.com/repos/mildred/cbor/assignees{/user}","branches_url":"https://api.github.com/repos/mildred/cbor/branches{/branch}","tags_url":"https://api.github.com/repos/mildred/cbor/tags","blobs_url":"https://api.github.com/repos/mildred/cbor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mildred/cbor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mildred/cbor/git/refs{/sha}","trees_url":"https://api.github.com/repos/mildred/cbor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mildred/cbor/statuses/{sha}","languages_url":"https://api.github.com/repos/mildred/cbor/languages","stargazers_url":"https://api.github.com/repos/mildred/cbor/stargazers","contributors_url":"https://api.github.com/repos/mildred/cbor/contributors","subscribers_url":"https://api.github.com/repos/mildred/cbor/subscribers","subscription_url":"https://api.github.com/repos/mildred/cbor/subscription","commits_url":"https://api.github.com/repos/mildred/cbor/commits{/sha}","git_commits_url":"https://api.github.com/repos/mildred/cbor/git/commits{/sha}","comments_url":"https://api.github.com/repos/mildred/cbor/comments{/number}","issue_comment_url":"https://api.github.com/repos/mildred/cbor/issues/comments{/number}","contents_url":"https://api.github.com/repos/mildred/cbor/contents/{+path}","compare_url":"https://api.github.com/repos/mildred/cbor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mildred/cbor/merges","archive_url":"https://api.github.com/repos/mildred/cbor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mildred/cbor/downloads","issues_url":"https://api.github.com/repos/mildred/cbor/issues{/number}","pulls_url":"https://api.github.com/repos/mildred/cbor/pulls{/number}","milestones_url":"https://api.github.com/repos/mildred/cbor/milestones{/number}","notifications_url":"https://api.github.com/repos/mildred/cbor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mildred/cbor/labels{/name}","releases_url":"https://api.github.com/repos/mildred/cbor/releases{/id}","deployments_url":"https://api.github.com/repos/mildred/cbor/deployments","created_at":"2016-01-12T20:58:02Z","updated_at":"2016-01-12T20:58:03Z","pushed_at":"2016-01-15T08:07:59Z","git_url":"git://github.com/mildred/cbor.git","ssh_url":"git@github.com:mildred/cbor.git","clone_url":"https://github.com/mildred/cbor.git","svn_url":"https://github.com/mildred/cbor","homepage":null,"size":95,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"whyrusleeping:master","ref":"master","sha":"6877b5d4169c96da15307aa89cfeed70c878b875","user":{"login":"whyrusleeping","id":1243164,"avatar_url":"https://avatars.githubusercontent.com/u/1243164?v=3","gravatar_id":"","url":"https://api.github.com/users/whyrusleeping","html_url":"https://github.com/whyrusleeping","followers_url":"https://api.github.com/users/whyrusleeping/followers","following_url":"https://api.github.com/users/whyrusleeping/following{/other_user}","gists_url":"https://api.github.com/users/whyrusleeping/gists{/gist_id}","starred_url":"https://api.github.com/users/whyrusleeping/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whyrusleeping/subscriptions","organizations_url":"https://api.github.com/users/whyrusleeping/orgs","repos_url":"https://api.github.com/users/whyrusleeping/repos","events_url":"https://api.github.com/users/whyrusleeping/events{/privacy}","received_events_url":"https://api.github.com/users/whyrusleeping/received_events","type":"User","site_admin":false},"repo":{"id":41391264,"name":"cbor","full_name":"whyrusleeping/cbor","owner":{"login":"whyrusleeping","id":1243164,"avatar_url":"https://avatars.githubusercontent.com/u/1243164?v=3","gravatar_id":"","url":"https://api.github.com/users/whyrusleeping","html_url":"https://github.com/whyrusleeping","followers_url":"https://api.github.com/users/whyrusleeping/followers","following_url":"https://api.github.com/users/whyrusleeping/following{/other_user}","gists_url":"https://api.github.com/users/whyrusleeping/gists{/gist_id}","starred_url":"https://api.github.com/users/whyrusleeping/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whyrusleeping/subscriptions","organizations_url":"https://api.github.com/users/whyrusleeping/orgs","repos_url":"https://api.github.com/users/whyrusleeping/repos","events_url":"https://api.github.com/users/whyrusleeping/events{/privacy}","received_events_url":"https://api.github.com/users/whyrusleeping/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/whyrusleeping/cbor","description":null,"fork":false,"url":"https://api.github.com/repos/whyrusleeping/cbor","forks_url":"https://api.github.com/repos/whyrusleeping/cbor/forks","keys_url":"https://api.github.com/repos/whyrusleeping/cbor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/whyrusleeping/cbor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/whyrusleeping/cbor/teams","hooks_url":"https://api.github.com/repos/whyrusleeping/cbor/hooks","issue_events_url":"https://api.github.com/repos/whyrusleeping/cbor/issues/events{/number}","events_url":"https://api.github.com/repos/whyrusleeping/cbor/events","assignees_url":"https://api.github.com/repos/whyrusleeping/cbor/assignees{/user}","branches_url":"https://api.github.com/repos/whyrusleeping/cbor/branches{/branch}","tags_url":"https://api.github.com/repos/whyrusleeping/cbor/tags","blobs_url":"https://api.github.com/repos/whyrusleeping/cbor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/whyrusleeping/cbor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/whyrusleeping/cbor/git/refs{/sha}","trees_url":"https://api.github.com/repos/whyrusleeping/cbor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/whyrusleeping/cbor/statuses/{sha}","languages_url":"https://api.github.com/repos/whyrusleeping/cbor/languages","stargazers_url":"https://api.github.com/repos/whyrusleeping/cbor/stargazers","contributors_url":"https://api.github.com/repos/whyrusleeping/cbor/contributors","subscribers_url":"https://api.github.com/repos/whyrusleeping/cbor/subscribers","subscription_url":"https://api.github.com/repos/whyrusleeping/cbor/subscription","commits_url":"https://api.github.com/repos/whyrusleeping/cbor/commits{/sha}","git_commits_url":"https://api.github.com/repos/whyrusleeping/cbor/git/commits{/sha}","comments_url":"https://api.github.com/repos/whyrusleeping/cbor/comments{/number}","issue_comment_url":"https://api.github.com/repos/whyrusleeping/cbor/issues/comments{/number}","contents_url":"https://api.github.com/repos/whyrusleeping/cbor/contents/{+path}","compare_url":"https://api.github.com/repos/whyrusleeping/cbor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/whyrusleeping/cbor/merges","archive_url":"https://api.github.com/repos/whyrusleeping/cbor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/whyrusleeping/cbor/downloads","issues_url":"https://api.github.com/repos/whyrusleeping/cbor/issues{/number}","pulls_url":"https://api.github.com/repos/whyrusleeping/cbor/pulls{/number}","milestones_url":"https://api.github.com/repos/whyrusleeping/cbor/milestones{/number}","notifications_url":"https://api.github.com/repos/whyrusleeping/cbor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/whyrusleeping/cbor/labels{/name}","releases_url":"https://api.github.com/repos/whyrusleeping/cbor/releases{/id}","deployments_url":"https://api.github.com/repos/whyrusleeping/cbor/deployments","created_at":"2015-08-25T22:32:55Z","updated_at":"2016-01-13T08:58:57Z","pushed_at":"2016-01-15T08:08:00Z","git_url":"git://github.com/whyrusleeping/cbor.git","ssh_url":"git@github.com:whyrusleeping/cbor.git","clone_url":"https://github.com/whyrusleeping/cbor.git","svn_url":"https://github.com/whyrusleeping/cbor","homepage":null,"size":240,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3"},"html":{"href":"https://github.com/whyrusleeping/cbor/pull/3"},"issue":{"href":"https://api.github.com/repos/whyrusleeping/cbor/issues/3"},"comments":{"href":"https://api.github.com/repos/whyrusleeping/cbor/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/whyrusleeping/cbor/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/whyrusleeping/cbor/statuses/dcaf805916c171db179473fe9eb7bca4aa25bf59"}}}}