{"id":22632228,"url":"https://github.com/spockbotmc/cpp-nbt","last_synced_at":"2026-03-14T16:36:19.876Z","repository":{"id":150639365,"uuid":"280452534","full_name":"SpockBotMC/cpp-nbt","owner":"SpockBotMC","description":"C++23 NBT serializer","archived":false,"fork":false,"pushed_at":"2022-12-21T12:30:32.000Z","size":89,"stargazers_count":42,"open_issues_count":1,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-25T16:08:36.072Z","etag":null,"topics":["cpp","cpp-library","cpp-nbt","cpp20","header-only","minecraft","nbt"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpockBotMC.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-07-17T14:57:44.000Z","updated_at":"2025-03-21T09:31:34.000Z","dependencies_parsed_at":"2023-06-12T03:45:19.771Z","dependency_job_id":null,"html_url":"https://github.com/SpockBotMC/cpp-nbt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpockBotMC%2Fcpp-nbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpockBotMC%2Fcpp-nbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpockBotMC%2Fcpp-nbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpockBotMC%2Fcpp-nbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpockBotMC","download_url":"https://codeload.github.com/SpockBotMC/cpp-nbt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248473127,"owners_count":21109628,"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","cpp-library","cpp-nbt","cpp20","header-only","minecraft","nbt"],"created_at":"2024-12-09T02:16:52.098Z","updated_at":"2026-03-14T16:36:14.837Z","avatar_url":"https://github.com/SpockBotMC.png","language":"C++","readme":"# cpp-nbt\n\n[![license](https://img.shields.io/badge/license-zlib-lightgrey.svg)](https://en.wikipedia.org/wiki/Zlib_License)\n\n\nThis is a C++23 header-only library for reading/writing\n[Minecraft NBT](https://wiki.vg/NBT) data:\n* Single header file\n* Requires C++23 (GCC 13, Clang 14, MSVC 19.latest)\n* Reads from `istream`s, writes to `ostream`s\n* Supports pretty printing\n\nThis is mostly for me to play with bleeding edge C++ stuff. Don't expect\nthis to compile on anything but trunk.\n\n## Quickstart\n\n`std::map` doesn't work with incomplete types portably, so you need to provide\nyour own (`std::map` may work depending on your platform and stdlib). By\ndefault cpp-nbt uses `boost::container::map`. You can do this by defining\n`NBT_MAP_TYPE` to whatever type you want to use, so long it has a vaguely\n`std::map`-ish API.\n\nInclude nbt.hpp, munch some data.\n\n```cpp\n#define NBT_MAP_TYPE myFavoriteMap\n#include \"nbt.hpp\"\n\nnbt::NBT root {std::ifstream {\"hello_world.nbt\"}};\nstd::cout \u003c\u003c root;\n```\n\n## Tags\n\nAll PC-edition NBT tags are supported, Bedrock is not currently supported.\n\nMost tags map directly to primitive types, the remainder map to STL containers.\n\n| Tag Type | Description |\n| --- | --- |\n| `TagEnd` | `std::nullptr_t` |\n| `TagByte` | `std::int8_t` |\n| `TagShort` | `std::int16_t` |\n| `TagInt` | `std::int32_t` |\n| `TagLong` | `std::int64_t` |\n| `TagFloat` | `float` |\n| `TagDouble` | `double` |\n| `TagByteArray` | `std::vector\u003cTagByte\u003e` |\n| `TagIntArray` | `std::vector\u003cTagInt\u003e` |\n| `TagLongArray` | `std::vector\u003cTagLong\u003e` |\n| `TagString` | `std::string` |\n| `TagList` | `std::variant\u003cstd::vectors\u003cTagEnd\u003e, std::vector\u003cTagByte\u003e, and all other tags\u003e` |\n| `Tag` | `std::variant\u003cTagEnd, TagByte, and all other tags\u003e` |\n| `TagCompound` | `std::map\u003cTagString, Tag\u003e`|\n| `NBTData` | `struct { TagString name; TagCompound tags; }` |\n| `NBT` | `struct {std::optional\u003cNBTData\u003e data; }` |\n\n\n### Constructing and Destructing Tags\n\nJava edition NBT root nodes are always either a TagEnd, or a named TagCompound.\nThese two root nodes are encapsulated by the `NBT` type, which has an\n`encode()` and `decode()` methods to serialize and deserialize NBT. When\nthe TagCompound is present the `data` field will be present, otherwise it\nwill be absent. If absent, the NBT container will serialize to a single `TagEnd`.\n\nExample Usage:\n```cpp\nnbt::NBT root;\nroot.decode(std::ifstream {\"hello_world.nbt\"});\n// Optionally, use the constructor\n// nbt::NBT root {ifs};\n\nroot.encode(std::ofstream {\"out.nbt\"});\n```\n\n### Manipulating Tags\n\nTags must exist inside a container type, and manipulating NBT containers\ninvolves standard usage of the STL.\n\n```cpp\nnbt::NBT root {\"LyricalNBT\", {\n  {\"Hello\", \"World\"},\n  {\"Lyrics\", nbt::TagList {\n      \"There's\", \"a\", \"song\", \"that\", \"we're\", \"singing\",\n  }},\n}};\n\nroot[\"LuckyNumbers\"] = nbt::TagByteArray {1, 3, 7, 9, 13, 15};\nstd::get\u003cnbt::TagByteArray\u003e(root[\"LuckyNumbers\"]).push_back(21);\n\nstd::cout \u003c\u003c root[\"Hello\"] \u003c\u003c std::endl;\nstd::cout \u003c\u003c root \u003c\u003c std::endl;\n```\n\n\n## Issues\n\nPlease open an issue or better yet, a pull request, for any bugs or other\nproblems.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspockbotmc%2Fcpp-nbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspockbotmc%2Fcpp-nbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspockbotmc%2Fcpp-nbt/lists"}