{"action":"created","comment":{"url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/comments/197182687","pull_request_review_id":130876808,"id":197182687,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzE4MjY4Nw==","diff_hunk":"@@ -38,12 +64,101 @@ func (m Msg) String() string {\n \n // Len implements the WireMessage interface.\n func (m Msg) Len() int {\n-\tpanic(\"not implemented\")\n+\t// Header + FlagBits + len of each section + optional checksum\n+\ttotalLen := 16 + 32 // header and flag bits\n+\n+\tfor _, section := range m.Sections {\n+\t\ttotalLen += section.Len()\n+\t}\n+\n+\tif m.FlagBits&ChecksumPresent > 0 {\n+\t\ttotalLen += 4\n+\t}\n+\n+\treturn totalLen\n }\n \n // UnmarshalWireMessage implements the Unmarshaler interface.\n-func (m *Msg) UnmarshalWireMessage([]byte) error {\n-\tpanic(\"not implemented\")\n+func (m *Msg) UnmarshalWireMessage(b []byte) error {\n+\tvar err error\n+\n+\tm.MsgHeader, err = ReadHeader(b, 0)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tif len(b) < int(m.MsgHeader.MessageLength) {\n+\t\treturn Error{\n+\t\t\tType:    ErrOpMsg,\n+\t\t\tMessage: \"[]byte too small\",\n+\t\t}\n+\t}\n+\n+\tm.FlagBits = MsgFlag(readInt32(b, 16))\n+\n+\t// read each section\n+\tsectionBytes := m.MsgHeader.MessageLength - 16 - 4 // number of bytes taken up by sections\n+\thasChecksum := m.FlagBits&ChecksumPresent > 0\n+\tif hasChecksum {\n+\t\tsectionBytes -= 4 // 4 bytes at end for checksum\n+\t}\n+\n+\tm.Sections = make([]Section, 0)\n+\tposition := 20 // position to read from\n+\tfor sectionBytes > 0 {\n+\t\tsectionType := SectionType(b[position])\n+\t\tposition++\n+\n+\t\tswitch sectionType {\n+\t\tcase SingleDocument:\n+\t\t\trdr, size, err := readDocument(b, int32(position))\n+\t\t\tif err.Message != \"\" {\n+\t\t\t\terr.Type = ErrOpMsg\n+\t\t\t\treturn err\n+\t\t\t}\n+\n+\t\t\tposition += size\n+\t\t\tsb := SectionBody{\n+\t\t\t\tDocument: rdr,\n+\t\t\t}\n+\t\t\tsectionBytes -= int32(sb.Len())\n+\t\t\tm.Sections = append(m.Sections, sb)\n+\t\tcase DocumentSequence:\n+\t\t\tsds := SectionDocumentSequence{}\n+\t\t\tsds.Size = readInt32(b, int32(position))\n+\t\t\tposition += 4\n+\n+\t\t\tidentifier, err := readCString(b, int32(position))\n+\t\t\tif err != nil {\n+\t\t\t\treturn err\n+\t\t\t}\n+\n+\t\t\tsds.Identifier = identifier\n+\t\t\tposition += len(identifier) + 1 // +1 for \\0\n+\n+\t\t\t// length of documents to read\n+\t\t\t// sequenceLen - 4 (size) - identifierLength (including \\0)\n+\t\t\tdocsLen := int(sds.Size) - 4 - len(identifier) - 1\n+\t\t\tfor docsLen > 0 {\n+\t\t\t\trdr, size, err := readDocument(b, int32(position))","path":"core/wiremessage/msg.go","position":139,"original_position":139,"commit_id":"c3d16599c77cb5189c7bf1db7bb40bc677d0d6a0","original_commit_id":"c3d16599c77cb5189c7bf1db7bb40bc677d0d6a0","user":{"login":"skriptble","id":1694269,"node_id":"MDQ6VXNlcjE2OTQyNjk=","avatar_url":"https://avatars0.githubusercontent.com/u/1694269?v=4","gravatar_id":"","url":"https://api.github.com/users/skriptble","html_url":"https://github.com/skriptble","followers_url":"https://api.github.com/users/skriptble/followers","following_url":"https://api.github.com/users/skriptble/following{/other_user}","gists_url":"https://api.github.com/users/skriptble/gists{/gist_id}","starred_url":"https://api.github.com/users/skriptble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skriptble/subscriptions","organizations_url":"https://api.github.com/users/skriptble/orgs","repos_url":"https://api.github.com/users/skriptble/repos","events_url":"https://api.github.com/users/skriptble/events{/privacy}","received_events_url":"https://api.github.com/users/skriptble/received_events","type":"User","site_admin":false},"body":"readDocument here is doing a lot of allocations, one for each document. It would probably be more useful to allocate one large `[]byte` and then break that into the pieces we need. We would need an `appendDocument` function that works like `readDocument` but attempts to append to a given slice and if it can't, grows the slice.\r\n\r\nAlternatively, we could just allocate one large slice, copy the bytes, and then make `bson.Reader`s from the slice and do the shallow validation that `readDocument` does.","created_at":"2018-06-21T15:41:51Z","updated_at":"2018-06-21T15:43:18Z","html_url":"https://github.com/mongodb/mongo-go-driver/pull/69#discussion_r197182687","pull_request_url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/comments/197182687"},"html":{"href":"https://github.com/mongodb/mongo-go-driver/pull/69#discussion_r197182687"},"pull_request":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69"}}},"pull_request":{"url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69","id":196282784,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk2MjgyNzg0","html_url":"https://github.com/mongodb/mongo-go-driver/pull/69","diff_url":"https://github.com/mongodb/mongo-go-driver/pull/69.diff","patch_url":"https://github.com/mongodb/mongo-go-driver/pull/69.patch","issue_url":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/69","number":69,"state":"open","locked":false,"title":"Implement the OP_MSG specification.","user":{"login":"divjotarora","id":9158924,"node_id":"MDQ6VXNlcjkxNTg5MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/9158924?v=4","gravatar_id":"","url":"https://api.github.com/users/divjotarora","html_url":"https://github.com/divjotarora","followers_url":"https://api.github.com/users/divjotarora/followers","following_url":"https://api.github.com/users/divjotarora/following{/other_user}","gists_url":"https://api.github.com/users/divjotarora/gists{/gist_id}","starred_url":"https://api.github.com/users/divjotarora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divjotarora/subscriptions","organizations_url":"https://api.github.com/users/divjotarora/orgs","repos_url":"https://api.github.com/users/divjotarora/repos","events_url":"https://api.github.com/users/divjotarora/events{/privacy}","received_events_url":"https://api.github.com/users/divjotarora/received_events","type":"User","site_admin":false},"body":"GODRIVER-54\r\n\r\nChange-Id: Id6cf355c7a63ed4bf922d5a33a170aa8c060a397","created_at":"2018-06-20T21:52:42Z","updated_at":"2018-06-21T15:43:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ede77c8757f9b07c39ef303954a1fc2a6a4638c4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69/commits","review_comments_url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69/comments","review_comment_url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/69/comments","statuses_url":"https://api.github.com/repos/mongodb/mongo-go-driver/statuses/c3d16599c77cb5189c7bf1db7bb40bc677d0d6a0","head":{"label":"divjotarora:opmsg","ref":"opmsg","sha":"c3d16599c77cb5189c7bf1db7bb40bc677d0d6a0","user":{"login":"divjotarora","id":9158924,"node_id":"MDQ6VXNlcjkxNTg5MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/9158924?v=4","gravatar_id":"","url":"https://api.github.com/users/divjotarora","html_url":"https://github.com/divjotarora","followers_url":"https://api.github.com/users/divjotarora/followers","following_url":"https://api.github.com/users/divjotarora/following{/other_user}","gists_url":"https://api.github.com/users/divjotarora/gists{/gist_id}","starred_url":"https://api.github.com/users/divjotarora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divjotarora/subscriptions","organizations_url":"https://api.github.com/users/divjotarora/orgs","repos_url":"https://api.github.com/users/divjotarora/repos","events_url":"https://api.github.com/users/divjotarora/events{/privacy}","received_events_url":"https://api.github.com/users/divjotarora/received_events","type":"User","site_admin":false},"repo":{"id":137089750,"node_id":"MDEwOlJlcG9zaXRvcnkxMzcwODk3NTA=","name":"mongo-go-driver","full_name":"divjotarora/mongo-go-driver","owner":{"login":"divjotarora","id":9158924,"node_id":"MDQ6VXNlcjkxNTg5MjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/9158924?v=4","gravatar_id":"","url":"https://api.github.com/users/divjotarora","html_url":"https://github.com/divjotarora","followers_url":"https://api.github.com/users/divjotarora/followers","following_url":"https://api.github.com/users/divjotarora/following{/other_user}","gists_url":"https://api.github.com/users/divjotarora/gists{/gist_id}","starred_url":"https://api.github.com/users/divjotarora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divjotarora/subscriptions","organizations_url":"https://api.github.com/users/divjotarora/orgs","repos_url":"https://api.github.com/users/divjotarora/repos","events_url":"https://api.github.com/users/divjotarora/events{/privacy}","received_events_url":"https://api.github.com/users/divjotarora/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/divjotarora/mongo-go-driver","description":"The Go driver for MongoDB","fork":true,"url":"https://api.github.com/repos/divjotarora/mongo-go-driver","forks_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/forks","keys_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/teams","hooks_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/hooks","issue_events_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/issues/events{/number}","events_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/events","assignees_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/assignees{/user}","branches_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/branches{/branch}","tags_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/tags","blobs_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/languages","stargazers_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/stargazers","contributors_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/contributors","subscribers_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/subscribers","subscription_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/subscription","commits_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/contents/{+path}","compare_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/merges","archive_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/downloads","issues_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/issues{/number}","pulls_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/labels{/name}","releases_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/releases{/id}","deployments_url":"https://api.github.com/repos/divjotarora/mongo-go-driver/deployments","created_at":"2018-06-12T15:11:55Z","updated_at":"2018-06-12T15:11:58Z","pushed_at":"2018-06-21T13:32:38Z","git_url":"git://github.com/divjotarora/mongo-go-driver.git","ssh_url":"git@github.com:divjotarora/mongo-go-driver.git","clone_url":"https://github.com/divjotarora/mongo-go-driver.git","svn_url":"https://github.com/divjotarora/mongo-go-driver","homepage":"","size":4109,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mongodb:master","ref":"master","sha":"59e0104575f3c7bb75aab8f99fea263528c3b155","user":{"login":"mongodb","id":45120,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ1MTIw","avatar_url":"https://avatars1.githubusercontent.com/u/45120?v=4","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":81355383,"node_id":"MDEwOlJlcG9zaXRvcnk4MTM1NTM4Mw==","name":"mongo-go-driver","full_name":"mongodb/mongo-go-driver","owner":{"login":"mongodb","id":45120,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ1MTIw","avatar_url":"https://avatars1.githubusercontent.com/u/45120?v=4","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-go-driver","description":"The Go driver for MongoDB","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-go-driver","forks_url":"https://api.github.com/repos/mongodb/mongo-go-driver/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-go-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-go-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-go-driver/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-go-driver/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-go-driver/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-go-driver/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-go-driver/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-go-driver/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-go-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-go-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-go-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-go-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-go-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-go-driver/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-go-driver/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-go-driver/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-go-driver/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-go-driver/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-go-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-go-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-go-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-go-driver/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-go-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-go-driver/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-go-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-go-driver/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-go-driver/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-go-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-go-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-go-driver/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-go-driver/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-go-driver/deployments","created_at":"2017-02-08T17:18:02Z","updated_at":"2018-06-21T13:07:21Z","pushed_at":"2018-06-21T15:32:25Z","git_url":"git://github.com/mongodb/mongo-go-driver.git","ssh_url":"git@github.com:mongodb/mongo-go-driver.git","clone_url":"https://github.com/mongodb/mongo-go-driver.git","svn_url":"https://github.com/mongodb/mongo-go-driver","homepage":"","size":5544,"stargazers_count":538,"watchers_count":538,"language":"Go","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":42,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":42,"open_issues":8,"watchers":538,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69"},"html":{"href":"https://github.com/mongodb/mongo-go-driver/pull/69"},"issue":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/69"},"comments":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/mongodb/mongo-go-driver/statuses/c3d16599c77cb5189c7bf1db7bb40bc677d0d6a0"}},"author_association":"NONE"}}
{"actor":{"display_login":"skriptble"}}