MyNixOS website logo
Description

NBT (named binary tag) serialization and deserialization.

This project was created because the old nbt package has had a 1-liner open issue preventing compilation for 2 years now at the time of writing, despite submitting a pull request to fix it.

While I was at it, I went ahead and changed the data structure to use konsumlamm's rrb-vector package instead of lists or unboxed arrays for more well-rounded asymptotics.

StrictData is also turned on, and some functions are exported for reading/writing NBT files that remove some of the old boilerplate code.

named-binary-tag

A replacement for the old nbt package, because that one has been defunct for 2 years due to missing a single-line fix.

There are also a few improvements(?) made while I was at it:

  • You can choose between a version with or without label maps using MapNbt or Nbt' respectively.
  • Uses konsumlamm's rrb-vector package instead of a mix of lists and unboxed arrays for more well-rounded asymptotics.
  • StrictData is enabled.
  • Names of types and constructors are shortened a bit, with the reasoning that you should really be using qualified access for most of them.
  • The code is shorter and better documented now (not that it really needed any documentation...)
  • Less boilerplate is required to use it, at the expense of having zlib as a dependency. See below.

Usage

import Data.Nbt qualified as Nbt
import Data.Serialize

main :: IO ()
main = do
  shouldBeNbt <- Nbt.readCompressed "level.dat" :: IO (Either String Nbt') -- see also "Nbt.readUncompressed"
  case shouldBeNbt of
    Left err -> putStrLn err
    Right nbt -> do
      print nbt
      Nbt.writeCompressed "anotherlevel.dat" nbt -- see also "Nbt.writeUncompressed"

Possible Future Work

  • Drop the cereal dependency and do bytestring parsing directly.
  • Conversion to/from SNBT.
  • Conversion to/from JSON.
Metadata

Version

0.1.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows