Skip to content

zwubs/nbeet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nbeet logo

nbeet

An NBT encoder and decoder for gleam

Package Version Hex Docs

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 gleam/dynamic/decode
import gleam/result
import nbeet

pub type InBeetWe {
  InBeetWe(trust: Int, must: String)
}

fn truth_decoder() {
  use trust <- decode.field("trust", decode.int)
  use must <- decode.field("must", decode.string)
  decode.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)
}

About

An NBT encoder and decoder for gleam

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages