{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/bond/pulls/comments/60129955","id":60129955,"diff_hunk":"@@ -93,16 +124,79 @@ public Transcoder()\n         /// <param name=\"writer\">Writer instance</param>\n         public void Transcode(R reader, W writer)\n         {\n-            transcode[0](reader, writer);\n+            helper.Transcode(reader, writer);\n+        }\n+\n+        private class TranscoderHelper\n+        {\n+            readonly Action<R, W>[] transcode;\n+\n+            public TranscoderHelper(RuntimeSchema schema)\n+            {\n+                transcode = Generate(schema);\n+            }\n+\n+            public TranscoderHelper(Type type)\n+            {\n+                transcode = Generate(type);\n+            }\n+\n+            virtual public void Transcode(R reader, W writer)\n+            {\n+                transcode[0](reader, writer);\n+            }\n+\n+            private Action<R, W>[] Generate<S>(S schema)\n+            {\n+                var parser = ParserFactory<R>.Create(schema);\n+                return SerializerGeneratorFactory<R, W>.Create(\n+                        (r, w, i) => transcode[i](r, w), schema)\n+                    .Generate(parser)\n+                    .Select(lambda => lambda.Compile()).ToArray();\n+            }\n         }\n \n-        Action<R, W>[] Generate<S>(S schema)\n+        private class TwoPassTranscoderHelper<FPW> : TranscoderHelper\n         {\n-            var parser = ParserFactory<R>.Create(schema);\n-            return SerializerGeneratorFactory<R, W>.Create(\n-                    (r, w, i) => transcode[i](r, w), schema)\n-                .Generate(parser)\n-                .Select(lambda => lambda.Compile()).ToArray();\n+            readonly Action<R, FPW>[] firstPassTranscode;\n+\n+            public TwoPassTranscoderHelper(RuntimeSchema schema):\n+                base(schema)\n+            {\n+                firstPassTranscode = GenerateFirstPass(schema);\n+            }\n+\n+            public TwoPassTranscoderHelper(Type type):\n+                base(type)\n+            {\n+                firstPassTranscode = GenerateFirstPass(type);\n+            }\n+\n+            public override void Transcode(R reader, W writer)\n+            {\n+                var firstPassWriter = ((ITwoPassProtocolWriter)writer).GetFirstPassWriter();\n+                if (firstPassWriter != null)\n+                {\n+                    if (!typeof(ICloneable<R>).IsAssignableFrom(typeof(R)))","path":"cs/src/core/Transcoder.cs","position":138,"original_position":138,"commit_id":"d1521e9c8d76502389b3ba4b1e81bfb77acfd5d6","original_commit_id":"d1521e9c8d76502389b3ba4b1e81bfb77acfd5d6","user":{"login":"chwarr","id":10605667,"avatar_url":"https://avatars.githubusercontent.com/u/10605667?v=3","gravatar_id":"","url":"https://api.github.com/users/chwarr","html_url":"https://github.com/chwarr","followers_url":"https://api.github.com/users/chwarr/followers","following_url":"https://api.github.com/users/chwarr/following{/other_user}","gists_url":"https://api.github.com/users/chwarr/gists{/gist_id}","starred_url":"https://api.github.com/users/chwarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chwarr/subscriptions","organizations_url":"https://api.github.com/users/chwarr/orgs","repos_url":"https://api.github.com/users/chwarr/repos","events_url":"https://api.github.com/users/chwarr/events{/privacy}","received_events_url":"https://api.github.com/users/chwarr/received_events","type":"User","site_admin":false},"body":"Can we do this check in the static ctor?","created_at":"2016-04-18T20:38:58Z","updated_at":"2016-04-18T20:38:58Z","html_url":"https://github.com/Microsoft/bond/pull/146#discussion_r60129955","pull_request_url":"https://api.github.com/repos/Microsoft/bond/pulls/146","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/comments/60129955"},"html":{"href":"https://github.com/Microsoft/bond/pull/146#discussion_r60129955"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/146"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/bond/pulls/146","id":65826895,"html_url":"https://github.com/Microsoft/bond/pull/146","diff_url":"https://github.com/Microsoft/bond/pull/146.diff","patch_url":"https://github.com/Microsoft/bond/pull/146.patch","issue_url":"https://api.github.com/repos/Microsoft/bond/issues/146","number":146,"state":"open","locked":false,"title":"C# Compact Binary v2 serialization","user":{"login":"jdubrule","id":11828477,"avatar_url":"https://avatars.githubusercontent.com/u/11828477?v=3","gravatar_id":"","url":"https://api.github.com/users/jdubrule","html_url":"https://github.com/jdubrule","followers_url":"https://api.github.com/users/jdubrule/followers","following_url":"https://api.github.com/users/jdubrule/following{/other_user}","gists_url":"https://api.github.com/users/jdubrule/gists{/gist_id}","starred_url":"https://api.github.com/users/jdubrule/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdubrule/subscriptions","organizations_url":"https://api.github.com/users/jdubrule/orgs","repos_url":"https://api.github.com/users/jdubrule/repos","events_url":"https://api.github.com/users/jdubrule/events{/privacy}","received_events_url":"https://api.github.com/users/jdubrule/received_events","type":"User","site_admin":false},"body":"Implement Compact Binary v2 serialization support in C#, which previously only supported v2 deserialization (and both for v1)","created_at":"2016-04-08T18:23:23Z","updated_at":"2016-04-18T20:38:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00dea3fe7adddad4151a21d9044ec86ce94c6031","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/bond/pulls/146/commits","review_comments_url":"https://api.github.com/repos/Microsoft/bond/pulls/146/comments","review_comment_url":"https://api.github.com/repos/Microsoft/bond/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/bond/issues/146/comments","statuses_url":"https://api.github.com/repos/Microsoft/bond/statuses/d1521e9c8d76502389b3ba4b1e81bfb77acfd5d6","head":{"label":"jdubrule:csharp-compact-binary-v2","ref":"csharp-compact-binary-v2","sha":"d1521e9c8d76502389b3ba4b1e81bfb77acfd5d6","user":{"login":"jdubrule","id":11828477,"avatar_url":"https://avatars.githubusercontent.com/u/11828477?v=3","gravatar_id":"","url":"https://api.github.com/users/jdubrule","html_url":"https://github.com/jdubrule","followers_url":"https://api.github.com/users/jdubrule/followers","following_url":"https://api.github.com/users/jdubrule/following{/other_user}","gists_url":"https://api.github.com/users/jdubrule/gists{/gist_id}","starred_url":"https://api.github.com/users/jdubrule/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdubrule/subscriptions","organizations_url":"https://api.github.com/users/jdubrule/orgs","repos_url":"https://api.github.com/users/jdubrule/repos","events_url":"https://api.github.com/users/jdubrule/events{/privacy}","received_events_url":"https://api.github.com/users/jdubrule/received_events","type":"User","site_admin":false},"repo":{"id":50680993,"name":"bond","full_name":"jdubrule/bond","owner":{"login":"jdubrule","id":11828477,"avatar_url":"https://avatars.githubusercontent.com/u/11828477?v=3","gravatar_id":"","url":"https://api.github.com/users/jdubrule","html_url":"https://github.com/jdubrule","followers_url":"https://api.github.com/users/jdubrule/followers","following_url":"https://api.github.com/users/jdubrule/following{/other_user}","gists_url":"https://api.github.com/users/jdubrule/gists{/gist_id}","starred_url":"https://api.github.com/users/jdubrule/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdubrule/subscriptions","organizations_url":"https://api.github.com/users/jdubrule/orgs","repos_url":"https://api.github.com/users/jdubrule/repos","events_url":"https://api.github.com/users/jdubrule/events{/privacy}","received_events_url":"https://api.github.com/users/jdubrule/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jdubrule/bond","description":"Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services. ","fork":true,"url":"https://api.github.com/repos/jdubrule/bond","forks_url":"https://api.github.com/repos/jdubrule/bond/forks","keys_url":"https://api.github.com/repos/jdubrule/bond/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jdubrule/bond/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jdubrule/bond/teams","hooks_url":"https://api.github.com/repos/jdubrule/bond/hooks","issue_events_url":"https://api.github.com/repos/jdubrule/bond/issues/events{/number}","events_url":"https://api.github.com/repos/jdubrule/bond/events","assignees_url":"https://api.github.com/repos/jdubrule/bond/assignees{/user}","branches_url":"https://api.github.com/repos/jdubrule/bond/branches{/branch}","tags_url":"https://api.github.com/repos/jdubrule/bond/tags","blobs_url":"https://api.github.com/repos/jdubrule/bond/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jdubrule/bond/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jdubrule/bond/git/refs{/sha}","trees_url":"https://api.github.com/repos/jdubrule/bond/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jdubrule/bond/statuses/{sha}","languages_url":"https://api.github.com/repos/jdubrule/bond/languages","stargazers_url":"https://api.github.com/repos/jdubrule/bond/stargazers","contributors_url":"https://api.github.com/repos/jdubrule/bond/contributors","subscribers_url":"https://api.github.com/repos/jdubrule/bond/subscribers","subscription_url":"https://api.github.com/repos/jdubrule/bond/subscription","commits_url":"https://api.github.com/repos/jdubrule/bond/commits{/sha}","git_commits_url":"https://api.github.com/repos/jdubrule/bond/git/commits{/sha}","comments_url":"https://api.github.com/repos/jdubrule/bond/comments{/number}","issue_comment_url":"https://api.github.com/repos/jdubrule/bond/issues/comments{/number}","contents_url":"https://api.github.com/repos/jdubrule/bond/contents/{+path}","compare_url":"https://api.github.com/repos/jdubrule/bond/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jdubrule/bond/merges","archive_url":"https://api.github.com/repos/jdubrule/bond/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jdubrule/bond/downloads","issues_url":"https://api.github.com/repos/jdubrule/bond/issues{/number}","pulls_url":"https://api.github.com/repos/jdubrule/bond/pulls{/number}","milestones_url":"https://api.github.com/repos/jdubrule/bond/milestones{/number}","notifications_url":"https://api.github.com/repos/jdubrule/bond/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jdubrule/bond/labels{/name}","releases_url":"https://api.github.com/repos/jdubrule/bond/releases{/id}","deployments_url":"https://api.github.com/repos/jdubrule/bond/deployments","created_at":"2016-01-29T18:07:09Z","updated_at":"2016-01-29T18:07:12Z","pushed_at":"2016-04-17T19:34:34Z","git_url":"git://github.com/jdubrule/bond.git","ssh_url":"git@github.com:jdubrule/bond.git","clone_url":"https://github.com/jdubrule/bond.git","svn_url":"https://github.com/jdubrule/bond","homepage":null,"size":3844,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"Microsoft:master","ref":"master","sha":"8995cafef60480c7b2d41159df010ce9380e235c","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":28014525,"name":"bond","full_name":"Microsoft/bond","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/bond","description":"Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services. ","fork":false,"url":"https://api.github.com/repos/Microsoft/bond","forks_url":"https://api.github.com/repos/Microsoft/bond/forks","keys_url":"https://api.github.com/repos/Microsoft/bond/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/bond/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/bond/teams","hooks_url":"https://api.github.com/repos/Microsoft/bond/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/bond/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/bond/events","assignees_url":"https://api.github.com/repos/Microsoft/bond/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/bond/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/bond/tags","blobs_url":"https://api.github.com/repos/Microsoft/bond/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/bond/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/bond/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/bond/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/bond/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/bond/languages","stargazers_url":"https://api.github.com/repos/Microsoft/bond/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/bond/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/bond/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/bond/subscription","commits_url":"https://api.github.com/repos/Microsoft/bond/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/bond/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/bond/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/bond/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/bond/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/bond/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/bond/merges","archive_url":"https://api.github.com/repos/Microsoft/bond/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/bond/downloads","issues_url":"https://api.github.com/repos/Microsoft/bond/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/bond/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/bond/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/bond/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/bond/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/bond/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/bond/deployments","created_at":"2014-12-15T01:05:31Z","updated_at":"2016-04-18T14:44:28Z","pushed_at":"2016-04-17T19:34:34Z","git_url":"git://github.com/Microsoft/bond.git","ssh_url":"git@github.com:Microsoft/bond.git","clone_url":"https://github.com/Microsoft/bond.git","svn_url":"https://github.com/Microsoft/bond","homepage":null,"size":4272,"stargazers_count":1302,"watchers_count":1302,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":147,"mirror_url":null,"open_issues_count":35,"forks":147,"open_issues":35,"watchers":1302,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/146"},"html":{"href":"https://github.com/Microsoft/bond/pull/146"},"issue":{"href":"https://api.github.com/repos/Microsoft/bond/issues/146"},"comments":{"href":"https://api.github.com/repos/Microsoft/bond/issues/146/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/146/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/146/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/bond/statuses/d1521e9c8d76502389b3ba4b1e81bfb77acfd5d6"}}}}