#minecraft #nbt #serde

fastnbt

Serde deserializer for Minecraft's NBT format

35 releases (15 stable)

Uses new Rust 2021

2.3.2 Aug 17, 2022
2.2.0 Jun 20, 2022
2.0.0-alpha Mar 29, 2022
1.3.0 Dec 10, 2021
0.6.0 Jul 15, 2020

#76 in Encoding

Download history 70/week @ 2022-08-16 113/week @ 2022-08-23 72/week @ 2022-08-30 159/week @ 2022-09-06 107/week @ 2022-09-13 53/week @ 2022-09-20 184/week @ 2022-09-27 218/week @ 2022-10-04 169/week @ 2022-10-11 30/week @ 2022-10-18 119/week @ 2022-10-25 152/week @ 2022-11-01 133/week @ 2022-11-08 132/week @ 2022-11-15 54/week @ 2022-11-22 63/week @ 2022-11-29

398 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

295KB
8K SLoC

fastnbt crate

Documentation: docs.rs

Fast serde deserializer and serializer for Minecraft: Java Edition's NBT format.

Zero-copy is supported where possible through from_bytes. The borrow module contains more types for avoiding allocations.

Includes a Value type for serializing or deserializing any NBT. Value correctly preserves the exact NBT structure. The nbt! macro allows easy creation of these values.

To support NBT's arrays, there are dedicated ByteArray, IntArray and LongArray types.

See the documentation for more information.

[dependencies]
fastnbt = "2"

fastnbt follows Semver, some things that this project does not count as a breaking change are:

  • Minimum Rust version change. Outside of corporate environments this should not be too difficult, and I don't see much need for NBT in those environments.
  • Improving the (de)serializer such that valid NBT that did not (de)serialize, then (de)serializes. Any of these cases I consider a bug.
  • Data format when serializing types from fastnbt/fastanvil to other formats. Types in fastnbt implement serde::Serialize to enable spitting out to other data formats, but may change structure in future.

Changes that make fastnbt incompatible with WebAssembly are considered breaking changes.

Other NBT crates

There appears to be a few crates that support serde (de)serialization, the main ones I found were:

There are likely others! There are definitely more without serde support.

  • All these crates support serialization and deserialization with serde.

  • They are not interoperable with each other due to requiring custom handling of NBT Array types.

  • They all handle Minecraft's (actually Java's) specialized Unicode.

  • quartz and fastnbt support borrowing from the underlying bytes being deserialized.

  • fastnbt's Value type can round-trip deserialize-serialize NBT arrays. The other crates have value types as well, they may also round-trip correctly.

    Honestly, they all seem like good options!

Dependencies

~0.5–1MB
~24K SLoC