About
nbeet
is a gleam package for all your NBT needs. For those that don’t know NBT (Named Binary Tag) is a file format utilized by the game Minecraft for storing information. This package focuses on encoding and decoding NBT data and has syntax inspired by gleam_json
and bison
packages.
Installation
Add nbeet
to your Gleam project.
gleam add nbeet
Usage
Encoding
import nbeet.{byte, compound, nbt, string}
pub fn encode_truth() -> Result(BitArray, Nil) {
let nbt =
nbt(
"in beet we",
compound([#("trust", byte(1)), #("must", string("true")), ])
)
nbeet.encode(nbt)
}
Decoding
import decode/zero
import gleam/result
import nbeet
pub type InBeetWe {
InBeetWe(trust: Int, must: String)
}
fn truth_decoder() {
use trust <- zero.field("trust", zero.int)
use must <- zero.field("must", zero.string)
zero.success(InBeetWe(trust, must))
}
fn decode_truth(nbt: BitArray) -> Result(InBeetWe, Nil) {
let decoder = truth_decoder()
use #(_, in_beet_we) <- result.try(nbeet.java_decode(nbt, decoder))
Ok(in_beet_we)
}