{"id":23552271,"url":"https://github.com/onyazuka/serializer","last_synced_at":"2026-06-28T18:31:55.249Z","repository":{"id":144020662,"uuid":"179641965","full_name":"onyazuka/Serializer","owner":"onyazuka","description":"Simple C++ serializer","archived":false,"fork":false,"pushed_at":"2020-02-25T12:44:53.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-15T17:13:48.134Z","etag":null,"topics":["containers","cpp","cpp17","deserialization","fast","serialization"],"latest_commit_sha":null,"homepage":null,"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/onyazuka.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-05T08:06:46.000Z","updated_at":"2020-02-25T12:45:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"af877286-419d-4612-85b2-604d4f2ed66d","html_url":"https://github.com/onyazuka/Serializer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/onyazuka/Serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onyazuka%2FSerializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onyazuka%2FSerializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onyazuka%2FSerializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onyazuka%2FSerializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onyazuka","download_url":"https://codeload.github.com/onyazuka/Serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onyazuka%2FSerializer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34900367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["containers","cpp","cpp17","deserialization","fast","serialization"],"created_at":"2024-12-26T11:10:01.385Z","updated_at":"2026-06-28T18:31:55.222Z","avatar_url":"https://github.com/onyazuka.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serializer\nSimple C++ serializer\n\n\u003ch2\u003eDescription\u003c/h2\u003e\nSimple c++ serialization library.\nIt allows you to serialize such types:\n\u003cul\u003e\n\u003cli\u003eSimple arithmetic types\u003c/li\u003e\n\u003cli\u003eArrays\u003c/li\u003e\n\u003cli\u003eAll std containers\u003c/li\u003e\n\u003cli\u003eYour custom types\u003c/li\u003e\n\u003c/ul\u003e\nIt makes a std::string, filled with binary data, on output. Why use std::string? Later, you can write it to a file or make some manipulations and write it somewhere after that.\n\n\u003ch2\u003eRequirements\u003c/h2\u003e\nIt is just one header, without any dependencies. So, any c++ compiler that supports c++17 should be ok, but I have only tested it with g++.\n\n\u003ch2\u003eExamples\u003c/h2\u003e\nFirst of all you should include \"serializer.hpp\" header and, if you want, do \"using namespace Serialization;\".\n\nThen, let's try to serialize some simple type:\n```Cpp\nint i = 5; \t\t\t\t\t\t\t// your value\nstd::string buf;\t\t// your buffer\nBytesCount b = Serializer::SerializeUnit\u003cint\u003e::serializeUnit(buf, \u0026i);\n```\nHere, 'b' is the number of bytes that was read;\n\nAnd after that, you can try to get your number back:\n```Cpp\nint i1;\nb = Deserializer::DeserializeUnit\u003cint\u003e::deserializeUnit(buf, 0, \u0026i);\n```\nHere, the second argument of deserializeUnit is the offset, from which value in the 'buf' will be looked for.\n\nIt is very convenient to use the 'serializeAll' function. It uses variadic templates, and with it you could serialize a bunch of things just in one line:\n```Cpp\nbuf.clear();\ndouble d = 1.1;\nstd::unordered_map\u003cint, std::string\u003e um{{1, \"neko\"}, {2, \"wanko\"}, {3, \"manko\"}};\nstd::vector\u003cstd::vector\u003cstd::string\u003e\u003e vvs{{\"some\", \"thing\"}, {\"some\", \"other\", \"thing\"}};\nb = Serializer::serializeAll(buf, \u0026um, \u0026d, \u0026vvs);\n\n// getting back\ndecltype(um) um1;\ndecltype(vvs) vvs1;\ndecltype(d) d1;\n\nb = Deserializer::deserializeAll(buf, 0, \u0026um1, \u0026d1, \u0026vvs1);\n```\nTo serialize array types(including std::array), you shoud use ArrayWrapper\u003cT\u003e from Serialization namespace:\n```Cpp\nbuf.clear();\nint* pi = new int[10];\n... // initializng 'i'\nArrayWrapper aw{pi, 10};\nb = Serializer::serializeAll(buf, \u0026aw);\n```\nAs you can see, pointers are used as arguments, so if you try to pass a raw pointer as a parameter, just the first value of this type starting from the passed address will be processed.\n\nAnd, to get it back, we should use ArrayWrapper again.\nWARNING: before deserialization, memory for array should be already allocated:\n```Cpp\nArrayWrapper\u003cint\u003e aw1;\naw11.start = new int[5];\nb = Deserializer::deserializeAll(buf, 0, \u0026aw1);\n```\n\nAnd, of course, you can serialize your own objects. Here you have two options:\n- If serialization/deserialization of your object can be done only in one way, you should inherit Serializable/Deserializable class(or both):\n```Cpp\nstruct User : public Serialization::Serializable, public Serialization::Deserializable\n{\n    std::string name;\n    int age;\n    std::vector\u003cstd::string\u003e hobbies;\n\n    S::BytesCount serialize(std::string \u0026buf)\n    {\n        return S::Serializer::serializeAll(buf, \u0026name, \u0026age, \u0026hobbies);\n    }\n\n    S::BytesCount deserialize(const std::string\u0026 buf, S::BytesCount offset)\n    {\n        return S::Deserializer::deserializeAll(buf, offset, \u0026name, \u0026age, \u0026hobbies);\n    }\n};\n\n...\n\nUser user;\nuser.age = 22;\nuser.name = \"Vasya\";\nuser.hobbies = {\"swimming\", \"anime\", \"fishing\"};\n\nstd::string buf;\nBytesCount b = Serializer::serializeAll(buf, \u0026user);\n\n```\n\n- If serialization/deserialization of your object can be done in multiple ways, you should inherit MultipleSerializable/MultipleDeserializable(or both):\n```Cpp\nstruct Cat : public MultipleSerializable, public MultipleDeserializable\n{\n    enum {NameLegsSerializer, AllSerializer, NameLegsDeserializer, AllDeserializer};\n    Cat()\n        : MultipleSerializable{}, MultipleDeserializable{}\n    {\n        registerSerializer(SerializerId(NameLegsSerializer), [this](std::string\u0026 buf) { return Serializer::serializeAll(buf, \u0026name, \u0026legs); } );\n        registerSerializer(SerializerId(AllSerializer), [this](std::string\u0026 buf) { return Serializer::serializeAll(buf, \u0026name, \u0026legs, \u0026age, \u0026places_to_sleep); } );\n        registerDeserializer(SerializerId(NameLegsDeserializer), [this](const std::string\u0026 buf, BytesCount offset) { return Deserializer::deserializeAll(buf, offset, \u0026name, \u0026legs); } );\n        registerDeserializer(SerializerId(AllDeserializer), [this](const std::string\u0026 buf, BytesCount offset) { return Deserializer::deserializeAll(buf, offset, \u0026name, \u0026legs, \u0026age, \u0026places_to_sleep); } );\n    }\n    std::string name;\n    int legs;\n    short age;\n    std::vector\u003cstd::string\u003e places_to_sleep;\n};\n\n...\n\nCat cat;\ncat.age = 5;\ncat.legs = 4;\ncat.name = \"Sugrob\";\ncat.places_to_sleep = std::move(std::vector\u003cstd::string\u003e{\"chair\", \"laptop\", \"my head\"});\ncat.setSerializerId((SerializerId)(Cat::AllSerializer));\n\nSerializer::serializeAll(buf, \u0026cat);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonyazuka%2Fserializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonyazuka%2Fserializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonyazuka%2Fserializer/lists"}