#nbt #minecraft #java #edition #tags #compound #versatile

ussr-nbt

A very fast and versatile NBT library for Minecraft: Java Edition

5 releases

0.2.1 Aug 12, 2024
0.2.0 Aug 11, 2024
0.1.2 Aug 10, 2024
0.1.1 Aug 10, 2024
0.1.0 Aug 10, 2024

#120 in Games

Download history 160/week @ 2024-08-05 121/week @ 2024-08-12 19/week @ 2024-09-16 6/week @ 2024-09-23 9/week @ 2024-09-30 24/week @ 2024-10-21 43/week @ 2024-10-28 24/week @ 2024-11-04

91 downloads per month

MIT license

180KB
2K SLoC

ussr-nbt

A very fast and versatile NBT library for Minecraft: Java Edition.

Some features of this library:

  • A borrow module for avoiding most allocations and all copying.
  • An API that differentiates between full (Nbt) and partial (Compound, Tag, List) NBT values.
  • Support for TAG_Long_Array introduced in Minecraft 1.12.
  • Support for the modified UTF-8 encoding of strings that Java uses.

Usage

use std::net::TcpStream;

use ussr_nbt::owned::*;

fn main() {
    let mut conn: TcpStream = TcpStream::connect("127.0.0.1:25565").unwrap();
    let nbt: Nbt = Nbt::read(&mut conn).unwrap();
    println!("{nbt:#?}");
}

For more examples see the examples directory.

Notes

  • Modified UTF-8 validation and conversion is not done during parsing.
  • Endianness is not swapped during parsing.
  • Bytes are unsigned.
  • When serializing, this library will only write up to i32::MAX elements for lists/arrays and up to u16::MAX bytes for strings. This is due to the fact that the NBT specification uses [i32] for lengths of lists/arrays and [u16] for lengths of strings.

Roadmap

  • nbt! macro for constructing NBT values.
  • serde support.
  • Some macro for checking (and binding) NBT patterns.
  • SNBT formatting in Debug/Display.
  • Perhaps iterators for RawVec and RawSlice, although converting in bulk is more efficient.

Performance comparison

Deserialization:

  1. simdnbt::borrow
  2. ussr-nbt::borrow
  3. simdnbt::owned
  4. ussr-nbt::owned
  5. shen-nbt5
  6. azalea-nbt
  7. graphite_binary

Serialization benchmarks violin plot

Serialization:

  1. simdnbt::owned
  2. azalea-nbt
  3. ussr-nbt::borrow
  4. ussr-nbt::owned*
  5. simdnbt::borrow*
  6. graphite_binary
  7. shen-nbt5

*Note: numbers 4 and 5 are very close.

Deserialization benchmarks violin plot

Plots are generated using criterion.

Cargo features

For swapping endianness in bulk this library uses SIMD instructions. By default, it will detect CPU features and use the fastest available instruction set. However, if you disable the rt-cpu-feat feature, it will always use the fallback implementation, which is actually the most performant implementation if compiled with -C target-cpu=native. Note that this flag will make the resulting binary not be able to run on CPUs other than the one it was compiled on.

Dependencies

~1.1–1.7MB
~28K SLoC