{"id":19157767,"url":"https://github.com/coyorkdow/liteproto","last_synced_at":"2025-05-07T08:34:04.997Z","repository":{"id":183013447,"uuid":"657612941","full_name":"coyorkdow/liteproto","owner":"coyorkdow","description":"A native C++17 reflection and serialization library [work in progress]","archived":false,"fork":false,"pushed_at":"2023-08-09T18:08:56.000Z","size":141,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T20:53:27.592Z","etag":null,"topics":["cpp","cpp17","reflection-library","template-meta-programming"],"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/coyorkdow.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":"2023-06-23T12:50:05.000Z","updated_at":"2024-03-04T09:55:16.000Z","dependencies_parsed_at":"2024-11-09T08:42:08.018Z","dependency_job_id":"ad537198-736c-4ed1-8187-474c9c06159e","html_url":"https://github.com/coyorkdow/liteproto","commit_stats":null,"previous_names":["coyorkdow/liteproto"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fliteproto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fliteproto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fliteproto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coyorkdow%2Fliteproto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coyorkdow","download_url":"https://codeload.github.com/coyorkdow/liteproto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252843275,"owners_count":21812847,"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","cpp17","reflection-library","template-meta-programming"],"created_at":"2024-11-09T08:42:02.521Z","updated_at":"2025-05-07T08:34:04.971Z","avatar_url":"https://github.com/coyorkdow.png","language":"C++","readme":"# liteproto\nA native C++17 reflection and serialization library.\n\nDefine a serializable class (called `Message`), and use reflection to inspect and modify its fields. Meanwhile you can use this class just like any other class.\nThe principle of the liteproto is to use Macro as little as possible, and make the syntax as close as possible to the C++'s native class definition.\nTherefore, I came up with a syntax which is very similar to the protobuf. And it reaches a very strong flexibility.\nYou can define any constructor and member function for a `Message`. Moreover, a `Message` can be template or inherit other class.\n\n---\n**This Project is still work in progress. The first release is not ready yet. I am still working on my reflect system.**\n\n---\n\n## Quick Start\n\nWith the following codes, we defined a reflectable class which called `FirstMessage`. It has 5 reflectable fields. Besides, we can use it as any other normal C++ class, define the constructors, destructor, or any member function.\n\nThe `StaticReflect` use the static reflection to dump all fields into a tuple. We can get or update the original object's value through this tuple. Here, we changed the message's value.\n\nFinally, we use dynamical reflection to print the structure and values of the message. Since the codes of the dyncamical reflection is complicate, we don't paste the implementation here. The full codes can be see in [example/first_message/first_message.cpp](example/first_message/first_message.cpp).\n\n```C++\nMESSAGE(FirstMessage) {\n  int FIELD(foo) -\u003e Seq\u003c1\u003e;\n  double FIELD(bar) -\u003e Seq\u003c2\u003e;\n  std::string FIELD(baz) -\u003e Seq\u003c3\u003e;\n  std::vector\u003cstd::deque\u003cint\u003e\u003e FIELD(d2list) -\u003e Seq\u003c4\u003e;\n  std::list\u003cstd::string\u003e FIELD(strlist) -\u003e Seq\u003c5\u003e;\n\n  FirstMessage() : foo_(0), bar_(0) {}\n};\n\nvoid StaticReflect(FirstMessage\u0026 msg) {\n  auto tuple = msg.DumpTuple();\n  std::get\u003c0\u003e(tuple)++;\n  std::get\u003c1\u003e(tuple) -= 5;\n  std::get\u003c2\u003e(tuple).append(\"str\");\n  std::get\u003c3\u003e(tuple).emplace_back(std::deque{5, 6, 7});\n  std::get\u003c4\u003e(tuple).emplace_back(\"abcdefg\");\n}\n\nvoid DynamicalReflect(liteproto::Message\u0026 msg) {\n  for (size_t i = 0; i \u003c msg.FieldsSize(); i++) {\n    std::cout \u003c\u003c msg.FieldName(i) \u003c\u003c \": \";\n    liteproto::Object object = msg.Field(i);\n    if (object.Descriptor().KindEnum() == liteproto::Kind::NUMBER) {\n      auto number = liteproto::NumberCast(object);  // number is a std::optional\n      PrintNumber(number.value());\n    } else if (object.Descriptor().KindEnum() == liteproto::Kind::STRING) {\n      auto str = liteproto::StringCast(object);\n      std::cout \u003c\u003c '\\\"' \u003c\u003c str-\u003estr() \u003c\u003c '\\\"';\n    } else if (object.Descriptor().KindEnum() == liteproto::Kind::LIST) {\n      PrintDynamicalList(object);\n    }\n    std::cout \u003c\u003c '\\n';\n  }\n}\n\nint main() {\n  FirstMessage first_msg;\n  first_msg.set_foo(1);\n  first_msg.set_bar(1.5);\n  first_msg.set_baz(\"str\");\n  first_msg.mutable_d2list().emplace_back(std::deque{1, 2, 3, 4});\n  first_msg.mutable_strlist().emplace_back(\"abc\");\n  StaticReflect(first_msg);\n  DynamicalReflect(first_msg);\n  /*\nDynamicalReflect will print\nfoo: 2\nbar: -3.5\nbaz: \"strstr\"\nd2list: [[1, 2, 3, 4], [5, 6, 7]]\nstrlist: [\"abc\", \"abcdefg\"]\n  */\n  return 0;\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoyorkdow%2Fliteproto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoyorkdow%2Fliteproto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoyorkdow%2Fliteproto/lists"}