nbt

package
v0.0.0-...-c982c26 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2014 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

nbt provides the ability to read/write NBT data structures from Readers and Writers.

NBT is the data serialization format used in many places in the official Notchian Minecraft server, typically to represent structured world, chunk and player information.

An NBT data structure can be created with code such as the following:

root := &Compound{
  map[string]ITag{
    "Data": &Compound{
      map[string]ITag{
        "Byte":   &Byte{1},
        "Short":  &Short{2},
        "Int":    &Int{3},
        "Long":   &Long{4},
        "Float":  &Float{5},
        "Double": &Double{6},
        "String": &String{"foo"},
        "List":   &List{TagByte, []ITag{&Byte{1}, &Byte{2}}},
      },
    },
  },
}

It is required that the root structure be a Compound for compatibility with existing NBT structures observed in the official server.

NBT structures can be read from an io.Reader with the Read function.

Index

Constants

View Source
const (
	// Tag types. All these values can be used to create a new tag, except
	// TagEnd.
	TagEnd       = TagType(0)
	TagByte      = TagType(1)
	TagShort     = TagType(2)
	TagInt       = TagType(3)
	TagLong      = TagType(4)
	TagFloat     = TagType(5)
	TagDouble    = TagType(6)
	TagByteArray = TagType(7)
	TagString    = TagType(8)
	TagList      = TagType(9)
	TagCompound  = TagType(10)
)

Variables

This section is empty.

Functions

func Write

func Write(writer io.Writer, tag *Compound) (err error)

Write writes an NBT compound to the given writer.

Types

type Byte

type Byte struct {
	Value int8
}

func (*Byte) Lookup

func (*Byte) Lookup(path string) ITag

func (*Byte) Read

func (b *Byte) Read(reader io.Reader) (err error)

func (*Byte) Type

func (*Byte) Type() TagType

func (*Byte) Write

func (b *Byte) Write(writer io.Writer) (err error)

type ByteArray

type ByteArray struct {
	Value []byte
}

func (*ByteArray) Lookup

func (*ByteArray) Lookup(path string) ITag

func (*ByteArray) Read

func (b *ByteArray) Read(reader io.Reader) (err error)

func (*ByteArray) Type

func (*ByteArray) Type() TagType

func (*ByteArray) Write

func (b *ByteArray) Write(writer io.Writer) (err error)

type Compound

type Compound struct {
	Tags map[string]ITag
}

func NewCompound

func NewCompound() *Compound

func Read

func Read(reader io.Reader) (tag *Compound, err error)

Read reads an NBT compound from the given reader.

func (*Compound) Lookup

func (c *Compound) Lookup(path string) (tag ITag)

func (*Compound) Read

func (c *Compound) Read(reader io.Reader) (err error)

func (*Compound) Set

func (c *Compound) Set(key string, tag ITag)

func (*Compound) Type

func (*Compound) Type() TagType

func (*Compound) Write

func (c *Compound) Write(writer io.Writer) (err error)

type Double

type Double struct {
	Value float64
}

func (*Double) Lookup

func (*Double) Lookup(path string) ITag

func (*Double) Read

func (d *Double) Read(reader io.Reader) (err error)

func (*Double) Type

func (*Double) Type() TagType

func (*Double) Write

func (d *Double) Write(writer io.Writer) (err error)

type Float

type Float struct {
	Value float32
}

func (*Float) Lookup

func (*Float) Lookup(path string) ITag

func (*Float) Read

func (f *Float) Read(reader io.Reader) (err error)

func (*Float) Type

func (*Float) Type() TagType

func (*Float) Write

func (f *Float) Write(writer io.Writer) (err error)

type ITag

type ITag interface {
	Type() TagType
	Read(io.Reader) error
	Write(io.Writer) error
	Lookup(path string) ITag
}

ITag is the interface for all tags that can be represented in an NBT tree.

type Int

type Int struct {
	Value int32
}

func (*Int) Lookup

func (*Int) Lookup(path string) ITag

func (*Int) Read

func (i *Int) Read(reader io.Reader) (err error)

func (*Int) Type

func (*Int) Type() TagType

func (*Int) Write

func (i *Int) Write(writer io.Writer) (err error)

type List

type List struct {
	TagType TagType
	Value   []ITag
}

func (*List) Lookup

func (*List) Lookup(path string) ITag

func (*List) Read

func (l *List) Read(reader io.Reader) (err error)

func (*List) Type

func (*List) Type() TagType

func (*List) Write

func (l *List) Write(writer io.Writer) (err error)

type Long

type Long struct {
	Value int64
}

func (*Long) Lookup

func (*Long) Lookup(path string) ITag

func (*Long) Read

func (l *Long) Read(reader io.Reader) (err error)

func (*Long) Type

func (*Long) Type() TagType

func (*Long) Write

func (l *Long) Write(writer io.Writer) (err error)

type Short

type Short struct {
	Value int16
}

func (*Short) Lookup

func (*Short) Lookup(path string) ITag

func (*Short) Read

func (s *Short) Read(reader io.Reader) (err error)

func (*Short) Type

func (*Short) Type() TagType

func (*Short) Write

func (s *Short) Write(writer io.Writer) (err error)

type String

type String struct {
	Value string
}

func (*String) Lookup

func (*String) Lookup(path string) ITag

func (*String) Read

func (s *String) Read(reader io.Reader) (err error)

func (*String) Type

func (*String) Type() TagType

func (*String) Write

func (s *String) Write(writer io.Writer) (err error)

type TagType

type TagType byte

TagType is the header byte value that identifies the type of tag(s).

func (TagType) NewTag

func (tt TagType) NewTag() (tag ITag, err error)

NewTag creates a new tag of the given TagType. TagEnd is not a valid value here.

Jump to

Keyboard shortcuts

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