nbt

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 7 Imported by: 0

README

quiver-nbt

A Go library for encoding and decoding Minecraft's Named Binary Tag (NBT) format.

Part of the Quiver project — a Minecraft Java Edition server implementation.

Features

  • Full NBT binary encoding/decoding
  • JSON NBT encoding/decoding
  • Anonymous root tag support (for network protocol payloads)
  • All NBT tag types: Byte, Short, Int, Long, Float, Double, ByteArray, String, List, Compound, IntArray, LongArray

Installation

go get github.com/gauvainw/quiver-nbt

Usage

import nbt "github.com/gauvainw/quiver-nbt"

// Create a compound tag
compound := &nbt.CompoundTag{
    Tags: []nbt.NamedTag{
        {Name: "name", Tag: &nbt.StringTag{Value: "Steve"}},
        {Name: "health", Tag: &nbt.FloatTag{Value: 20.0}},
    },
}

// Encode to binary
data, err := nbt.Marshal(nbt.NamedTag{Name: "", Tag: compound})

// Decode from binary
tag, err := nbt.Unmarshal(bytes.NewReader(data))

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(tag Tag) ([]byte, error)

func MarshalAnonymous

func MarshalAnonymous(tag Tag) ([]byte, error)

MarshalAnonymous writes a root tag in network form: type byte + payload, without a root name.

func MarshalNamed

func MarshalNamed(tag NamedTag) ([]byte, error)

func WriteNamed

func WriteNamed(w io.Writer, tag NamedTag) error

Types

type ByteArrayTag

type ByteArrayTag struct {
	Value []byte
}

func (ByteArrayTag) Type

func (ByteArrayTag) Type() TagType

type ByteTag

type ByteTag struct {
	Value int8
}

func (ByteTag) Type

func (ByteTag) Type() TagType

type CompoundTag

type CompoundTag struct {
	Fields []NamedTag
}

func (CompoundTag) Type

func (CompoundTag) Type() TagType

type DoubleTag

type DoubleTag struct {
	Value float64
}

func (DoubleTag) Type

func (DoubleTag) Type() TagType

type EndTag

type EndTag struct{}

func (EndTag) Type

func (EndTag) Type() TagType

type FloatTag

type FloatTag struct {
	Value float32
}

func (FloatTag) Type

func (FloatTag) Type() TagType

type IntArrayTag

type IntArrayTag struct {
	Value []int32
}

func (IntArrayTag) Type

func (IntArrayTag) Type() TagType

type IntTag

type IntTag struct {
	Value int32
}

func (IntTag) Type

func (IntTag) Type() TagType

type ListTag

type ListTag struct {
	ElemType TagType
	Elements []Tag
}

func (ListTag) Type

func (ListTag) Type() TagType

type LongArrayTag

type LongArrayTag struct {
	Value []int64
}

func (LongArrayTag) Type

func (LongArrayTag) Type() TagType

type LongTag

type LongTag struct {
	Value int64
}

func (LongTag) Type

func (LongTag) Type() TagType

type NamedTag

type NamedTag struct {
	Name string
	Tag  Tag
}

func ReadNamed

func ReadNamed(r io.Reader) (NamedTag, error)

func UnmarshalNamed

func UnmarshalNamed(data []byte) (NamedTag, error)

type ShortTag

type ShortTag struct {
	Value int16
}

func (ShortTag) Type

func (ShortTag) Type() TagType

type StringTag

type StringTag struct {
	Value string
}

func (StringTag) Type

func (StringTag) Type() TagType

type Tag

type Tag interface {
	Type() TagType
	// contains filtered or unexported methods
}

func FromJSON

func FromJSON(data []byte) (Tag, error)

func ReadAnonymous

func ReadAnonymous(r io.Reader) (Tag, error)

ReadAnonymous reads a root tag in network form: type byte + payload, without a root name.

func Unmarshal

func Unmarshal(data []byte) (Tag, error)

func UnmarshalAnonymous

func UnmarshalAnonymous(data []byte) (Tag, error)

type TagType

type TagType byte
const (
	TagEnd TagType = iota
	TagByte
	TagShort
	TagInt
	TagLong
	TagFloat
	TagDouble
	TagByteArray
	TagString
	TagList
	TagCompound
	TagIntArray
	TagLongArray
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL