2 unstable releases

0.2.0 Dec 29, 2020
0.1.0 Nov 23, 2015

#875 in Encoding

22 downloads per month

Zlib license



Nobility is a Rust crate for encoding and decoding NBT, which is a format used by Minecraft: Java Edition.


  • Decoder which creates few memory allocations
  • Encoder that uses builders instead of heap allocated objects
  • Supports TAG_Long_Array, added in Minecraft 1.12 (all tags as of 2020).
  • Can encode and decode test files correctly (e.g. bigtest.nbt).
  • Supports the Java variant of CESU-8 used for encoding text.
  • Zero usage of unsafe.

This library is based on the spec at https://wiki.vg/NBT#Specification.

Missing features:

  • Serde support. Ran into lifetime issues.
  • CJSON support. Not yet implemented.
  • Bedrock edition support. The format used there is different.
  • Roundtrip encode/decode, as the encoder and decoder use different types.


let mut file = File::open("hello_world.nbt")?;
let mut data = vec![];
file.read_to_end(&mut data)?;
let cursor = std::io::Cursor::new(data);

// Load the document. This step either copies the data (plaintext)
// or decompresses it (gzip).
let doc = Document::load(cursor)?;
// Parses the document. This returns the root tag's name, and the
// root tag (always a Compound tag). Both of these are borrowing the
// data inside the Document.
let (name, root) = doc.parse()?;

println!("name: {}", name.decode()?);
println!("{:#?}", root);


let mut writer = NbtWriter::new();

let mut root = writer.root("hello world");
// finish() call is required.

let result: Vec<u8> = writer.finish();


~10K SLoC