{"id":18463901,"url":"https://github.com/vimpunk/endian","last_synced_at":"2025-04-08T07:32:50.794Z","repository":{"id":117061836,"uuid":"113783802","full_name":"vimpunk/endian","owner":"vimpunk","description":"Ultra light-weight endian utility for C++11 (header only)","archived":false,"fork":false,"pushed_at":"2019-01-20T09:26:54.000Z","size":31,"stargazers_count":25,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T08:51:14.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vimpunk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-12-10T21:10:27.000Z","updated_at":"2024-12-04T02:36:33.000Z","dependencies_parsed_at":"2023-04-30T01:45:51.427Z","dependency_job_id":null,"html_url":"https://github.com/vimpunk/endian","commit_stats":null,"previous_names":["vimpunk/endian"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fendian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fendian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fendian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vimpunk%2Fendian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vimpunk","download_url":"https://codeload.github.com/vimpunk/endian/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796352,"owners_count":20997553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T09:08:20.157Z","updated_at":"2025-04-08T07:32:50.505Z","avatar_url":"https://github.com/vimpunk.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Endian\n\nA small, but much needed utility library for any program that needs to handle numbers during network or file IO.\n\n## Usage\n\nThis is a header-only library, so just place `endian.hpp` in your system wide or project's include directory. Then, use the library by including endian, i.e.:\n```c++\n#include \u003cendian.hpp\u003e\n```\n\n### Working with buffers\n\nConvert from Network Byte Order to Host Byte Order, e.g. when using a receive buffer.\n```c++\nstd::vector\u003cchar\u003e buffer;\n// ... receive data into buffer\nconst int64_t i = endian::read\u003cendian::network, int64_t\u003e(buffer.data());\n```\n\nConvert from Host Byte Order to Network Byte Order, e.g. when using a send buffer.\n```c++\nstd::vector\u003cchar\u003e buffer;\nconst int16_t number = 42; \nendian::write\u003cendian::network\u003e(number, buffer.data());\n```\n\nYou can also read and parse arbitrary width integers in the range [1, 8] specified in bytes .\n```c++\nconst uint32_t three_bytes = 0xaabbcc;\nendian::write\u003cendian::big, 3\u003e(number, buffer.data());\nauto res = endian::read\u003cendian::big, 3\u003e(buffer.data());\nassert(res = three_bytes);\n```\n\nThere are also aliases provided:\n```c++\nendian::write_le\u003c3\u003e(number, buffer.data());\nendian::write_be\u003c3\u003e(number, buffer.data());\nendian::write_le\u003cint32_t\u003e(number, buffer.data());\nendian::write_be\u003cint32_t\u003e(number, buffer.data());\n\nnumber = endian::read_le\u003c5\u003e(buffer.data());\nnumber = endian::read_be\u003c5\u003e(buffer.data());\nnumber = endian::read_le\u003cint64_t\u003e(buffer.data());\nnumber = endian::read_be\u003cint64_t\u003e(buffer.data());\n```\n\n### Platform specific functions\n\nNote that these functions are only available if you're on one of the supported\nplatforms (where host byte order could be determined). As such, the following\nfunctions are conditionally enabled with a preprocessor flag.\n\n#### Reversing byte order\n\n```c++\nconst int16_t a = 0x1234; \nconst int16_t b = endian::reverse(a);\n// b is 0x3412\n```\n\nAlternatively, only reverse byte order if target endianness and host's endianness differ.\n```c++\nconst auto i = endian::conditional_reverse\u003cendian::big\u003e(42);\n```\n\n#### ntoh, hton\n\nConvenience function to conditionally convert to Network Byte Order, same as the POSIX hton function.\n```c++\nconst auto n = endian::host_to_network(h);\n```\n\nConvenience function to conditionally convert from Network Byte Order, same as the POSIX ntoh function.\n```c++\nconst auto h = endian::network_to_host(n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimpunk%2Fendian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvimpunk%2Fendian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvimpunk%2Fendian/lists"}