Skip to content

Go: SNBT and NBT values

Functions

ParseSNBT

Go
func ParseSNBT(text string) (*Nbt, error)

ParseSNBT parses SNBT text, with the same rules as the Rust binding: a bare number is an int, then a long, then a double; a suffix b, s, l, f or d fixes the type; true and false are bytes; any other bare word is a string.

  • Parameters:
    • text : string
  • Return type: (*Nbt, error)

NewCompound

Go
func NewCompound() *Nbt

NewCompound is an empty compound.

  • Return type: *Nbt

NbtByteOf

Go
func NbtByteOf(v int8) *Nbt

NbtByteOf is a byte value.

  • Parameters:
    • v : int8
  • Return type: *Nbt

NbtIntOf

Go
func NbtIntOf(v int32) *Nbt

NbtIntOf is an int value.

  • Parameters:
    • v : int32
  • Return type: *Nbt

NbtLongOf

Go
func NbtLongOf(v int64) *Nbt

NbtLongOf is a long value.

  • Parameters:
    • v : int64
  • Return type: *Nbt

NbtDoubleOf

Go
func NbtDoubleOf(v float64) *Nbt

NbtDoubleOf is a double value.

  • Parameters:
    • v : float64
  • Return type: *Nbt

NbtStringOf

Go
func NbtStringOf(v string) *Nbt

NbtStringOf is a string value.

  • Parameters:
    • v : string
  • Return type: *Nbt

Nbt

Go
type Nbt struct {
    Kind  NbtKind
    Int   int64
    Float float64
    Str   string
    List  []*Nbt
    Keys  []string
    Map   map[string]*Nbt
    Ints  []int64
}

Nbt is one SNBT value. Integers of every width are in Int and both floating kinds in Float; a compound keeps its keys in order in Keys and its values in Map.

Nbt.Set

Go
func (v *Nbt) Set(key string, value *Nbt)

Set puts value under key of a compound, keeping the key's first position.

  • Parameters:
    • key : string
    • value : *Nbt

Nbt.Get

Go
func (v *Nbt) Get(path string) *Nbt

Get follows a dotted path through compounds, and is nil when a step is missing.

  • Parameters:
    • path : string
  • Return type: *Nbt

Nbt.OptString

Go
func (v *Nbt) OptString(path string) (string, bool)

OptString is the string at path, and false when it is absent or not a string.

  • Parameters:
    • path : string
  • Return type: (string, bool)

Nbt.OptInt

Go
func (v *Nbt) OptInt(path string) (int64, bool)

OptInt is the integer at path of any width, and false when it is absent or not one.

  • Parameters:
    • path : string
  • Return type: (int64, bool)

Nbt.OptFloat

Go
func (v *Nbt) OptFloat(path string) (float64, bool)

OptFloat is the number at path, integer or floating, and false when it is absent.

  • Parameters:
    • path : string
  • Return type: (float64, bool)

Nbt.OptBool

Go
func (v *Nbt) OptBool(path string) (bool, bool)

OptBool is the byte at path read as a boolean, and false in the second result when it is absent or not a 0 or 1 byte.

  • Parameters:
    • path : string
  • Return type: (bool, bool)

Nbt.SNBT

Go
func (v *Nbt) SNBT() (string, error)

SNBT writes the value as SNBT. A floating value that is not finite is an error: SNBT has no spelling for it, and the host's parser refuses every field after one.

  • Return type: (string, error)

NbtKind

Go
type NbtKind uint8

NbtKind is the type of one NBT value.

Name Value Description
NbtByte 1
NbtShort 2
NbtInt 3
NbtLong 4
NbtFloat 5
NbtDouble 6
NbtString 7
NbtList 8
NbtCompound 9
NbtByteArray 10
NbtIntArray 11
NbtLongArray 12