#binary-format #minecraft #nbt #io #binary-data #read-write

named-binary-tag

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

9 releases (5 breaking)

0.6.0 Mar 21, 2021
0.5.0 Nov 30, 2020
0.4.0 Nov 4, 2020
0.3.0 Oct 3, 2020
0.1.0 Oct 13, 2019

#203 in Games

Download history 182/week @ 2024-07-28 77/week @ 2024-08-04 67/week @ 2024-08-11 385/week @ 2024-08-18 229/week @ 2024-08-25 165/week @ 2024-09-01 120/week @ 2024-09-08 121/week @ 2024-09-15 76/week @ 2024-09-22 111/week @ 2024-09-29 61/week @ 2024-10-06 62/week @ 2024-10-13 244/week @ 2024-10-20 327/week @ 2024-10-27 394/week @ 2024-11-03 83/week @ 2024-11-10

1,048 downloads per month
Used in 5 crates

MIT license

48KB
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.6"

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