{"id":18406474,"url":"https://github.com/georgiifirsov/podserializer","last_synced_at":"2025-04-12T20:29:05.748Z","repository":{"id":159274026,"uuid":"238294419","full_name":"GeorgiiFirsov/PodSerializer","owner":"GeorgiiFirsov","description":"Library used to serialize and deserialize any POD-structure (and some non-POD structs) with no modifications applied to them. Here I use a lot of templates and other meta-magic :)","archived":false,"fork":false,"pushed_at":"2021-04-17T16:44:49.000Z","size":188,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T04:29:07.091Z","etag":null,"topics":["cplusplus","cplusplus-14","cpp","cpp14","pods","serialization","templates"],"latest_commit_sha":null,"homepage":"https://georgyfirsov.github.io/articles/cpp_reflection.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GeorgiiFirsov.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":"2020-02-04T20:00:36.000Z","updated_at":"2022-11-08T07:38:04.000Z","dependencies_parsed_at":"2023-06-11T16:10:42.995Z","dependency_job_id":null,"html_url":"https://github.com/GeorgiiFirsov/PodSerializer","commit_stats":null,"previous_names":["georgiifirsov/podserializer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2FPodSerializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2FPodSerializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2FPodSerializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeorgiiFirsov%2FPodSerializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GeorgiiFirsov","download_url":"https://codeload.github.com/GeorgiiFirsov/PodSerializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248628477,"owners_count":21136087,"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":["cplusplus","cplusplus-14","cpp","cpp14","pods","serialization","templates"],"created_at":"2024-11-06T03:09:14.759Z","updated_at":"2025-04-12T20:29:05.689Z","avatar_url":"https://github.com/GeorgiiFirsov.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PodSerializer\n\n| Compiler | Version | Status             | Comments                                                               |\n|----------|---------|--------------------|------------------------------------------------------------------------|\n| MSVC     | 19.22   | [![Success][]]()   | Main build system.                                                     |\n| MSVC     | 19.16   | [![Partial][]]()   | Precise reflection doesn't work on MSVC 19.16                          |\n| GCC      | 6.1     | [![Partial][]]()   | `GetFieldsCount`, `FromTuple` and `GetTypeList` are compiled and tested successfully. |\n| CLang    | 6.0.0   | [![Partial][]]()   | `GetFieldsCount` and `FromTuple` are compiled and tested successfully. |\n\n[Success]:   https://img.shields.io/badge/Build%20Status-pass-success\n[Partial]:   https://img.shields.io/badge/Build%20Status-partially%20passed-important\n[Failed]:    https://img.shields.io/badge/Build%20Status-fail-critical\n[NotTested]: https://img.shields.io/badge/Build%20Status-not%20built%20yet-inactive\n\nPodSerializer is actually two-in-one library: it contains various static reflection tools along with classes for serialization of POD's.\nNow it is possible to serialize some non-POD's into `StringStreamSerializer`. Also you can convert them into a tuple with `ToTuplePrecise` and `ToStandardTuplePrecise` methods.\n\n\u003e Developing in progress\n\n\u003e Documentation in progress\n\n## Brief introduction and review\n### Serialization\n\nCurrently are fully developed two ways to serialize POD's: to binary buffer and to I/O streams. Main featores of serialization tools from this library can be included with `Serialization.h` and `StreamOperators.h` files. Here is an example:\n```cpp\nstruct MyStruct\n{\n  char field1;\n  int  field2;\n};\n\n// ...\n\nMyStruct original{ 'a', 42 };\nMyStruct loaded{ '\\0', 0 };\n\nBinarySerializer\u003cMyStruct\u003e serializer;    // Serializer class (it is a specialization of generic template)\nBinaryBuffer\u003cMyStruct\u003e buffer;            // Buffer instance to hold serialized value\n\nserializer.Serialize( original, buffer ); // Save our struct\n\nassert( !buffer.IsEmpty() );              // Here buffer will never be empty\n\nserializer.Deserialize( loaded, buffer ); // Now load data into a new variable\n\nassert( original.field1 == loaded.field1 ); // Ensure equality of fields of loaded and original structs\nassert( original.field2 == loaded.field2 );\n```\n\nSerialization to I/O streams differs from example above only by usage of classes `StringStreamSerializer` and `StringStreamBuffer` instead of `BinarySerializer` and `BinaryBuffer` respectively.\n\nMoreover now you are allowed to write the following code:\n\n```cpp\n#include \"StreamOperators.h\"\n\nusing namespace io_operators;\n\n// ...\n\n// No operators \u003c\u003c and \u003e\u003e are defined for MyStruct!!!\nMyStruct obj{ 'a', 42 };\n\nstd::cout \u003c\u003c obj; // Will print \"a 42\"\nstd::cin \u003e\u003e obj;  // Input each field from keyboard and put them directly into 'obj'\n```\n\n### Reflection\n\nAnother half of th library contains several reflection tools. All of them can be included with file `Reflection.h`. Using this header you can now look inside of some POD structure and, for instance, enumerate each its field (I wish I could find out names of fields... But today it is impossible in C++). Here is a couple examples:\n\n##### Example #1\n```cpp\n#include \"Reflection.h\"\n\nusing namespace io_operators;\n\nstruct MyStruct\n{\n  int    field1;\n  double field2;\n  char   field3;\n};\n\n// ...\n\nMyStruct obj{ 42, 3.14, 'a' };\n\nstd::cout \u003c\u003c \"MyStruct has \"                   // Will print \"MyStruct has 3 fields\"\n          \u003c\u003c reflection::GetFieldsCount( obj ) \n          \u003c\u003c \" fields\" \u003c\u003c std::endl;\n```\n\n##### Example #2\n```cpp\n#include \"Reflection.h\"\n#include \"Tuple.h\" // Here is rewritten tuple class and some tools for it\n\n// ...\n\nMyStruct obj{ 42, 3.14, 'a' };\n\n// Convert our struct into a tuple\nauto tpl = reflection::ToTuple( obj ); // tpl is instance of type types::Tuple\u003cint, double, char\u003e\n\nassert( types::get\u003c0\u003e( tpl ) == obj.field1 ); // Tuple contains exactly the same values as 'obj'\nassert( types::get\u003c1\u003e( tpl ) == obj.field2 );\nassert( types::get\u003c2\u003e( tpl ) == obj.field3 );\n\n// Will be printed: \"42 3.14 a\"\n// It is really important to use a generic lambda (with template invocation function) inside types::for_each\ntypes::for_each( tpl, []( const auto\u0026 elem ) {\n  std::cout \u003c\u003c elem \u003c\u003c \" \";\n});\n```\n\n##### Example #3\n```cpp\n#include \u003ctuple\u003e\n\n#include \"Reflection.h\"\n#include \"Tuple.h\"\n\n// ...\n\nMyStruct obj{ 42, 3.14, 'a' };\n\n// You can convert your struct into a standard tuple\nauto tpl = reflection::ToStandardTuple( obj ); // tpl is instance of type std::tuple\u003cint, double, char\u003e\n\nassert( std::get\u003c0\u003e( tpl ) == obj.field1 ); // Tuple contains exactly the same values as 'obj'\nassert( std::get\u003c1\u003e( tpl ) == obj.field2 );\nassert( std::get\u003c2\u003e( tpl ) == obj.field3 );\n\n//\n// Moreover you can use ToStdTuple function to convert types::Typle into corresponding std::tuple\n//\n```\n\n##### Example #4\n```cpp\n#include \"Reflection.h\"\n#include \"Tuple.h\"\n\n// ...\n\nMyStruct obj{ 42, 2.71, 'a' };\ntypes::Tuple\u003cint, double, char\u003e tpl{ -42, 2.71, 'b' };\n\n// Load values from tuple directly into 'obj'\nobj = reflection::FromTuple\u003cMyStruct\u003e( tpl );\n\nassert( obj.field1 == -42  ); // 'obj' now contains exactly the same values as tuple\nassert( obj.field2 == 2.71 );\nassert( obj.field3 == 'b'  );\n```\n\n##### Example #5\n\n```cpp\n#include \"StreamOperators.h\"\n#include \"Reflection.h\"\n#include \"Tuple.h\"\n\nusing namespace io_operators;\n\nstruct Person \n{\n    std::string m_name;\n    size_t m_age;\n};\n\n// ...\n\nPerson bob{ \"Bob\", 45 };\n\nstd::cout \u003c\u003c bob;                     // will print: Bob 45\nstd::cout \u003c\u003c beautiful_struct \u003c\u003c bob; // will print: { Bob, 45 }\n\nauto bob_tpl = ToTuplePrecise( bob );\n\n// Will print: Bob is 45 years old.\nstd::cout \u003c\u003c types::get\u003c0\u003e( bob_tpl ) \u003c\u003c \" is \" \n          \u003c\u003c types::get\u003c1\u003e( bob_tpl ) \u003c\u003c \" years old.\" \u003c\u003c std::endl;\n```\n\n## Requirements\n- C++14 support.\n- Reflected (serialization uses reflection inside) structure must not contain static fields (they are simply ignored), bit-fields (they can cause some errors), unions and references. *Currently* pointers are not supported too (coming soon).\n- Reflected struct must be constexpr aggregate initializable.\n- Other limitations are listed in file [Support.h](https://github.com/GeorgyFirsov/PodSerializer/blob/master/PodSerializer/Support.h)\n\n## License\n[GNU General Public License v3.0](https://github.com/GeorgyFirsov/PodSerializer/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgiifirsov%2Fpodserializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgiifirsov%2Fpodserializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgiifirsov%2Fpodserializer/lists"}