{"id":21380427,"url":"https://github.com/redskittlefox/binarylove3","last_synced_at":"2025-07-13T13:30:37.154Z","repository":{"id":54671272,"uuid":"333927343","full_name":"RedSkittleFox/BinaryLove3","owner":"RedSkittleFox","description":"Simple C++ 20 Serialization Library that works out of the box with aggregate types!","archived":false,"fork":false,"pushed_at":"2021-09-11T23:26:05.000Z","size":81,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-03T02:54:33.761Z","etag":null,"topics":["cpp","cpp20","cpp20-library","serialization","serialization-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedSkittleFox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-28T20:35:43.000Z","updated_at":"2023-06-01T09:29:57.000Z","dependencies_parsed_at":"2022-08-13T23:30:42.126Z","dependency_job_id":null,"html_url":"https://github.com/RedSkittleFox/BinaryLove3","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedSkittleFox%2FBinaryLove3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedSkittleFox%2FBinaryLove3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedSkittleFox%2FBinaryLove3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedSkittleFox%2FBinaryLove3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedSkittleFox","download_url":"https://codeload.github.com/RedSkittleFox/BinaryLove3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225885811,"owners_count":17539640,"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":["cpp","cpp20","cpp20-library","serialization","serialization-library"],"created_at":"2024-11-22T10:40:21.431Z","updated_at":"2024-11-22T10:40:21.967Z","avatar_url":"https://github.com/RedSkittleFox.png","language":"C++","readme":"![MSVC](https://github.com/RedSkittleFox/BinaryLove3/workflows/Build%20Demo/badge.svg)\n![Unit Tests](https://github.com/RedSkittleFox/BinaryLove3/workflows/VS%20Test%20Platform/badge.svg)\n\n# BinaryLove3\nSimple C++ 20 Serialization Library that works out of the box with aggregate types!\n\n# Requirements\nBinaryLove3 is a c++20 only library. \nLibrary can serialize only types matching these requirements:\n* trivial types (e.g. `uint32_t`, `struct { uint32_t a; float_t b; }`): \n  \n  Types matching requirements for [`std::is_trivial`](https://en.cppreference.com/w/cpp/types/is_trivial).\n* agregate types (e.g. `std::pair`, `struct { uint32_t a; std::vector\u003cuint32_t\u003e b; }`):\n  \n  Types matching requirements for [`std::is_aggregate`](https://en.cppreference.com/w/cpp/types/is_aggregate).\n* iterable types (e.g. `std::vector`):\n  \n  Type is required to be compatible with [`std::begin`](https://en.cppreference.com/w/cpp/iterator/begin), [`std::end`](https://en.cppreference.com/w/cpp/iterator/end) and [`std::inserter`](https://en.cppreference.com/w/cpp/iterator/inserter). Additionally member type `value_type` is also required.\n  \n  If type's iterator fulfils [`std::random_access_iterator`](https://en.cppreference.com/w/cpp/iterator/random_access_iterator) requirement and `value_type` matches requirement [`is_trivial`](https://en.cppreference.com/w/cpp/types/is_trivial) then optimisations will be made. \n\n* types providing specializations for `BinaryLove3::serialize` and `BinaryLove3::deserialize`. Refer to [Providing custom serialization methods](https://github.com/RedSkittleFox/BinaryLove3#providing-custom-serialization-methods)\n\n# Usage\n```cpp\n// demo.cpp\n\n#include \u003ciostream\u003e\n#include \u003cvector\u003e\n#include \u003cstring\u003e\n#include \u003ccstdint\u003e\n#include \u003cstring\u003e\n#include \u003clist\u003e\n\n#include \"BinaryLove3.hpp\"\n\nstruct foo\n{\n\tuint32_t v0 = 3;\n\tuint32_t v1 = 2;\n\tfloat_t v2 = 2.5f;\n\tchar v3 = 'c';\n\tstruct\n\t{\n\t\tstd::vector\u003cint\u003e vec_of_trivial = { 1, 2, 3 };\n\t\tstd::vector\u003cstd::string\u003e vec_of_nontrivial = { \"I am a Fox!\", \"In a big Box!\" };\n\t\tstd::string str = \"Foxes can fly!\";\n\t\tstd::list\u003cint\u003e non_random_access_container = { 3, 4, 5 };\n\t} non_trivial;\n\tstruct\n\t{\n\t\tuint32_t v0 = 1;\n\t\tuint32_t v1 = 2;\n\t} trivial;\n};\n\nauto main() -\u003e int32_t\n{\n\tfoo out = { 4, 5, 6.7f, 'd', {{5, 4, 3, 2}, {\"cc\", \"dd\"}, \"Fly me to the moon...\" , {7, 8, 9}}, {3, 4} };\n\tauto data = BinaryLove3::serialize(bobux);\n\t\n\tfoo in;\n\tBinaryLove3::deserialize(data, in);\n\treturn int32_t(0);\n}\n```\n\n# Providing custom serialization methods.\nOne can provide custom serialization methods by creating specializations for the following functions:\n* `std::vector\u003cstd::byte\u003e serialize(const T\u0026 var_)`\n* `bool deserialize(const std::byte*\u0026 cur_, const std::byte* end_, T\u0026 obj_)`\n\n```cpp\n#include \u003cBinaryLove3\u003e\n\nclass foo\n{\n  friend std::vector\u003cstd::byte\u003e serialize(const foo\u0026 var_);\n  friend bool deserialize(const std::byte*\u0026 cur_, const std::byte* end_, foo\u0026 obj_);\nprivate:\n  uint32_t m_a;\n  std::vector\u003cuint32_t\u003e m_b;\npublic:\n  void foo_method();\n}\n\nstd::vector\u003cstd::byte\u003e serialize(const foo\u0026 var_)\n{\n  auto ret = BinaryLove3::serialize(var_.m_a);\n  auto data = BinaryLove3::serialize(var_.m_b);\n  ret.insert(std::end(insert), std::begin(data), std::end(data));\n  return ret;\n}\n\nbool deserialize(const std::byte*\u0026 cur_, const std::byte* end_, foo\u0026 obj_)\n{\n  uint32_t a;\n  std::vector\u003cuint32_t\u003e b;\n  if(!BinaryLove3::deserialize(cur_, end_, a))\n    return false;\n  \n  if(!BinaryLove3::deserialize(cur_, end_, b))\n    return false;\n    \n  obj_.m_a = std::move(a);\n  obj_.m_b = std::move(b);\n  \n  return true;\n}\n```\n\n# Notes\nThis library works only with up to 10 member variables of an aggregate type right now. This will be expanded in the near future. Cheers!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredskittlefox%2Fbinarylove3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredskittlefox%2Fbinarylove3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredskittlefox%2Fbinarylove3/lists"}