nobility

Crates.ionobility
lib.rsnobility
version0.2.0
sourcesrc
created_at2015-11-23 04:57:10.384808
updated_at2020-12-29 02:50:10.259218
descriptionNBT decoder
homepage
repositoryhttps://github.com/tiffany352/nobility
max_upload_size
id3479
size66,710
Tiffany Bennett (tiffany352)

documentation

README

Nobility

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

Features:

  • 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.

Decoding

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);

Encoding

let mut writer = NbtWriter::new();

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

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

cargo fmt