named-binary-tag

crates.io Build Status codecov

NBT (Named Binary Tag) is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data.

Usage

Add this to your Cargo.toml:

toml [dependencies] named-binary-tag = "0.5"

Example

Read

```rust use nbt::decode::readcompoundtag; use std::io::Cursor;

let mut cursor = Cursor::new(includebytes!("../test/binary/servers.dat").tovec()); let roottag = readcompound_tag(&mut cursor).unwrap();

let servers = roottag.getcompoundtagvec("servers").unwrap(); assert_eq!(servers.len(), 1);

let server = servers[0]; let ip = server.getstr("ip").unwrap(); let name = server.getstr("name").unwrap(); let hideaddress = server.getbool("hideAddress").unwrap();

asserteq!(ip, "localhost:25565"); asserteq!(name, "Minecraft Server"); assert!(hide_address); ```

Write

```rust use nbt::encode::writecompoundtag; use nbt::CompoundTag;

let mut server = CompoundTag::new();

server.insertstr("ip", "localhost:25565"); server.insertstr("name", "Minecraft Server"); server.insert_bool("hideAddress", true);

let mut servers = Vec::new(); servers.push(server);

let mut roottag = CompoundTag::new(); roottag.insertcompoundtag_vec("servers", servers);

let mut vec = Vec::new(); writecompoundtag(&mut vec, &root_tag).unwrap(); ```