https://github.com/webfreak001/nbtd
A lightweight NBT decoding/encoding library
https://github.com/webfreak001/nbtd
Last synced: 6 months ago
JSON representation
A lightweight NBT decoding/encoding library
- Host: GitHub
- URL: https://github.com/webfreak001/nbtd
- Owner: WebFreak001
- License: unlicense
- Created: 2015-06-06T16:32:05.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-07-15T10:47:41.000Z (about 1 year ago)
- Last Synced: 2025-08-14T11:45:26.119Z (11 months ago)
- Language: D
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nbtd
A small NBT encoding and decoding library for D.
It supports all Data TAGs in version 19133 and contains a simple API.
## [Documentation](http://nbtd.webfreak.org/)
generated using [MaterialDoc](https://github.com/WebFreak001/MaterialDoc)
## Examples
### Hello World
```D
import std.file;
import nbtd;
void main(string[] args)
{
NBTString helloWorld = new NBTString("Hello World");
write("helloWorld.nbt.gz", helloWorld.encode(true, false));
// helloWorld.nbt.gz will now contain this binary string compressed:
// 11 Hello World
// String Length UTF-8 string
//
// TAG-ID and Name are not written when hasName is false
}
```
### Encoding & Decoding
```D
import std.file;
import nbtd;
void main(string[] args)
{
NBTCompound level = new NBTCompound();
level.name = "Level";
level["players"] = new NBTList([new NBTString("Foo"), new NBTString("Bar")]);
level["seed"] = new NBTLong(48968643157);
write("level.nbt.gz", level.encode());
write("level.nbt", level.encode(false));
NBTCompound imported = new NBTCompound();
imported.decode(cast(ubyte[])read("level.nbt.gz"));
assert(imported.name == "Level");
assert(imported["players"].asList().length == 2);
assert(imported["players"].asList()[0].asString().value == "Foo");
assert(imported["players"].asList()[1].asString().value == "Bar");
assert(imported["seed"].asLong().value == 48968643157);
}
```
## TODO
- [ ] Encoding/Decoding using class schemas
- [ ] Easier interface for files
- [x] Encoding/Decoding ubyte[]
- [x] Encoding/Decoding gzip'd ubyte[]
- [x] Support all v19133 TAGs