Module erl_nbt

Provides an interface for dealing with NBT data in Erlang.

Copyright © (C) 2021 hypothermic.nl

Authors: Matthijs Bakker (matthijs at hypothermic .nl).

Description

Provides an interface for dealing with NBT data in Erlang

Data Types

nbt()

nbt() = #{nbt_key() => nbt_value()}

nbt_byte()

nbt_byte() = byte()

nbt_byte_array()

nbt_byte_array() = list()

nbt_compound()

nbt_compound() = map()

nbt_double()

nbt_double() = float()

nbt_float()

nbt_float() = float()

nbt_int()

nbt_int() = integer()

nbt_int_array()

nbt_int_array() = list()

nbt_key()

nbt_key() = string()

nbt_long()

nbt_long() = integer()

nbt_long_array()

nbt_long_array() = list()

nbt_short()

nbt_short() = integer()

nbt_string()

nbt_string() = string()

nbt_value()

nbt_value() = nbt_byte() | nbt_short() | nbt_int() | nbt_int() | nbt_long() | nbt_float() | nbt_double() | nbt_byte_array() | nbt_int_array() | nbt_long_array() | nbt_string() | nbt_compound()

Function Index

decode/1Decodes the first (nested) NBT tag in the specified binary.
decode_with_rest/1*Decodes the first (nested) NBT tag in the specified binary.
encode/1Encodes an NBT tag in Erlang Map form to binary.

Function Details

decode/1

decode(Binary::binary()) -> {ok, nbt()}

Binary: The binary to read the NBT tag from

returns: A tuple containing {ok, Nbt} where Nbt is a map

Decodes the first (nested) NBT tag in the specified binary.

This function reads the first NBT tag from a binary. If it is a compound tag, it will read all children (including nested compound tags.)

This function is for basic usage. I recommend using decode_with_rest in production because it has better error handling.

Introduced in: 0.1.0

decode_with_rest/1 *

decode_with_rest(Binary::binary()) -> {ok, nbt(), Rest::binary()}

Binary: The binary to read the NBT tag from

returns: A tuple containing {ok, Nbt, Remainder} where Nbt is a map (same as type erl_nbt:nbt()) and Remainder is an (empty) binary or an error tuple containing {error, {Reason, Details}}

Decodes the first (nested) NBT tag in the specified binary.

This function reads the first NBT tag from a binary. If it is a compound tag, it will read all children (including nested compound tags.)

If the given binary has remaining data after the NBT tag, this remaining data will be returned as Rest.

Introduced in: 0.1.0

encode/1

encode(Nbt::nbt()) -> {ok, binary()}

Nbt: The NBT tag to encode

returns: A tuple containing {ok, Nbt} where Nbt is a map

Encodes an NBT tag in Erlang Map form to binary.

This function accepts an NBT tag representation in map-form (aka type erl_nbt:nbt()) and encodes it into a binary.

Introduced in: 0.1.0


Generated by EDoc