{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/57115483","id":57115483,"diff_hunk":"@@ -0,0 +1,330 @@\n+package tablecodec\n+\n+import (\n+\t\"sort\"\n+\t\"time\"\n+\n+\t\"bytes\"\n+\t\"github.com/golang/protobuf/proto\"\n+\t\"github.com/juju/errors\"\n+\t\"github.com/ngaut/log\"\n+\t\"github.com/pingcap/tidb/kv\"\n+\t\"github.com/pingcap/tidb/model\"\n+\t\"github.com/pingcap/tidb/mysql\"\n+\t\"github.com/pingcap/tidb/util/codec\"\n+\t\"github.com/pingcap/tidb/util/types\"\n+\t\"github.com/pingcap/tidb/xapi/tipb\"\n+)\n+\n+var (\n+\ttablePrefix     = []byte{'t'}\n+\trecordPrefixSep = []byte(\"_r\")\n+\tindexPrefixSep  = []byte(\"_i\")\n+)\n+\n+const (\n+\tidLen           = 8\n+\tprefixLen       = 1 + idLen /*tableID*/ + 2\n+\trecordRowKeyLen = prefixLen + idLen /*handle*/\n+)\n+\n+// EncodeRowKey encodes the table id and record handle into a kv.Key\n+func EncodeRowKey(tableID int64, encodedHandle []byte) kv.Key {\n+\tbuf := make([]byte, 0, recordRowKeyLen)\n+\tbuf = appendTableRecordPrefix(buf, tableID)\n+\tbuf = append(buf, encodedHandle...)\n+\treturn buf\n+}\n+\n+// EncodeColumnKey encodes the table id, row handle and columnID into a kv.Key\n+func EncodeColumnKey(tableID int64, encodedHandle []byte, columnID int64) kv.Key {\n+\tbuf := make([]byte, 0, recordRowKeyLen+idLen)\n+\tbuf = appendTableRecordPrefix(buf, tableID)\n+\tbuf = append(buf, encodedHandle...)\n+\tbuf = codec.EncodeInt(buf, columnID)\n+\treturn buf\n+}\n+\n+// DecodeRowKey decodes the key and gets the handle.\n+func DecodeRowKey(key kv.Key) (handle int64, err error) {\n+\tk := key\n+\tif !key.HasPrefix(tablePrefix) {\n+\t\treturn 0, errors.Errorf(\"invalid record key - %q\", k)\n+\t}\n+\n+\tkey = key[len(tablePrefix):]\n+\t// Table ID is not needed.\n+\tkey, _, err = codec.DecodeInt(key)\n+\tif err != nil {\n+\t\treturn 0, errors.Trace(err)\n+\t}\n+\n+\tif !key.HasPrefix(recordPrefixSep) {\n+\t\treturn 0, errors.Errorf(\"invalid record key - %q\", k)\n+\t}\n+\n+\tkey = key[len(recordPrefixSep):]\n+\n+\tkey, handle, err = codec.DecodeInt(key)\n+\tif err != nil {","path":"xapi/tablecodec/tablecodec.go","position":69,"original_position":69,"commit_id":"5597bdaba3ef4e07010666781dd23aa84d7b0f58","original_commit_id":"5748fbbf9a7bf8ec00c79a2781402668acfe1e6f","user":{"login":"zimulala","id":4242506,"avatar_url":"https://avatars.githubusercontent.com/u/4242506?v=3","gravatar_id":"","url":"https://api.github.com/users/zimulala","html_url":"https://github.com/zimulala","followers_url":"https://api.github.com/users/zimulala/followers","following_url":"https://api.github.com/users/zimulala/following{/other_user}","gists_url":"https://api.github.com/users/zimulala/gists{/gist_id}","starred_url":"https://api.github.com/users/zimulala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zimulala/subscriptions","organizations_url":"https://api.github.com/users/zimulala/orgs","repos_url":"https://api.github.com/users/zimulala/repos","events_url":"https://api.github.com/users/zimulala/events{/privacy}","received_events_url":"https://api.github.com/users/zimulala/received_events","type":"User","site_admin":false},"body":"Here can return directly?","created_at":"2016-03-23T06:32:52Z","updated_at":"2016-03-23T06:32:52Z","html_url":"https://github.com/pingcap/tidb/pull/1002#discussion_r57115483","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/1002","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/57115483"},"html":{"href":"https://github.com/pingcap/tidb/pull/1002#discussion_r57115483"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1002"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/1002","id":63715878,"html_url":"https://github.com/pingcap/tidb/pull/1002","diff_url":"https://github.com/pingcap/tidb/pull/1002.diff","patch_url":"https://github.com/pingcap/tidb/pull/1002.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/1002","number":1002,"state":"open","locked":false,"title":"xapi: add xapi functions.","user":{"login":"coocood","id":891222,"avatar_url":"https://avatars.githubusercontent.com/u/891222?v=3","gravatar_id":"","url":"https://api.github.com/users/coocood","html_url":"https://github.com/coocood","followers_url":"https://api.github.com/users/coocood/followers","following_url":"https://api.github.com/users/coocood/following{/other_user}","gists_url":"https://api.github.com/users/coocood/gists{/gist_id}","starred_url":"https://api.github.com/users/coocood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coocood/subscriptions","organizations_url":"https://api.github.com/users/coocood/orgs","repos_url":"https://api.github.com/users/coocood/repos","events_url":"https://api.github.com/users/coocood/events{/privacy}","received_events_url":"https://api.github.com/users/coocood/received_events","type":"User","site_admin":false},"body":"Some functions are not used, but the following PR will use them.\r\nTests will be added in following PR.","created_at":"2016-03-22T13:04:01Z","updated_at":"2016-03-23T06:32:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3edad00c4dfa1f3aef025cf5de36305ab2df404e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/1002/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/1002/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/1002/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/5597bdaba3ef4e07010666781dd23aa84d7b0f58","head":{"label":"pingcap:coocood/xapi","ref":"coocood/xapi","sha":"5597bdaba3ef4e07010666781dd23aa84d7b0f58","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2016-03-23T02:31:43Z","pushed_at":"2016-03-23T06:15:10Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":12304,"stargazers_count":3565,"watchers_count":3565,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":414,"mirror_url":null,"open_issues_count":67,"forks":414,"open_issues":67,"watchers":3565,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"a224bcc57d3afaa7c608c156f2155875b476244c","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed NewSQL database compatible with MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2016-03-23T02:31:43Z","pushed_at":"2016-03-23T06:15:10Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":12304,"stargazers_count":3565,"watchers_count":3565,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":414,"mirror_url":null,"open_issues_count":67,"forks":414,"open_issues":67,"watchers":3565,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1002"},"html":{"href":"https://github.com/pingcap/tidb/pull/1002"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1002"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/1002/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1002/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/1002/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/5597bdaba3ef4e07010666781dd23aa84d7b0f58"}}}}