Expand description
This module provides functionality for reading, manipulating, and writing NBT data. It supports both Java and Bedrock data formats.
§Example
use commandblock::nbt::{read_from_file, write_to_file, NbtValue, Compression, Endian};
use std::collections::HashMap;
use std::path::PathBuf;
// Read NBT data from a file
let path = PathBuf::from("./tests/data/bedrock_level.dat");
let (name, mut value) = read_from_file(path, Compression::Uncompressed, Endian::Little).unwrap();
// Manipulate the NBT data which automatically converts to NbtValue's
value.insert("test".to_string(), "Hello, world!");
let mut inner_compound = HashMap::new();
inner_compound.insert("isTest".to_string(), NbtValue::Byte(1));
inner_compound.insert("numberTests".to_string(), NbtValue::Int(123));
value.insert("test2".to_string(), inner_compound);
// Write the manipulated NBT data to a new file
let path = PathBuf::from("./tests/data/test.dat");
write_to_file(Some(&name), value, path, Compression::Uncompressed, Endian::Little).unwrap();Structs§
- NbtReader
NbtReaderis a struct that reads NBT data from a reader and interprets it according to the specified endian style.- NbtWriter
NbtWriteris a struct that writes NBT data to a writer encoding it according to the specified endian style.
Enums§
- Compression
- Enum representing the different types of compression that can be used.
- Endian
- Enum representing the endianness of the data.
- NbtError
- Enum representing the different types of NBT errors that can occur.
- NbtValue
- Enum representing the different types of NBT (Named Binary Tag) values that can be used. These types are used to represent data in a Minecraft world file.
Functions§
- read_
from_ file - Reads an NBT file from the given path, decompresses it if necessary, and returns the parsed NBT value.
- read_
from_ reader - Reads an NBT file from the given reader, decompresses it if necessary, and returns the parsed NBT value.
- write_
to_ file - Writes an NBT file to the requested path using the given compression and endian style. If the file already exists, it will overwrite the existing data.
- write_
to_ writer - Writes an NBT data to the given writer using the given compression and endian style.