Up-to-date Rust crate for easy and intuitive working with NBT data.
CrabNBT combines best features of existing NBT crates, to create perfect solution.
Big thanks to simdnbt and fastnbt for ideas!
🚧 Support for serializing to/from Struct (soon)
✅ Java string support
✅ NBT! macro for easy creation
✅ Good system of getting values from NBT
✅ Serializing for single tags
✅ Support of Network NBT
cargo add crab_nbt
use crab_nbt::{nbt, Nbt, NbtCompound};
fn main() {
// Using NBT macro
let nbt = nbt!("root nbt_inner name", {
"float": 1.0,
"key": "value",
"long_array": [L; 1],
"int_array": [Int; 1],
"list": ["a", "b", "c"],
"nbt_inner": {
"key": "sub value"
}
});
let nbt = Nbt::new(
"root",
NbtCompound::from_values(vec![
("float", 1.0.into()),
("key", "value".into()),
("nbt_inner", NbtCompound::from_values(vec![
("key", "sub value".into()),
]).into())
])
);
}
use bytes::Bytes;
use crab_nbt::{nbt, Nbt, NbtCompound};
fn example(bytes: &mut Bytes) {
let nbt = Nbt::read(bytes).unwrap();
let egg_name = nbt
.get_compound("nbt_inner")
.and_then(|compound| compound.get_compound("egg"))
.and_then(|compound| compound.get_string("name"))
.unwrap();
}