Documentation ¶
Overview ¶
Package nbt implements NBT read/write file support.
Its based heavily onthe io.ReaderFrom and io.WriteTo interfaces, so you can just use io.Copy to read and write NBT streams.
An NBT data structure can be created with code such as the following:
root := &Compound{ map[string]Tag{ "Data": &Compound{ map[string]Tag{ "Byte": &Byte{1}, "Short": &Short{2}, "Int": &Int{3}, "Long": &Long{4}, "Float": &Float{5}, "Double": &Double{6}, "String": &String{"foo"}, "List": &List{TagByte, []Tag{&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.
Many thanks to #mcdevs from Freenode and it's great documentation: http://wiki.vg/NBT
Index ¶
Constants ¶
const ArrayNum = 8
Sets the maximum number of elements to show in string representations of types: NBT_ByteArray and NBT_IntArray.
Variables ¶
var ( ErrEndTop = errors.New("End tag found at top level.") ErrInvalidTop = errors.New("Expected compound at top level.") )
Functions ¶
Types ¶
type ByteArray ¶
ByteArray holds a length-prefixed array of signed bytes. The prefix is a signed integer (4 bytes). TagType: 7, Size: 4 + elem * 1 bytes
func NewByteArray ¶
type Compound ¶
Compounds hold a list of a named tags. Order is not guaranteed. TagType: 10, Size: 1 + 4 + elem * id_size bytes
func NewCompound ¶
type End ¶
type End struct{}
End marks end of a Compound. TagType: 0, Size: 1 byte
type Float32 ¶
Float holds a single IEEE-754 single-precision floating point number. TagType: 5, Size: 4 bytes
type Float64 ¶
Double holds a single IEEE-754 double-precision floating point number. TagType: 6, Size: 8 bytes
type IntArray ¶
IntArray holds a length-prefixed array of signed integers. The prefix is a signed integer (4 bytes) and indicates the number of 4 byte integers. TagType: 11, Size: 4 + 4 * elem
func NewIntArray ¶
type List ¶
List holds a list of nameless tags, all of the same type. The list is prefixed with the Type ID of the items it contains (1 byte), and the length of the list as a signed integer (4 bytes). TagType: 9, Size: 1 + 4 + elem * id_size bytes
type String ¶
type String struct {
Value string
}
String holds a length-prefixed UTF-8 string. The prefix is an unsigned short (2 bytes). TagType: 8, Size: 1 + (2 + elem) + (2 + elem)
type Tag ¶
type Tag interface { io.ReaderFrom io.WriterTo Type() TagType Size() int64 Lookup(path string) Tag }
Tag is the interface for all tags that can be represented in an NBT tree.
type TagType ¶
type TagType int8
TagType is the header byte value that identifies the type of tag(s). List & Compound types send TagType over the wire as a signed byte, using a int8 as underlying type allows us to assign TagType to Byte.
const ( // Tag types. All these can be used to create a new tag. TagEnd TagType = iota // Size: 0 TagByte // Size: 1 TagShort // Size: 2 TagInt // Size: 4 TagLong // Size: 8 TagFloat // Size: 4 TagDouble // Size: 8 TagByteArray // Size: 4 + 1*elem TagString // Size: 2 + 4*elem TagList // Size: 1 + 4 + elem*len TagCompound // Size: varies TagIntArray // Size: 4 + 4*elem )