{"action":"created","comment":{"url":"https://api.github.com/repos/steinwurf/endian/pulls/comments/175083875","pull_request_review_id":104558177,"id":175083875,"diff_hunk":"@@ -1,284 +1,142 @@\n-// Copyright (c) 2016 Steinwurf ApS\n+// Copyright (c) 2018 Steinwurf ApS\n // All Rights Reserved\n //\n // Distributed under the \"BSD License\". See the accompanying LICENSE.rst file.\n \n #pragma once\n \n #include <cassert>\n-#include <cstdint>\n #include <cstring>\n+#include <cstdint>\n #include <limits>\n-#include <type_traits>\n+\n+#include \"helpers.hpp\"\n \n namespace endian\n {\n namespace detail\n {\n-template<class ValueType, uint8_t Bytes>\n-struct big\n-{\n-    static void put(ValueType value, uint8_t* buffer);\n-    static void get(ValueType& value, const uint8_t* buffer);\n-};\n \n-template<class ValueType>\n-struct big<ValueType, 1>\n+// Where the actual conversion takes place\n+template<class ValueType, uint8_t Bytes>\n+struct big_impl\n {\n-    static void put(ValueType value, uint8_t* buffer)\n-    {\n-        static_assert(sizeof(ValueType) <= 1, \"ValueType too big.\");\n-        assert(buffer != nullptr);\n-        *buffer = value;\n-    }\n-\n-    static void get(ValueType& value, const uint8_t* buffer)\n+    static void put(ValueType& value, uint8_t* buffer)\n     {\n-        static_assert(sizeof(ValueType) >= 1, \"ValueType too small.\");\n-        assert(buffer != nullptr);\n-        value = *buffer;\n-    }\n-};\n+        big_impl<ValueType, Bytes - 1>::put(value, buffer + 1);\n \n-template<class ValueType>\n-struct big<ValueType, 2>\n-{\n-    static void put(ValueType value, uint8_t* buffer)\n-    {\n-        static_assert(sizeof(ValueType) <= 2, \"ValueType too big.\");\n-        assert(buffer != nullptr);\n-        buffer[1] = ((value >> 0) & 0xFF);\n-        buffer[0] = ((value >> 8) & 0xFF);\n+        value = (value >> 8);\n+        *buffer = value & 0xFF;\n     }\n \n     static void get(ValueType& value, const uint8_t* buffer)\n     {\n-        static_assert(sizeof(ValueType) >= 2, \"ValueType too small.\");\n-        assert(buffer != nullptr);\n-        value = (((ValueType) buffer[0]) << 8) |\n-                (((ValueType) buffer[1]) << 0);\n-    }\n-};\n-\n-template<class ValueType>\n-struct big<ValueType, 3>\n-{\n-    static void put(ValueType value, uint8_t* buffer)\n-    {\n-        static_assert(std::is_unsigned<ValueType>::value, \"Must be unsigned\");\n-        assert(buffer != nullptr);\n-        assert(value <= 0x00FFFFFF);\n-        buffer[2] = ((value >> 0) & 0xFF);\n-        buffer[1] = ((value >> 8) & 0xFF);\n-        buffer[0] = ((value >> 16) & 0xFF);\n-    }\n+        value |= ((ValueType) *buffer);\n+        value = (value << 8);\n \n-    static void get(ValueType& value, const uint8_t* buffer)\n-    {\n-        static_assert(sizeof(ValueType) >= 3, \"ValueType too small.\");\n-        static_assert(std::is_unsigned<ValueType>::value, \"must be unsigned\");\n-        assert(buffer != nullptr);\n-        value = (((ValueType) buffer[0]) << 16) |\n-                (((ValueType) buffer[1]) << 8)  |\n-                (((ValueType) buffer[2]) << 0);\n+        big_impl<ValueType, Bytes - 1>::get(value, buffer + 1);\n     }\n };\n \n template<class ValueType>\n-struct big<ValueType, 4>\n+struct big_impl<ValueType, 1>\n {\n-    static void put(ValueType value, uint8_t* buffer)\n-    {\n-        static_assert(sizeof(ValueType) <= 4, \"ValueType too big.\");\n-        assert(buffer != nullptr);\n-        buffer[3] = ((value >> 0) & 0xFF);\n-        buffer[2] = ((value >> 8) & 0xFF);\n-        buffer[1] = ((value >> 16) & 0xFF);\n-        buffer[0] = ((value >> 24) & 0xFF);\n-    }\n \n-    static void get(ValueType& value, const uint8_t* buffer)\n-    {\n-        static_assert(sizeof(ValueType) >= 4, \"ValueType too small.\");\n-        assert(buffer != nullptr);\n-        value = (((ValueType) buffer[0]) << 24) |\n-                (((ValueType) buffer[1]) << 16) |\n-                (((ValueType) buffer[2]) << 8)  |\n-                (((ValueType) buffer[3]) << 0);\n-    }\n-};\n-\n-template<class ValueType>\n-struct big<ValueType, 5>\n-{\n-    static void put(ValueType value, uint8_t* buffer)\n+    static void put(ValueType& value, uint8_t* buffer)\n     {\n-        static_assert(std::is_unsigned<ValueType>::value, \"Must be unsigned\");\n-        assert(buffer != nullptr);\n-        assert(value <= 0x000000FFFFFFFFFF);\n-        buffer[4] = ((value >> 0) & 0xFF);\n-        buffer[3] = ((value >> 8) & 0xFF);\n-        buffer[2] = ((value >> 16) & 0xFF);\n-        buffer[1] = ((value >> 24) & 0xFF);\n-        buffer[0] = ((value >> 32) & 0xFF);\n+        *buffer = value & 0xFF;\n     }\n \n     static void get(ValueType& value, const uint8_t* buffer)\n     {\n-        static_assert(sizeof(ValueType) >= 5, \"ValueType too small.\");\n-        static_assert(std::is_unsigned<ValueType>::value, \"Must be unsigned\");\n-        assert(buffer != nullptr);\n-        value = (((ValueType) buffer[0]) << 32) |\n-                (((ValueType) buffer[1]) << 24) |\n-                (((ValueType) buffer[2]) << 16) |\n-                (((ValueType) buffer[3]) << 8)  |\n-                (((ValueType) buffer[4]) << 0);\n+        value |= ((ValueType) *buffer);\n     }\n };\n \n-template<class ValueType>\n-struct big<ValueType, 6>\n+\n+// Helper to delegate to the appropiate specialization depednign on the type","path":"src/endian/big_endian.hpp","position":160,"original_position":160,"commit_id":"b9ee89b5ec7a63547a41fbeb647ceb34d403008f","original_commit_id":"b9ee89b5ec7a63547a41fbeb647ceb34d403008f","user":{"login":"jpihl","id":583663,"avatar_url":"https://avatars3.githubusercontent.com/u/583663?v=4","gravatar_id":"","url":"https://api.github.com/users/jpihl","html_url":"https://github.com/jpihl","followers_url":"https://api.github.com/users/jpihl/followers","following_url":"https://api.github.com/users/jpihl/following{/other_user}","gists_url":"https://api.github.com/users/jpihl/gists{/gist_id}","starred_url":"https://api.github.com/users/jpihl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpihl/subscriptions","organizations_url":"https://api.github.com/users/jpihl/orgs","repos_url":"https://api.github.com/users/jpihl/repos","events_url":"https://api.github.com/users/jpihl/events{/privacy}","received_events_url":"https://api.github.com/users/jpihl/received_events","type":"User","site_admin":false},"body":"Spalling","created_at":"2018-03-16T13:10:02Z","updated_at":"2018-03-16T13:18:14Z","html_url":"https://github.com/steinwurf/endian/pull/29#discussion_r175083875","pull_request_url":"https://api.github.com/repos/steinwurf/endian/pulls/29","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/comments/175083875"},"html":{"href":"https://github.com/steinwurf/endian/pull/29#discussion_r175083875"},"pull_request":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/steinwurf/endian/pulls/29","id":174941418,"html_url":"https://github.com/steinwurf/endian/pull/29","diff_url":"https://github.com/steinwurf/endian/pull/29.diff","patch_url":"https://github.com/steinwurf/endian/pull/29.patch","issue_url":"https://api.github.com/repos/steinwurf/endian/issues/29","number":29,"state":"open","locked":false,"title":"Recursive implementation","user":{"login":"janusheide","id":569445,"avatar_url":"https://avatars3.githubusercontent.com/u/569445?v=4","gravatar_id":"","url":"https://api.github.com/users/janusheide","html_url":"https://github.com/janusheide","followers_url":"https://api.github.com/users/janusheide/followers","following_url":"https://api.github.com/users/janusheide/following{/other_user}","gists_url":"https://api.github.com/users/janusheide/gists{/gist_id}","starred_url":"https://api.github.com/users/janusheide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janusheide/subscriptions","organizations_url":"https://api.github.com/users/janusheide/orgs","repos_url":"https://api.github.com/users/janusheide/repos","events_url":"https://api.github.com/users/janusheide/events{/privacy}","received_events_url":"https://api.github.com/users/janusheide/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-03-14T12:36:45Z","updated_at":"2018-03-16T13:18:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8889dc52a972f4e83e9d4f140e39bdbef8ee0135","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/steinwurf/endian/pulls/29/commits","review_comments_url":"https://api.github.com/repos/steinwurf/endian/pulls/29/comments","review_comment_url":"https://api.github.com/repos/steinwurf/endian/pulls/comments{/number}","comments_url":"https://api.github.com/repos/steinwurf/endian/issues/29/comments","statuses_url":"https://api.github.com/repos/steinwurf/endian/statuses/b9ee89b5ec7a63547a41fbeb647ceb34d403008f","head":{"label":"steinwurf:recursive-implementation","ref":"recursive-implementation","sha":"b9ee89b5ec7a63547a41fbeb647ceb34d403008f","user":{"login":"steinwurf","id":1279612,"avatar_url":"https://avatars3.githubusercontent.com/u/1279612?v=4","gravatar_id":"","url":"https://api.github.com/users/steinwurf","html_url":"https://github.com/steinwurf","followers_url":"https://api.github.com/users/steinwurf/followers","following_url":"https://api.github.com/users/steinwurf/following{/other_user}","gists_url":"https://api.github.com/users/steinwurf/gists{/gist_id}","starred_url":"https://api.github.com/users/steinwurf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steinwurf/subscriptions","organizations_url":"https://api.github.com/users/steinwurf/orgs","repos_url":"https://api.github.com/users/steinwurf/repos","events_url":"https://api.github.com/users/steinwurf/events{/privacy}","received_events_url":"https://api.github.com/users/steinwurf/received_events","type":"Organization","site_admin":false},"repo":{"id":51446286,"name":"endian","full_name":"steinwurf/endian","owner":{"login":"steinwurf","id":1279612,"avatar_url":"https://avatars3.githubusercontent.com/u/1279612?v=4","gravatar_id":"","url":"https://api.github.com/users/steinwurf","html_url":"https://github.com/steinwurf","followers_url":"https://api.github.com/users/steinwurf/followers","following_url":"https://api.github.com/users/steinwurf/following{/other_user}","gists_url":"https://api.github.com/users/steinwurf/gists{/gist_id}","starred_url":"https://api.github.com/users/steinwurf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steinwurf/subscriptions","organizations_url":"https://api.github.com/users/steinwurf/orgs","repos_url":"https://api.github.com/users/steinwurf/repos","events_url":"https://api.github.com/users/steinwurf/events{/privacy}","received_events_url":"https://api.github.com/users/steinwurf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/steinwurf/endian","description":"C++ library for conversion between big and little endian data representations.","fork":false,"url":"https://api.github.com/repos/steinwurf/endian","forks_url":"https://api.github.com/repos/steinwurf/endian/forks","keys_url":"https://api.github.com/repos/steinwurf/endian/keys{/key_id}","collaborators_url":"https://api.github.com/repos/steinwurf/endian/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/steinwurf/endian/teams","hooks_url":"https://api.github.com/repos/steinwurf/endian/hooks","issue_events_url":"https://api.github.com/repos/steinwurf/endian/issues/events{/number}","events_url":"https://api.github.com/repos/steinwurf/endian/events","assignees_url":"https://api.github.com/repos/steinwurf/endian/assignees{/user}","branches_url":"https://api.github.com/repos/steinwurf/endian/branches{/branch}","tags_url":"https://api.github.com/repos/steinwurf/endian/tags","blobs_url":"https://api.github.com/repos/steinwurf/endian/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/steinwurf/endian/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/steinwurf/endian/git/refs{/sha}","trees_url":"https://api.github.com/repos/steinwurf/endian/git/trees{/sha}","statuses_url":"https://api.github.com/repos/steinwurf/endian/statuses/{sha}","languages_url":"https://api.github.com/repos/steinwurf/endian/languages","stargazers_url":"https://api.github.com/repos/steinwurf/endian/stargazers","contributors_url":"https://api.github.com/repos/steinwurf/endian/contributors","subscribers_url":"https://api.github.com/repos/steinwurf/endian/subscribers","subscription_url":"https://api.github.com/repos/steinwurf/endian/subscription","commits_url":"https://api.github.com/repos/steinwurf/endian/commits{/sha}","git_commits_url":"https://api.github.com/repos/steinwurf/endian/git/commits{/sha}","comments_url":"https://api.github.com/repos/steinwurf/endian/comments{/number}","issue_comment_url":"https://api.github.com/repos/steinwurf/endian/issues/comments{/number}","contents_url":"https://api.github.com/repos/steinwurf/endian/contents/{+path}","compare_url":"https://api.github.com/repos/steinwurf/endian/compare/{base}...{head}","merges_url":"https://api.github.com/repos/steinwurf/endian/merges","archive_url":"https://api.github.com/repos/steinwurf/endian/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/steinwurf/endian/downloads","issues_url":"https://api.github.com/repos/steinwurf/endian/issues{/number}","pulls_url":"https://api.github.com/repos/steinwurf/endian/pulls{/number}","milestones_url":"https://api.github.com/repos/steinwurf/endian/milestones{/number}","notifications_url":"https://api.github.com/repos/steinwurf/endian/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/steinwurf/endian/labels{/name}","releases_url":"https://api.github.com/repos/steinwurf/endian/releases{/id}","deployments_url":"https://api.github.com/repos/steinwurf/endian/deployments","created_at":"2016-02-10T14:32:36Z","updated_at":"2018-01-22T18:46:50Z","pushed_at":"2018-03-16T12:49:00Z","git_url":"git://github.com/steinwurf/endian.git","ssh_url":"git@github.com:steinwurf/endian.git","clone_url":"https://github.com/steinwurf/endian.git","svn_url":"https://github.com/steinwurf/endian","homepage":"","size":331,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"steinwurf:master","ref":"master","sha":"7f137feb10052ad4dccd322fe3e4b8b9346a6faf","user":{"login":"steinwurf","id":1279612,"avatar_url":"https://avatars3.githubusercontent.com/u/1279612?v=4","gravatar_id":"","url":"https://api.github.com/users/steinwurf","html_url":"https://github.com/steinwurf","followers_url":"https://api.github.com/users/steinwurf/followers","following_url":"https://api.github.com/users/steinwurf/following{/other_user}","gists_url":"https://api.github.com/users/steinwurf/gists{/gist_id}","starred_url":"https://api.github.com/users/steinwurf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steinwurf/subscriptions","organizations_url":"https://api.github.com/users/steinwurf/orgs","repos_url":"https://api.github.com/users/steinwurf/repos","events_url":"https://api.github.com/users/steinwurf/events{/privacy}","received_events_url":"https://api.github.com/users/steinwurf/received_events","type":"Organization","site_admin":false},"repo":{"id":51446286,"name":"endian","full_name":"steinwurf/endian","owner":{"login":"steinwurf","id":1279612,"avatar_url":"https://avatars3.githubusercontent.com/u/1279612?v=4","gravatar_id":"","url":"https://api.github.com/users/steinwurf","html_url":"https://github.com/steinwurf","followers_url":"https://api.github.com/users/steinwurf/followers","following_url":"https://api.github.com/users/steinwurf/following{/other_user}","gists_url":"https://api.github.com/users/steinwurf/gists{/gist_id}","starred_url":"https://api.github.com/users/steinwurf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steinwurf/subscriptions","organizations_url":"https://api.github.com/users/steinwurf/orgs","repos_url":"https://api.github.com/users/steinwurf/repos","events_url":"https://api.github.com/users/steinwurf/events{/privacy}","received_events_url":"https://api.github.com/users/steinwurf/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/steinwurf/endian","description":"C++ library for conversion between big and little endian data representations.","fork":false,"url":"https://api.github.com/repos/steinwurf/endian","forks_url":"https://api.github.com/repos/steinwurf/endian/forks","keys_url":"https://api.github.com/repos/steinwurf/endian/keys{/key_id}","collaborators_url":"https://api.github.com/repos/steinwurf/endian/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/steinwurf/endian/teams","hooks_url":"https://api.github.com/repos/steinwurf/endian/hooks","issue_events_url":"https://api.github.com/repos/steinwurf/endian/issues/events{/number}","events_url":"https://api.github.com/repos/steinwurf/endian/events","assignees_url":"https://api.github.com/repos/steinwurf/endian/assignees{/user}","branches_url":"https://api.github.com/repos/steinwurf/endian/branches{/branch}","tags_url":"https://api.github.com/repos/steinwurf/endian/tags","blobs_url":"https://api.github.com/repos/steinwurf/endian/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/steinwurf/endian/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/steinwurf/endian/git/refs{/sha}","trees_url":"https://api.github.com/repos/steinwurf/endian/git/trees{/sha}","statuses_url":"https://api.github.com/repos/steinwurf/endian/statuses/{sha}","languages_url":"https://api.github.com/repos/steinwurf/endian/languages","stargazers_url":"https://api.github.com/repos/steinwurf/endian/stargazers","contributors_url":"https://api.github.com/repos/steinwurf/endian/contributors","subscribers_url":"https://api.github.com/repos/steinwurf/endian/subscribers","subscription_url":"https://api.github.com/repos/steinwurf/endian/subscription","commits_url":"https://api.github.com/repos/steinwurf/endian/commits{/sha}","git_commits_url":"https://api.github.com/repos/steinwurf/endian/git/commits{/sha}","comments_url":"https://api.github.com/repos/steinwurf/endian/comments{/number}","issue_comment_url":"https://api.github.com/repos/steinwurf/endian/issues/comments{/number}","contents_url":"https://api.github.com/repos/steinwurf/endian/contents/{+path}","compare_url":"https://api.github.com/repos/steinwurf/endian/compare/{base}...{head}","merges_url":"https://api.github.com/repos/steinwurf/endian/merges","archive_url":"https://api.github.com/repos/steinwurf/endian/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/steinwurf/endian/downloads","issues_url":"https://api.github.com/repos/steinwurf/endian/issues{/number}","pulls_url":"https://api.github.com/repos/steinwurf/endian/pulls{/number}","milestones_url":"https://api.github.com/repos/steinwurf/endian/milestones{/number}","notifications_url":"https://api.github.com/repos/steinwurf/endian/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/steinwurf/endian/labels{/name}","releases_url":"https://api.github.com/repos/steinwurf/endian/releases{/id}","deployments_url":"https://api.github.com/repos/steinwurf/endian/deployments","created_at":"2016-02-10T14:32:36Z","updated_at":"2018-01-22T18:46:50Z","pushed_at":"2018-03-16T12:49:00Z","git_url":"git://github.com/steinwurf/endian.git","ssh_url":"git@github.com:steinwurf/endian.git","clone_url":"https://github.com/steinwurf/endian.git","svn_url":"https://github.com/steinwurf/endian","homepage":"","size":331,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/29"},"html":{"href":"https://github.com/steinwurf/endian/pull/29"},"issue":{"href":"https://api.github.com/repos/steinwurf/endian/issues/29"},"comments":{"href":"https://api.github.com/repos/steinwurf/endian/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/steinwurf/endian/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/steinwurf/endian/statuses/b9ee89b5ec7a63547a41fbeb647ceb34d403008f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"jpihl"}}