GitHub PullRequestReviewCommentEvent at 2014-11-14 18:22:26
Repository: rippled
Actor: vinniefalco
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/ripple/rippled/pulls/comments/20375821","id":20375821,"diff_hunk":"@@ -0,0 +1,165 @@\n+//------------------------------------------------------------------------------\n+/*\n+    This file is part of Beast: https://github.com/vinniefalco/Beast\n+    Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>\n+\n+    Permission to use, copy, modify, and/or distribute this software for any\n+    purpose  with  or without fee is hereby granted, provided that the above\n+    copyright notice and this permission notice appear in all copies.\n+\n+    THE  SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n+    WITH  REGARD  TO  THIS  SOFTWARE  INCLUDING  ALL  IMPLIED  WARRANTIES  OF\n+    MERCHANTABILITY  AND  FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n+    ANY  SPECIAL ,  DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n+    WHATSOEVER  RESULTING  FROM  LOSS  OF USE, DATA OR PROFITS, WHETHER IN AN\n+    ACTION  OF  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n+    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n+*/\n+//==============================================================================\n+\n+#include <beast/asio/streambuf.h>\n+#include <beast/http/chunked_encoder.h>\n+#include <beast/unit_test/suite.h>\n+\n+namespace beast {\n+namespace http {\n+\n+class chunked_encoder_test : public unit_test::suite\n+{\n+public:\n+    // Convert CR LF to printables for display\n+    static\n+    std::string\n+    encode (std::string const& s)\n+    {\n+        std::string result;\n+        for(auto const c : s)\n+        {\n+            if (c == '\\r')\n+                result += \"\\\\r\";\n+            else if (c== '\\n')\n+                result += \"\\\\n\";\n+            else\n+                result += c;\n+        }\n+        return result;\n+    }\n+\n+    // Print the contents of a ConstBufferSequence to the log\n+    template <class ConstBufferSequence, class Log>\n+    static\n+    void\n+    print (ConstBufferSequence const& buffers, Log log)\n+    {\n+        for(auto const& buf : buffers)\n+            log << encode (std::string(\n+                boost::asio::buffer_cast<char const*>(buf),\n+                    boost::asio::buffer_size(buf)));\n+    } \n+\n+    // Convert a ConstBufferSequence to a string\n+    template <class ConstBufferSequence>\n+    static\n+    std::string\n+    buffer_to_string (ConstBufferSequence const& b)\n+    {\n+        std::string s;\n+        auto const n = boost::asio::buffer_size(b);\n+        s.resize(n);\n+        boost::asio::buffer_copy(\n+            boost::asio::buffer(&s[0], n), b);\n+        return s;\n+    }\n+\n+    // Append a ConstBufferSequence to an existing string\n+    template <class ConstBufferSequence>\n+    static\n+    void\n+    buffer_append (std::string& s, ConstBufferSequence const& b)\n+    {\n+        s += buffer_to_string(b);\n+    }\n+\n+    // Convert the input sequence of the stream to a\n+    // chunked-encoded string. The input sequence is consumed.\n+    template <class Streambuf>\n+    static\n+    std::string\n+    streambuf_to_string_encoded (Streambuf& sb,\n+        bool complete = false)\n+    {\n+        std::string s;\n+        chunked_encoder e;\n+        std::size_t in = 0;\n+        while(sb.size() > 0)\n+        {\n+            in = e.prepare(sb.data());\n+            buffer_append(s, e.data());\n+            sb.consume(in);\n+            e.consume(boost::asio::buffer_size(e.data()));\n+        }\n+        if (complete)\n+        {\n+            e.complete();\n+            buffer_append(s, e.data());\n+            e.consume(boost::asio::buffer_size(e.data()));\n+        }\n+        return s;\n+    }\n+\n+    // Check an input against the correct chunk encoded version\n+    void\n+    check (std::string const& in, std::string const& answer,\n+        bool complete = true)\n+    {\n+        asio::streambuf sb(3);\n+        sb << in;\n+        auto const out = streambuf_to_string_encoded (\n+            sb, true);\n+        if (! expect (out == answer))\n+            log << \"expected\\n\" << answer << \"\\ngot\\n\" << out;\n+    }\n+\n+    void testStreambuf()\n+    {\n+        asio::streambuf sb(3);\n+        std::string const s =\n+            \"......................................................................\"\n+            \"......................................................................\"\n+            \"......................................................................\";\n+        sb << s;\n+        expect(buffer_to_string(sb.data()) == s);\n+    }\n+\n+    void\n+    testEncoder()\n+    {\n+        check(\"\", \"0\\r\\n\\r\\n\");\n+        check(\"x\", \"1\\r\\nx\\r\\n0\\r\\n\\r\\n\");\n+        check(\"abcd\", \"4\\r\\nabcd\\r\\n0\\r\\n\\r\\n\");\n+        check(","path":"src/beast/beast/http/tests/chunked_encoder.test.cpp","position":140,"original_position":140,"commit_id":"8e8c59393cc277f907ec9bb6f687bb93f8a689be","original_commit_id":"e991e4fb4f9ab7536ce4b71423c03009090206c6","user":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"body":"Its zero-copy, there's no \"filling in\". But I will change the text.","created_at":"2014-11-14T18:22:26Z","updated_at":"2014-11-14T18:22:26Z","html_url":"https://github.com/ripple/rippled/pull/721#discussion_r20375821","pull_request_url":"https://api.github.com/repos/ripple/rippled/pulls/721","_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/20375821"},"html":{"href":"https://github.com/ripple/rippled/pull/721#discussion_r20375821"},"pull_request":{"href":"https://api.github.com/repos/ripple/rippled/pulls/721"}}},"pull_request":{"url":"https://api.github.com/repos/ripple/rippled/pulls/721","id":24336860,"html_url":"https://github.com/ripple/rippled/pull/721","diff_url":"https://github.com/ripple/rippled/pull/721.diff","patch_url":"https://github.com/ripple/rippled/pull/721.patch","issue_url":"https://api.github.com/repos/ripple/rippled/issues/721","number":721,"state":"open","locked":false,"title":"Add http::chunked_encoder:","user":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"body":"This transforms a ConstBufferSequence into a new ConstBufferSequence whose\r\ndata is encoded according to the Content transfer encoding rules of RFC2616.\r\nThe implementation does not copy any memory but also does not coalesce\r\nbuffers into larger ones if the input data is in small pieces.\r\nReviewers: @rec @donovanhide","created_at":"2014-11-13T00:17:54Z","updated_at":"2014-11-14T18:22:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7826e5ac4aa8f91c4faab5c620d54ce1717e889c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ripple/rippled/pulls/721/commits","review_comments_url":"https://api.github.com/repos/ripple/rippled/pulls/721/comments","review_comment_url":"https://api.github.com/repos/ripple/rippled/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ripple/rippled/issues/721/comments","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/8e8c59393cc277f907ec9bb6f687bb93f8a689be","head":{"label":"vinniefalco:chunked","ref":"chunked","sha":"8e8c59393cc277f907ec9bb6f687bb93f8a689be","user":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"repo":{"id":10961863,"name":"rippled","full_name":"vinniefalco/rippled","owner":{"login":"vinniefalco","id":1503976,"avatar_url":"https://avatars.githubusercontent.com/u/1503976?v=3","gravatar_id":"","url":"https://api.github.com/users/vinniefalco","html_url":"https://github.com/vinniefalco","followers_url":"https://api.github.com/users/vinniefalco/followers","following_url":"https://api.github.com/users/vinniefalco/following{/other_user}","gists_url":"https://api.github.com/users/vinniefalco/gists{/gist_id}","starred_url":"https://api.github.com/users/vinniefalco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinniefalco/subscriptions","organizations_url":"https://api.github.com/users/vinniefalco/orgs","repos_url":"https://api.github.com/users/vinniefalco/repos","events_url":"https://api.github.com/users/vinniefalco/events{/privacy}","received_events_url":"https://api.github.com/users/vinniefalco/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vinniefalco/rippled","description":"Ripple peer-to-peer network daemon","fork":true,"url":"https://api.github.com/repos/vinniefalco/rippled","forks_url":"https://api.github.com/repos/vinniefalco/rippled/forks","keys_url":"https://api.github.com/repos/vinniefalco/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vinniefalco/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vinniefalco/rippled/teams","hooks_url":"https://api.github.com/repos/vinniefalco/rippled/hooks","issue_events_url":"https://api.github.com/repos/vinniefalco/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/vinniefalco/rippled/events","assignees_url":"https://api.github.com/repos/vinniefalco/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/vinniefalco/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/vinniefalco/rippled/tags","blobs_url":"https://api.github.com/repos/vinniefalco/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vinniefalco/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vinniefalco/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/vinniefalco/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vinniefalco/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/vinniefalco/rippled/languages","stargazers_url":"https://api.github.com/repos/vinniefalco/rippled/stargazers","contributors_url":"https://api.github.com/repos/vinniefalco/rippled/contributors","subscribers_url":"https://api.github.com/repos/vinniefalco/rippled/subscribers","subscription_url":"https://api.github.com/repos/vinniefalco/rippled/subscription","commits_url":"https://api.github.com/repos/vinniefalco/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/vinniefalco/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/vinniefalco/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/vinniefalco/rippled/issues/comments/{number}","contents_url":"https://api.github.com/repos/vinniefalco/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/vinniefalco/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vinniefalco/rippled/merges","archive_url":"https://api.github.com/repos/vinniefalco/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vinniefalco/rippled/downloads","issues_url":"https://api.github.com/repos/vinniefalco/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/vinniefalco/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/vinniefalco/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/vinniefalco/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vinniefalco/rippled/labels{/name}","releases_url":"https://api.github.com/repos/vinniefalco/rippled/releases{/id}","created_at":"2013-06-26T07:51:04Z","updated_at":"2014-08-27T20:02:56Z","pushed_at":"2014-11-14T17:30:46Z","git_url":"git://github.com/vinniefalco/rippled.git","ssh_url":"git@github.com:vinniefalco/rippled.git","clone_url":"https://github.com/vinniefalco/rippled.git","svn_url":"https://github.com/vinniefalco/rippled","homepage":"https://ripple.com","size":68555,"stargazers_count":4,"watchers_count":4,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":4,"default_branch":"develop"}},"base":{"label":"ripple:develop","ref":"develop","sha":"0829ee9234338c1f7facc304a3f27eefa1c27daa","user":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"repo":{"id":2724167,"name":"rippled","full_name":"ripple/rippled","owner":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ripple/rippled","description":"Ripple peer-to-peer network daemon","fork":false,"url":"https://api.github.com/repos/ripple/rippled","forks_url":"https://api.github.com/repos/ripple/rippled/forks","keys_url":"https://api.github.com/repos/ripple/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ripple/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ripple/rippled/teams","hooks_url":"https://api.github.com/repos/ripple/rippled/hooks","issue_events_url":"https://api.github.com/repos/ripple/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/ripple/rippled/events","assignees_url":"https://api.github.com/repos/ripple/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/ripple/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/ripple/rippled/tags","blobs_url":"https://api.github.com/repos/ripple/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ripple/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ripple/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/ripple/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/ripple/rippled/languages","stargazers_url":"https://api.github.com/repos/ripple/rippled/stargazers","contributors_url":"https://api.github.com/repos/ripple/rippled/contributors","subscribers_url":"https://api.github.com/repos/ripple/rippled/subscribers","subscription_url":"https://api.github.com/repos/ripple/rippled/subscription","commits_url":"https://api.github.com/repos/ripple/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/ripple/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/ripple/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/ripple/rippled/issues/comments/{number}","contents_url":"https://api.github.com/repos/ripple/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/ripple/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ripple/rippled/merges","archive_url":"https://api.github.com/repos/ripple/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ripple/rippled/downloads","issues_url":"https://api.github.com/repos/ripple/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/ripple/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/ripple/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/ripple/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ripple/rippled/labels{/name}","releases_url":"https://api.github.com/repos/ripple/rippled/releases{/id}","created_at":"2011-11-07T04:40:15Z","updated_at":"2014-11-12T05:35:10Z","pushed_at":"2014-11-12T00:59:27Z","git_url":"git://github.com/ripple/rippled.git","ssh_url":"git@github.com:ripple/rippled.git","clone_url":"https://github.com/ripple/rippled.git","svn_url":"https://github.com/ripple/rippled","homepage":"https://ripple.com","size":100449,"stargazers_count":872,"watchers_count":872,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":231,"mirror_url":null,"open_issues_count":140,"forks":231,"open_issues":140,"watchers":872,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/721"},"html":{"href":"https://github.com/ripple/rippled/pull/721"},"issue":{"href":"https://api.github.com/repos/ripple/rippled/issues/721"},"comments":{"href":"https://api.github.com/repos/ripple/rippled/issues/721/comments"},"review_comments":{"href":"https://api.github.com/repos/ripple/rippled/pulls/721/comments"},"review_comment":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ripple/rippled/pulls/721/commits"},"statuses":{"href":"https://api.github.com/repos/ripple/rippled/statuses/8e8c59393cc277f907ec9bb6f687bb93f8a689be"}}}}