#minecraft #nbt #io

named-binary-tag

Format is used by minecraft for the various files in which it saves data

8 releases (4 breaking)

0.5.0 Nov 30, 2020
0.4.0 Nov 4, 2020
0.3.0 Oct 3, 2020
0.2.3 Oct 26, 2019
0.1.0 Oct 13, 2019

#2 in #minecraft

Download history 42/week @ 2020-11-04 12/week @ 2020-11-11 18/week @ 2020-11-18 37/week @ 2020-11-25 18/week @ 2020-12-02 20/week @ 2020-12-09 115/week @ 2020-12-16 5/week @ 2020-12-23 16/week @ 2020-12-30 55/week @ 2021-01-06 82/week @ 2021-01-13 24/week @ 2021-01-20 25/week @ 2021-01-27 100/week @ 2021-02-03 36/week @ 2021-02-10 41/week @ 2021-02-17

128 downloads per month
Used in 2 crates

MIT license

45KB
1K SLoC

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:

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

Example

Read

use nbt::decode::read_compound_tag;
use std::io::Cursor;

let mut cursor = Cursor::new(include_bytes!("../test/binary/servers.dat").to_vec());
let root_tag = read_compound_tag(&mut cursor).unwrap();

let servers = root_tag.get_compound_tag_vec("servers").unwrap();
assert_eq!(servers.len(), 1);

let server = servers[0];
let ip = server.get_str("ip").unwrap();
let name = server.get_str("name").unwrap();
let hide_address = server.get_bool("hideAddress").unwrap();

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

Write

use nbt::encode::write_compound_tag;
use nbt::CompoundTag;

let mut server = CompoundTag::new();

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

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

let mut root_tag = CompoundTag::new();
root_tag.insert_compound_tag_vec("servers", servers);

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

Dependencies

~480KB