Expand description
Support for serializing and deserializing compounds in Java edition’s binary format.
§Examples
use valence_nbt::{compound, to_binary, Compound, List};
let c = compound! {
"byte" => 5_i8,
"string" => "hello",
"list_of_float" => List::Float(vec![
std::f32::consts::PI,
std::f32::consts::E,
1.4142
]),
};
let mut buf = vec![];
to_binary(&c, &mut buf, "").unwrap();
Decode NBT data from its binary form.
use valence_nbt::{compound, from_binary, Compound, Value};
let some_bytes = [10, 0, 0, 3, 0, 3, 105, 110, 116, 0, 0, 222, 173, 0];
let expected_value = compound! {
"int" => 0xdead
};
let (nbt, root_name) = from_binary(&mut some_bytes.as_slice()).unwrap();
assert_eq!(nbt, expected_value);
assert_eq!(root_name, "");
Structs§
Traits§
- A string type which can be decoded from Java’s modified UTF-8.
- A string type which can be encoded into Java’s modified UTF-8.
Functions§
- Decodes uncompressed NBT binary data from the provided slice.
- Encodes uncompressed NBT binary data to the provided writer.
- Returns the number of bytes that will be written when
to_binary
is called with this compound and root name.