{"id":13645638,"url":"https://github.com/google/libnop","last_synced_at":"2025-04-04T10:06:39.671Z","repository":{"id":29070009,"uuid":"118494580","full_name":"google/libnop","owner":"google","description":"libnop: C++ Native Object Protocols","archived":false,"fork":false,"pushed_at":"2024-08-11T06:54:26.000Z","size":387,"stargazers_count":576,"open_issues_count":11,"forks_count":59,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-28T09:04:01.900Z","etag":null,"topics":["cpp-library","cpp14","serialization-engine","serialization-format","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-22T18:03:27.000Z","updated_at":"2025-02-18T22:08:24.000Z","dependencies_parsed_at":"2024-01-14T09:57:57.294Z","dependency_job_id":"0b034bf5-22e2-43d9-bafd-b672cc592bfc","html_url":"https://github.com/google/libnop","commit_stats":{"total_commits":189,"total_committers":5,"mean_commits":37.8,"dds":"0.021164021164021163","last_synced_commit":"35e800d81f28c632956c5a592e3cbe8085ecd430"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flibnop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flibnop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flibnop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flibnop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/libnop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247155548,"owners_count":20893060,"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-library","cpp14","serialization-engine","serialization-format","serialization-library"],"created_at":"2024-08-02T01:02:38.852Z","updated_at":"2025-04-04T10:06:39.651Z","avatar_url":"https://github.com/google.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# libnop: C++ Native Object Protocols\n\nlibnop is a header-only library for serializing and deserializing C++ data\ntypes without external code generators or runtime support libraries. The only\nmandatory requirement is a compiler that supports the C++14 standard.\n\nNote: This is not an officially supported Google product at this time.\n\n## Goals\n\nlibnop has the following goals:\n\n  * Make simple serialization tasks easy and complex tasks tractable.\n  * Remove the need to use code generators and schema files to describe data\n    types, formats, and protocols: perform these tasks naturally within the C++\n    language.\n  * Avoid additional runtime support requirements for serialization.\n  * Provide contemporary features such as bidirectional binary compatibility,\n    data validation, type safety, and type fungibility.\n  * Handle intrinsic types, common STL types and containers, and user-defined\n    types with a minimum of effort.\n  * Produce optimized code that is easy to analyze and profile.\n  * Avoid internal dynamic memory allocation when possible.\n\n## Getting Started\n\nTake a look at [Getting Started](docs/getting-started.md) for an introduction to\nthe library.\n\n## Quick Examples\n\nHere is a quick series of examples to demonstrate how libnop is used. You can\nfind more examples in the repository under [examples/](examples/).\n\n### Writing STL Containers to a Stream\n\n```C++\n#include \u003ciostream\u003e\n#include \u003cmap\u003e\n#include \u003csstream\u003e\n#include \u003cutility\u003e\n#include \u003cvector\u003e\n\n#include \u003cnop/serializer.h\u003e\n#include \u003cnop/utility/stream_writer.h\u003e\n\nint main(int argc, char** argv) {\n  using Writer = nop::StreamWriter\u003cstd::stringstream\u003e;\n  nop::Serializer\u003cWriter\u003e serializer;\n\n  serializer.Write(std::vector\u003cint\u003e{1, 2, 3, 4});\n  serializer.Write(std::vector\u003cstd::string\u003e{\"foo\", \"bar\", \"baz\"});\n\n  using MapType =\n      std::map\u003cstd::uint32_t, std::pair\u003cstd::uint64_t, std::string\u003e\u003e;\n  serializer.Write(\n      MapType{{0, {10, \"foo\"}}, {1, {20, \"bar\"}}, {2, {30, \"baz\"}}});\n\n  const std::string data = serializer.writer().stream().str();\n  std::cout \u003c\u003c \"Wrote \" \u003c\u003c data.size() \u003c\u003c \" bytes.\" \u003c\u003c std::endl;\n  return 0;\n}\n```\n\n### Simple User-Defined Types\n\n```C++\n#include \u003ccstdint\u003e\n#include \u003ciostream\u003e\n#include \u003csstream\u003e\n#include \u003cstring\u003e\n#include \u003cvector\u003e\n\n#include \u003cnop/serializer.h\u003e\n#include \u003cnop/structure.h\u003e\n#include \u003cnop/utility/stream_writer.h\u003e\n\nnamespace example {\n\nstruct Person {\n  std::string name;\n  std::uint32_t age_years;\n  std::uint8_t height_inches;\n  std::uint16_t weight_pounds;\n  NOP_STRUCTURE(Person, name, age_years, height_inches, weight_pounds);\n};\n\n}  // namespace example\n\nint main(int argc, char** argv) {\n  using Writer = nop::StreamWriter\u003cstd::stringstream\u003e;\n  nop::Serializer\u003cWriter\u003e serializer;\n\n  serializer.Write(example::Person{\"John Doe\", 37, 72, 180});\n  serializer.Write(std::vector\u003cexample::Person\u003e{\n      {\"John Doe\", 37, 72, 180}, {\"Jane Doe\", 36, 69, 130}});\n\n  const std::string data = serializer.writer().stream().str();\n  std::cout \u003c\u003c \"Wrote \" \u003c\u003c data.size() \u003c\u003c \" bytes.\" \u003c\u003c std::endl;\n  return 0;\n}\n```\n\n### More Complex User-Defined Types\n\n```C++\n#include \u003carray\u003e\n#include \u003ciostream\u003e\n#include \u003csstream\u003e\n#include \u003cstring\u003e\n\n#include \u003cnop/serializer.h\u003e\n#include \u003cnop/structure.h\u003e\n#include \u003cnop/utility/stream_writer.h\u003e\n\nnamespace example {\n\n// Contrived template type with private members.\ntemplate \u003ctypename T\u003e\nstruct UserDefined {\n public:\n  UserDefined() = default;\n  UserDefined(std::string label, std::vector\u003cT\u003e vector)\n      : label_{std::move(label)}, vector_{std::move(vector)} {}\n\n  const std::string label() const { return label_; }\n  const std::vector\u003cT\u003e\u0026 vector() const { return vector_; }\n\n private:\n  std::string label_;\n  std::vector\u003cT\u003e vector_;\n\n  NOP_STRUCTURE(UserDefined, label_, vector_);\n};\n\n}  // namespace example\n\nint main(int argc, char** argv) {\n  using Writer = nop::StreamWriter\u003cstd::stringstream\u003e;\n  nop::Serializer\u003cWriter\u003e serializer;\n\n  serializer.Write(example::UserDefined\u003cint\u003e{\"ABC\", {1, 2, 3, 4, 5}});\n\n  using ArrayType = std::array\u003cexample::UserDefined\u003cfloat\u003e, 2\u003e;\n  serializer.Write(\n      ArrayType{{{\"ABC\", {1, 2, 3, 4, 5}}, {\"XYZ\", {3.14, 2.72, 23.14}}}});\n\n  const std::string data = serializer.writer().stream().str();\n  std::cout \u003c\u003c \"Wrote \" \u003c\u003c data.size() \u003c\u003c \" bytes.\" \u003c\u003c std::endl;\n  return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Flibnop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Flibnop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Flibnop/lists"}