nbt

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 10 Imported by: 5

README

NBT

Maybe This is a simple NBT parser.

Gets

You can get the package with go get command.

go get -u github.com/beito123/nbt

-u is a option updating the package

License

This is licensed by MIT License. See LICENSE file.

Examples

Read
func main() {
	// Data: Unnamed(compound){ world_name(string): jagajaga, hardcore(byte): 18 }

	// Raw data
	// 	0x0000: 0a 00 00 01 00 08 68 61 72 64 63 6f | ......hardco
	// 	0x000c: 72 65 12 08 00 0a 77 6f 72 6c 64 5f | re....world_
	// 	0x0018: 6e 61 6d 65 00 08 6a 61 67 61 6a 61 | name..jagaja
	// 	0x0024: 67 61 00                            | ga.

	// Compressed bytes // level.dat and more are saved as compressed with gzip
	data := []byte{0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x03, 0xE3, 0x62, 0x60, 0x60, 0x64, 0xE0, 0xC8, 0x48, 0x2C, 0x4A,
		0x49, 0xCE, 0x2F, 0x4A, 0x15, 0xE2, 0x60, 0xE0, 0x2A, 0xCF, 0x2F,
		0xCA, 0x49, 0x89, 0xCF, 0x4B, 0xCC, 0x4D, 0x65, 0xE0, 0xC8, 0x4A,
		0x4C, 0x4F, 0x04, 0x61, 0x06, 0x00, 0x7A, 0x8D, 0xB4, 0xF9, 0x27, 0x00, 0x00, 0x00}

	// Read after uncompressing
	// If you want to parse compressed bytes, you should use this
	stream, err := nbt.FromReader(bytes.NewBuffer(data), nbt.BigEndian)
	if err != nil {
		panic(err)
	}

	// If you read from file
	// stream, err := nbt.FromFile("./level.dat", nbt.BigEndian)

	// Read a tag from read bytes
	tag, err := stream.ReadTag()
	if err != nil {
		panic(err)
	}

	// Convert to String // For dump
	str, err := tag.ToString()
	if err != nil {
		panic(err)
	}

	// read data: { hardcore(Byte): 18, world_name(String): jagajaga }
	fmt.Printf("read data: %s", str)
}
Write
func main(){
	// tag = Unnamed(Compound){ hardcore(Byte): 18, world_name(String): jagajaga }
	tag := &nbt.Compound{
		Value: map[string]nbt.Tag{
			"hardcore": &nbt.Byte{
				Value: 18,
			},
			"world_name": &nbt.String{
				Value: "jagajaga",
			},
		},
	}

	// New stream with big endian
	// Big endian is used for level.dat and world data
	// Little endian is used for leveldb
	stream := nbt.NewStream(nbt.BigEndian)

	// Write a tag
	err := stream.WriteTag(tag)
	if err != nil {
		panic(err)
	}

	// Output file:
	// 0x0000: 0a 00 00 01 00 08 68 61 72 64 63 6f | ......hardco
	// 0x000c: 72 65 12 08 00 0a 77 6f 72 6c 64 5f | re....world_
	// 0x0018: 6e 61 6d 65 00 08 6a 61 67 61 6a 61 | name..jagaja
	// 0x0024: 67 61 00                            | ga.
	ioutil.WriteFile("./nbt.dat", stream.Bytes(), os.ModePerm)

	fmt.Println("generated ./nbt.dat")

	// If you want to compress for level.dat etc...
	data, err := nbt.Compress(stream, nbt.CompressGZip, nbt.DefaultCompressionLevel)
	if err != nil {
		panic(err)
	}

	ioutil.WriteFile("./nbt_compressed.dat", data, os.ModePerm)

	fmt.Println("generated ./nbt_compressed.dat")
}

Documentation

Index

Constants

View Source
const (
	// IDTagEnd signifies end for compound tag
	// Payload: none
	IDTagEnd = iota

	// IDTagByte is a signed byte (-128 to 127)
	// Payload is 1byte
	IDTagByte

	// IDTagShort is a signed short (-32768 to 32767)
	// Payload is 2 bytes
	IDTagShort

	// IDTagInt is a signed int (-2147483648 to 2147483647)
	// Payload is 4 bytes
	IDTagInt

	// IDTagLong is a signed long (-9223372036854775808 to 9223372036854775807)
	// Payload is 8 bytes
	IDTagLong

	// IDTagFloat is a signed single float (IEEE-754)
	// Payload is 4 bytes
	IDTagFloat

	// IDTagDouble is a signed single double (IEEE-754)
	// Payload is 8 bytes
	IDTagDouble

	// IDTagByteArray is a array of signed bytes
	// Payload is 4 bytes(len of data with signed int) + len bytes
	IDTagByteArray

	// IDTagString is a UTF-8 string (max 32767 bytes)
	// Payload is 2 bytes (len of data with short) + len bytes
	IDTagString

	// IDTagList is a list of nameless tags, all tags need same type.
	// Payload is 1 byte(tag type with byte) + 4 bytes(len with signed int) + len bytes
	IDTagList

	// IDTagCompound is a list of named tags.
	IDTagCompound

	// IDTagIntArray is a array for int(4bytes).
	IDTagIntArray

	// IDTagLongArray is a array for long(8bytes).
	IDTagLongArray
)
View Source
const DefaultCompressionLevel = -1

DefaultCompressionLevel set the default compression level when it's compressing

Variables

View Source
var (
	// BigEndian is for MCJE, anvil and more...
	BigEndian = binary.BigEndian

	// LittleEndian is for MCBE leveldb format
	LittleEndian = binary.LittleEndian
)

Functions

func Compress

func Compress(s *Stream, typ CompressType, level int) ([]byte, error)

Compress compresses stream's bytes You can use compression level in "compress/gzip" and "compress/zlib" for level If you set the default compression level, you can set DefaultCompressionLevel This often is used for player and level data

func GetTagName

func GetTagName(id byte) string

GetTagName returns tag name

Types

type Byte

type Byte struct {
	Value int8
	// contains filtered or unexported fields
}

Byte is a tag for a byte

func NewByteTag added in v1.2.2

func NewByteTag(name string, val int8) *Byte

NewByteTag returns a new Byte tag

func (*Byte) ID

func (t *Byte) ID() byte

ID returns tag id

func (*Byte) Name

func (t *Byte) Name() string

Name returns tag's name

func (*Byte) Read

func (t *Byte) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Byte) SetName

func (t *Byte) SetName(name string)

SetName set name in tag

func (*Byte) ToBool

func (t *Byte) ToBool() (bool, error)

ToBool returns value as bool

func (*Byte) ToByte

func (t *Byte) ToByte() (byte, error)

ToByte returns value as byte

func (*Byte) ToByteArray

func (t *Byte) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Byte) ToFloat32

func (t *Byte) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Byte) ToFloat64

func (t *Byte) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Byte) ToInt

func (t *Byte) ToInt() (int, error)

ToInt returns value as int

func (*Byte) ToInt16

func (t *Byte) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Byte) ToInt32

func (t *Byte) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Byte) ToInt64

func (t *Byte) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Byte) ToInt8

func (t *Byte) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Byte) ToIntArray

func (t *Byte) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Byte) ToLongArray added in v1.2.0

func (t *Byte) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Byte) ToRune

func (t *Byte) ToRune() (rune, error)

ToRune returns value as rune

func (*Byte) ToString

func (t *Byte) ToString() (string, error)

ToString returns value as string

func (*Byte) ToUInt

func (t *Byte) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Byte) ToUInt16

func (t *Byte) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Byte) ToUInt32

func (t *Byte) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Byte) ToUInt64

func (t *Byte) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Byte) ToUInt8

func (t *Byte) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Byte) Write

func (t *Byte) Write(n *Stream) error

Write writes tag for Stream

type ByteArray

type ByteArray struct {
	Value []byte
	// contains filtered or unexported fields
}

ByteArray is a tag for []byte

func NewByteArrayTag added in v1.2.2

func NewByteArrayTag(name string, val []byte) *ByteArray

NewByteArrayTag returns a new ByteArray tag

func (*ByteArray) ID

func (t *ByteArray) ID() byte

ID returns tag id

func (*ByteArray) Name

func (t *ByteArray) Name() string

Name returns tag's name

func (*ByteArray) Read

func (t *ByteArray) Read(n *Stream) error

Read reads tag from Stream

func (*ByteArray) SetName

func (t *ByteArray) SetName(name string)

SetName set name in tag

func (*ByteArray) ToBool

func (t *ByteArray) ToBool() (bool, error)

ToBool returns value as bool

func (*ByteArray) ToByte

func (t *ByteArray) ToByte() (byte, error)

ToByte returns value as byte

func (*ByteArray) ToByteArray

func (t *ByteArray) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*ByteArray) ToFloat32

func (t *ByteArray) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*ByteArray) ToFloat64

func (t *ByteArray) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*ByteArray) ToInt

func (t *ByteArray) ToInt() (int, error)

ToInt returns value as int

func (*ByteArray) ToInt16

func (t *ByteArray) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*ByteArray) ToInt32

func (t *ByteArray) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*ByteArray) ToInt64

func (t *ByteArray) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*ByteArray) ToInt8

func (t *ByteArray) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*ByteArray) ToIntArray

func (t *ByteArray) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*ByteArray) ToLongArray added in v1.2.0

func (t *ByteArray) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*ByteArray) ToRune

func (t *ByteArray) ToRune() (rune, error)

ToRune returns value as rune

func (*ByteArray) ToString

func (t *ByteArray) ToString() (string, error)

ToString returns value as string

func (*ByteArray) ToUInt

func (t *ByteArray) ToUInt() (uint, error)

ToUInt returns value as uint

func (*ByteArray) ToUInt16

func (t *ByteArray) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*ByteArray) ToUInt32

func (t *ByteArray) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*ByteArray) ToUInt64

func (t *ByteArray) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*ByteArray) ToUInt8

func (t *ByteArray) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*ByteArray) Write

func (t *ByteArray) Write(n *Stream) error

Write writes tag for Stream

type Compound

type Compound struct {
	Value map[string]Tag
	// contains filtered or unexported fields
}

Compound is a map contained tags

func NewCompoundTag added in v1.2.2

func NewCompoundTag(name string, val map[string]Tag) *Compound

NewCompoundTag returns a new Compound tag

func (*Compound) Get

func (t *Compound) Get(name string) (Tag, bool)

Get gets a tag with name from Compound

func (*Compound) GetBool

func (t *Compound) GetBool(name string) (bool, error)

GetBool gets a tag with name as bool

func (*Compound) GetByte

func (t *Compound) GetByte(name string) (byte, error)

GetByte gets a tag with name as byte

func (*Compound) GetByteArray

func (t *Compound) GetByteArray(name string) ([]byte, error)

GetByteArray gets a tag with name as []byte

func (*Compound) GetCompound

func (t *Compound) GetCompound(name string) (*Compound, error)

GetCompound gets a tag with name as *Compound

func (*Compound) GetDouble

func (t *Compound) GetDouble(name string) (float64, error)

GetDouble gets a tag with name as float64

func (*Compound) GetFloat

func (t *Compound) GetFloat(name string) (float32, error)

GetFloat gets a tag with name as float32

func (*Compound) GetInt

func (t *Compound) GetInt(name string) (int32, error)

GetInt gets a tag with name as int32

func (*Compound) GetIntArray

func (t *Compound) GetIntArray(name string) ([]int32, error)

GetIntArray gets a tag with name as []int32

func (*Compound) GetList

func (t *Compound) GetList(name string) ([]Tag, error)

GetList gets a tag with name as []Tag

func (*Compound) GetLong

func (t *Compound) GetLong(name string) (int64, error)

GetLong gets a tag with name as int64

func (*Compound) GetLongArray added in v1.2.1

func (t *Compound) GetLongArray(name string) ([]int64, error)

GetLongArray gets a tag with name as []int64

func (*Compound) GetShort

func (t *Compound) GetShort(name string) (int16, error)

GetShort gets a tag with name as int16

func (*Compound) GetString

func (t *Compound) GetString(name string) (string, error)

GetString gets a tag with name as string

func (*Compound) Has

func (t *Compound) Has(name string) bool

Has returns whether a tag

func (*Compound) ID

func (t *Compound) ID() byte

ID returns tag id

func (*Compound) Name

func (t *Compound) Name() string

Name returns tag's name

func (*Compound) Read

func (t *Compound) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Compound) Set

func (t *Compound) Set(tag Tag)

Set set a tag

func (*Compound) SetName

func (t *Compound) SetName(name string)

SetName set name in tag

func (*Compound) ToBool

func (t *Compound) ToBool() (bool, error)

ToBool returns value as bool

func (*Compound) ToByte

func (t *Compound) ToByte() (byte, error)

ToByte returns value as byte

func (*Compound) ToByteArray

func (t *Compound) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Compound) ToFloat32

func (t *Compound) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Compound) ToFloat64

func (t *Compound) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Compound) ToInt

func (t *Compound) ToInt() (int, error)

ToInt returns value as int

func (*Compound) ToInt16

func (t *Compound) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Compound) ToInt32

func (t *Compound) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Compound) ToInt64

func (t *Compound) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Compound) ToInt8

func (t *Compound) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Compound) ToIntArray

func (t *Compound) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Compound) ToLongArray added in v1.2.0

func (t *Compound) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Compound) ToRune

func (t *Compound) ToRune() (rune, error)

ToRune returns value as rune

func (*Compound) ToString

func (t *Compound) ToString() (string, error)

ToString returns value as string

func (*Compound) ToUInt

func (t *Compound) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Compound) ToUInt16

func (t *Compound) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Compound) ToUInt32

func (t *Compound) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Compound) ToUInt64

func (t *Compound) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Compound) ToUInt8

func (t *Compound) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Compound) Write

func (t *Compound) Write(n *Stream) error

Write writes tag for Stream

type CompressType added in v1.1.0

type CompressType int

CompressType is a compression type

const (
	// CompressGZip compresses with gzip
	CompressGZip CompressType = iota

	// CompressZlib compresses with zlib
	CompressZlib
)

func (CompressType) DefaultCompression added in v1.2.0

func (ct CompressType) DefaultCompression() int

DefaultCompression returns the default compression level

type Double

type Double struct {
	Value float64
	// contains filtered or unexported fields
}

Double is a tag for float64

func NewDoubleTag added in v1.2.2

func NewDoubleTag(name string, val float64) *Double

NewDoubleTag returns a new Double tag

func (*Double) ID

func (t *Double) ID() byte

ID returns tag id

func (*Double) Name

func (t *Double) Name() string

Name returns tag's name

func (*Double) Read

func (t *Double) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Double) SetName

func (t *Double) SetName(name string)

SetName set name in tag

func (*Double) ToBool

func (t *Double) ToBool() (bool, error)

ToBool returns value as bool

func (*Double) ToByte

func (t *Double) ToByte() (byte, error)

ToByte returns value as byte

func (*Double) ToByteArray

func (t *Double) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Double) ToFloat32

func (t *Double) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Double) ToFloat64

func (t *Double) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Double) ToInt

func (t *Double) ToInt() (int, error)

ToInt returns value as int

func (*Double) ToInt16

func (t *Double) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Double) ToInt32

func (t *Double) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Double) ToInt64

func (t *Double) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Double) ToInt8

func (t *Double) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Double) ToIntArray

func (t *Double) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Double) ToLongArray added in v1.2.0

func (t *Double) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Double) ToRune

func (t *Double) ToRune() (rune, error)

ToRune returns value as rune

func (*Double) ToString

func (t *Double) ToString() (string, error)

ToString returns value as string

func (*Double) ToUInt

func (t *Double) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Double) ToUInt16

func (t *Double) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Double) ToUInt32

func (t *Double) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Double) ToUInt64

func (t *Double) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Double) ToUInt8

func (t *Double) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Double) Write

func (t *Double) Write(n *Stream) error

Write writes tag for Stream

type End

type End struct {
	// contains filtered or unexported fields
}

End is a end tag It shows stream end of tag data

func NewEndTag added in v1.2.2

func NewEndTag(name string) *End

NewEndTag returns a new End tag

func (*End) ID

func (t *End) ID() byte

ID returns tag id

func (*End) Name

func (t *End) Name() string

Name returns tag's name

func (*End) Read

func (t *End) Read(nbt *Stream) error

Read reads tag from Stream

func (*End) SetName

func (t *End) SetName(name string)

SetName set name in tag

func (*End) ToBool

func (t *End) ToBool() (bool, error)

ToBool returns value as bool

func (*End) ToByte

func (t *End) ToByte() (byte, error)

ToByte returns value as byte

func (*End) ToByteArray

func (t *End) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*End) ToFloat32

func (t *End) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*End) ToFloat64

func (t *End) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*End) ToInt

func (t *End) ToInt() (int, error)

ToInt returns value as int

func (*End) ToInt16

func (t *End) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*End) ToInt32

func (t *End) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*End) ToInt64

func (t *End) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*End) ToInt8

func (t *End) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*End) ToIntArray

func (t *End) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*End) ToLongArray added in v1.2.0

func (t *End) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*End) ToRune

func (t *End) ToRune() (rune, error)

ToRune returns value as rune

func (*End) ToString

func (t *End) ToString() (string, error)

ToString returns value as string

func (*End) ToUInt

func (t *End) ToUInt() (uint, error)

ToUInt returns value as uint

func (*End) ToUInt16

func (t *End) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*End) ToUInt32

func (t *End) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*End) ToUInt64

func (t *End) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*End) ToUInt8

func (t *End) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*End) Write

func (t *End) Write(nbt *Stream) error

Write writes tag for Stream

type Float

type Float struct {
	Value float32
	// contains filtered or unexported fields
}

Float is a tag for a float

func NewFloatTag added in v1.2.2

func NewFloatTag(name string, val float32) *Float

NewFloatTag returns a new Float tag

func (*Float) ID

func (t *Float) ID() byte

ID returns tag id

func (*Float) Name

func (t *Float) Name() string

Name returns tag's name

func (*Float) Read

func (t *Float) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Float) SetName

func (t *Float) SetName(name string)

SetName set name in tag

func (*Float) ToBool

func (t *Float) ToBool() (bool, error)

ToBool returns value as bool

func (*Float) ToByte

func (t *Float) ToByte() (byte, error)

ToByte returns value as byte

func (*Float) ToByteArray

func (t *Float) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Float) ToFloat32

func (t *Float) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Float) ToFloat64

func (t *Float) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Float) ToInt

func (t *Float) ToInt() (int, error)

ToInt returns value as int

func (*Float) ToInt16

func (t *Float) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Float) ToInt32

func (t *Float) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Float) ToInt64

func (t *Float) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Float) ToInt8

func (t *Float) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Float) ToIntArray

func (t *Float) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Float) ToLongArray added in v1.2.0

func (t *Float) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Float) ToRune

func (t *Float) ToRune() (rune, error)

ToRune returns value as rune

func (*Float) ToString

func (t *Float) ToString() (string, error)

ToString returns value as string

func (*Float) ToUInt

func (t *Float) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Float) ToUInt16

func (t *Float) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Float) ToUInt32

func (t *Float) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Float) ToUInt64

func (t *Float) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Float) ToUInt8

func (t *Float) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Float) Write

func (t *Float) Write(n *Stream) error

Write writes tag for Stream

type Int

type Int struct {
	Value int32
	// contains filtered or unexported fields
}

Int is a tag for an int

func NewIntTag added in v1.2.2

func NewIntTag(name string, val int32) *Int

NewIntTag returns a new Int tag

func (*Int) ID

func (t *Int) ID() byte

ID returns tag id

func (*Int) Name

func (t *Int) Name() string

Name returns tag's name

func (*Int) Read

func (t *Int) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Int) SetName

func (t *Int) SetName(name string)

SetName set name in tag

func (*Int) ToBool

func (t *Int) ToBool() (bool, error)

ToBool returns value as bool

func (*Int) ToByte

func (t *Int) ToByte() (byte, error)

ToByte returns value as byte

func (*Int) ToByteArray

func (t *Int) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Int) ToFloat32

func (t *Int) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Int) ToFloat64

func (t *Int) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Int) ToInt

func (t *Int) ToInt() (int, error)

ToInt returns value as int

func (*Int) ToInt16

func (t *Int) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Int) ToInt32

func (t *Int) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Int) ToInt64

func (t *Int) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Int) ToInt8

func (t *Int) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Int) ToIntArray

func (t *Int) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Int) ToLongArray added in v1.2.0

func (t *Int) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Int) ToRune

func (t *Int) ToRune() (rune, error)

ToRune returns value as rune

func (*Int) ToString

func (t *Int) ToString() (string, error)

ToString returns value as string

func (*Int) ToUInt

func (t *Int) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Int) ToUInt16

func (t *Int) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Int) ToUInt32

func (t *Int) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Int) ToUInt64

func (t *Int) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Int) ToUInt8

func (t *Int) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Int) Write

func (t *Int) Write(n *Stream) error

Write writes tag for Stream

type IntArray

type IntArray struct {
	Value []int32
	// contains filtered or unexported fields
}

IntArray is a tag for a int array

func NewIntArrayTag added in v1.2.2

func NewIntArrayTag(name string, val []int32) *IntArray

NewIntArrayTag returns a new IntArray tag

func (*IntArray) ID

func (t *IntArray) ID() byte

ID returns tag id

func (*IntArray) Name

func (t *IntArray) Name() string

Name returns tag's name

func (*IntArray) Read

func (t *IntArray) Read(n *Stream) (err error)

Read reads tag from Stream

func (*IntArray) SetName

func (t *IntArray) SetName(name string)

SetName set name in tag

func (*IntArray) ToBool

func (t *IntArray) ToBool() (bool, error)

ToBool returns value as bool

func (*IntArray) ToByte

func (t *IntArray) ToByte() (byte, error)

ToByte returns value as byte

func (*IntArray) ToByteArray

func (t *IntArray) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*IntArray) ToFloat32

func (t *IntArray) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*IntArray) ToFloat64

func (t *IntArray) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*IntArray) ToInt

func (t *IntArray) ToInt() (int, error)

ToInt returns value as int

func (*IntArray) ToInt16

func (t *IntArray) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*IntArray) ToInt32

func (t *IntArray) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*IntArray) ToInt64

func (t *IntArray) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*IntArray) ToInt8

func (t *IntArray) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*IntArray) ToIntArray

func (t *IntArray) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*IntArray) ToLongArray added in v1.2.0

func (t *IntArray) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*IntArray) ToRune

func (t *IntArray) ToRune() (rune, error)

ToRune returns value as rune

func (*IntArray) ToString

func (t *IntArray) ToString() (string, error)

ToString returns value as string

func (*IntArray) ToUInt

func (t *IntArray) ToUInt() (uint, error)

ToUInt returns value as uint

func (*IntArray) ToUInt16

func (t *IntArray) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*IntArray) ToUInt32

func (t *IntArray) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*IntArray) ToUInt64

func (t *IntArray) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*IntArray) ToUInt8

func (t *IntArray) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*IntArray) Write

func (t *IntArray) Write(n *Stream) error

Write writes tag for Stream

type List

type List struct {
	Value []Tag

	ListType byte
	// contains filtered or unexported fields
}

List is a container for tags

func NewListTag added in v1.2.2

func NewListTag(name string, val []Tag, typ byte) *List

NewListTag returns a new List tag

func (*List) ID

func (t *List) ID() byte

ID returns tag id

func (*List) Name

func (t *List) Name() string

Name returns tag's name

func (*List) Read

func (t *List) Read(n *Stream) (err error)

Read reads tag from Stream

func (*List) SetName

func (t *List) SetName(name string)

SetName set name in tag

func (*List) ToBool

func (t *List) ToBool() (bool, error)

ToBool returns value as bool

func (*List) ToByte

func (t *List) ToByte() (byte, error)

ToByte returns value as byte

func (*List) ToByteArray

func (t *List) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*List) ToFloat32

func (t *List) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*List) ToFloat64

func (t *List) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*List) ToInt

func (t *List) ToInt() (int, error)

ToInt returns value as int

func (*List) ToInt16

func (t *List) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*List) ToInt32

func (t *List) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*List) ToInt64

func (t *List) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*List) ToInt8

func (t *List) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*List) ToIntArray

func (t *List) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*List) ToLongArray added in v1.2.0

func (t *List) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*List) ToRune

func (t *List) ToRune() (rune, error)

ToRune returns value as rune

func (*List) ToString

func (t *List) ToString() (string, error)

ToString returns value as string

func (*List) ToUInt

func (t *List) ToUInt() (uint, error)

ToUInt returns value as uint

func (*List) ToUInt16

func (t *List) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*List) ToUInt32

func (t *List) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*List) ToUInt64

func (t *List) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*List) ToUInt8

func (t *List) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*List) Write

func (t *List) Write(n *Stream) error

Write writes tag for Stream

type Long

type Long struct {
	Value int64
	// contains filtered or unexported fields
}

Long is a tag for an int64

func NewLongTag added in v1.2.2

func NewLongTag(name string, val int64) *Long

NewLongTag returns a new Long tag

func (*Long) ID

func (t *Long) ID() byte

ID returns tag id

func (*Long) Name

func (t *Long) Name() string

Name returns tag's name

func (*Long) Read

func (t *Long) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Long) SetName

func (t *Long) SetName(name string)

SetName set name in tag

func (*Long) ToBool

func (t *Long) ToBool() (bool, error)

ToBool returns value as bool

func (*Long) ToByte

func (t *Long) ToByte() (byte, error)

ToByte returns value as byte

func (*Long) ToByteArray

func (t *Long) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Long) ToFloat32

func (t *Long) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Long) ToFloat64

func (t *Long) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Long) ToInt

func (t *Long) ToInt() (int, error)

ToInt returns value as int

func (*Long) ToInt16

func (t *Long) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Long) ToInt32

func (t *Long) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Long) ToInt64

func (t *Long) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Long) ToInt8

func (t *Long) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Long) ToIntArray

func (t *Long) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Long) ToLongArray added in v1.2.0

func (t *Long) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Long) ToRune

func (t *Long) ToRune() (rune, error)

ToRune returns value as rune

func (*Long) ToString

func (t *Long) ToString() (string, error)

ToString returns value as string

func (*Long) ToUInt

func (t *Long) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Long) ToUInt16

func (t *Long) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Long) ToUInt32

func (t *Long) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Long) ToUInt64

func (t *Long) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Long) ToUInt8

func (t *Long) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Long) Write

func (t *Long) Write(n *Stream) error

Write writes tag for Stream

type LongArray added in v1.2.0

type LongArray struct {
	Value []int64
	// contains filtered or unexported fields
}

LongArray is a tag for a array of longs

func NewLongArrayTag added in v1.2.2

func NewLongArrayTag(name string, val []int64) *LongArray

NewLongArrayTag returns a new LongArray tag

func (*LongArray) ID added in v1.2.0

func (t *LongArray) ID() byte

ID returns tag id

func (*LongArray) Name added in v1.2.0

func (t *LongArray) Name() string

Name returns tag's name

func (*LongArray) Read added in v1.2.0

func (t *LongArray) Read(n *Stream) (err error)

Read reads tag from Stream

func (*LongArray) SetName added in v1.2.0

func (t *LongArray) SetName(name string)

SetName set name in tag

func (*LongArray) ToBool added in v1.2.0

func (t *LongArray) ToBool() (bool, error)

ToBool returns value as bool

func (*LongArray) ToByte added in v1.2.0

func (t *LongArray) ToByte() (byte, error)

ToByte returns value as byte

func (*LongArray) ToByteArray added in v1.2.0

func (t *LongArray) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*LongArray) ToFloat32 added in v1.2.0

func (t *LongArray) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*LongArray) ToFloat64 added in v1.2.0

func (t *LongArray) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*LongArray) ToInt added in v1.2.0

func (t *LongArray) ToInt() (int, error)

ToInt returns value as int

func (*LongArray) ToInt16 added in v1.2.0

func (t *LongArray) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*LongArray) ToInt32 added in v1.2.0

func (t *LongArray) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*LongArray) ToInt64 added in v1.2.0

func (t *LongArray) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*LongArray) ToInt8 added in v1.2.0

func (t *LongArray) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*LongArray) ToIntArray added in v1.2.1

func (t *LongArray) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*LongArray) ToLongArray added in v1.2.0

func (t *LongArray) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*LongArray) ToRune added in v1.2.0

func (t *LongArray) ToRune() (rune, error)

ToRune returns value as rune

func (*LongArray) ToString added in v1.2.0

func (t *LongArray) ToString() (string, error)

ToString returns value as string

func (*LongArray) ToUInt added in v1.2.0

func (t *LongArray) ToUInt() (uint, error)

ToUInt returns value as uint

func (*LongArray) ToUInt16 added in v1.2.0

func (t *LongArray) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*LongArray) ToUInt32 added in v1.2.0

func (t *LongArray) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*LongArray) ToUInt64 added in v1.2.0

func (t *LongArray) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*LongArray) ToUInt8 added in v1.2.0

func (t *LongArray) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*LongArray) Write added in v1.2.0

func (t *LongArray) Write(n *Stream) error

Write writes tag for Stream

type Short

type Short struct {
	Value int16
	// contains filtered or unexported fields
}

Short is a tag for a short

func NewShortTag added in v1.2.2

func NewShortTag(name string, val int16) *Short

NewShortTag returns a new Short tag

func (*Short) ID

func (t *Short) ID() byte

ID returns tag id

func (*Short) Name

func (t *Short) Name() string

Name returns tag's name

func (*Short) Read

func (t *Short) Read(n *Stream) (err error)

Read reads tag from Stream

func (*Short) SetName

func (t *Short) SetName(name string)

SetName set name in tag

func (*Short) ToBool

func (t *Short) ToBool() (bool, error)

ToBool returns value as bool

func (*Short) ToByte

func (t *Short) ToByte() (byte, error)

ToByte returns value as byte

func (*Short) ToByteArray

func (t *Short) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*Short) ToFloat32

func (t *Short) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*Short) ToFloat64

func (t *Short) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*Short) ToInt

func (t *Short) ToInt() (int, error)

ToInt returns value as int

func (*Short) ToInt16

func (t *Short) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*Short) ToInt32

func (t *Short) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*Short) ToInt64

func (t *Short) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*Short) ToInt8

func (t *Short) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*Short) ToIntArray

func (t *Short) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*Short) ToLongArray added in v1.2.0

func (t *Short) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*Short) ToRune

func (t *Short) ToRune() (rune, error)

ToRune returns value as rune

func (*Short) ToString

func (t *Short) ToString() (string, error)

ToString returns value as string

func (*Short) ToUInt

func (t *Short) ToUInt() (uint, error)

ToUInt returns value as uint

func (*Short) ToUInt16

func (t *Short) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*Short) ToUInt32

func (t *Short) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*Short) ToUInt64

func (t *Short) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*Short) ToUInt8

func (t *Short) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*Short) Write

func (t *Short) Write(n *Stream) error

Write writes tag for Stream

type Stream

type Stream struct {
	Stream *binary.OrderStream
}

Stream is binary nbt stream

func FromBytes added in v1.2.0

func FromBytes(b []byte, order binary.Order) (*Stream, error)

FromBytes returns new stream with bytes If the bytes is compressed, it will uncompresses

func FromFile

func FromFile(path string, order binary.Order) (*Stream, error)

FromFile returns new stream from file If the bytes is compressed, it will uncompresses

func FromReader

func FromReader(reader io.Reader, order binary.Order) (*Stream, error)

FromReader returns new stream from Reader If the bytes is compressed, it will uncompresses

func NewStream

func NewStream(order binary.Order) *Stream

NewStream returns new Stream

func NewStreamBytes

func NewStreamBytes(order binary.Order, b []byte) *Stream

NewStreamBytes returns new Stream with bytes data

func (*Stream) Bytes

func (s *Stream) Bytes() []byte

Bytes returns stream's all buffer

func (*Stream) ReadTag

func (s *Stream) ReadTag() (Tag, error)

ReadTag reads tag from buffer

func (*Stream) Reset

func (s *Stream) Reset()

Reset resets buffer

func (*Stream) WriteTag

func (s *Stream) WriteTag(tag Tag) error

WriteTag writes tag to buffer

type String

type String struct {
	Value string
	// contains filtered or unexported fields
}

String is a tag for string

func NewStringTag added in v1.2.2

func NewStringTag(name string, val string) *String

NewStringTag returns a new String tag

func (*String) ID

func (t *String) ID() byte

ID returns tag id

func (*String) Name

func (t *String) Name() string

Name returns tag's name

func (*String) Read

func (t *String) Read(n *Stream) (err error)

Read reads tag from Stream

func (*String) SetName

func (t *String) SetName(name string)

SetName set name in tag

func (*String) ToBool

func (t *String) ToBool() (bool, error)

ToBool returns value as bool

func (*String) ToByte

func (t *String) ToByte() (byte, error)

ToByte returns value as byte

func (*String) ToByteArray

func (t *String) ToByteArray() ([]byte, error)

ToByteArray returns value as []byte

func (*String) ToFloat32

func (t *String) ToFloat32() (float32, error)

ToFloat32 returns value as float32

func (*String) ToFloat64

func (t *String) ToFloat64() (float64, error)

ToFloat64 returns value as float64

func (*String) ToInt

func (t *String) ToInt() (int, error)

ToInt returns value as int

func (*String) ToInt16

func (t *String) ToInt16() (int16, error)

ToInt16 returns value as int16

func (*String) ToInt32

func (t *String) ToInt32() (int32, error)

ToInt32 returns value as int32

func (*String) ToInt64

func (t *String) ToInt64() (int64, error)

ToInt64 returns value as int64

func (*String) ToInt8

func (t *String) ToInt8() (int8, error)

ToInt8 returns value as int8

func (*String) ToIntArray

func (t *String) ToIntArray() ([]int32, error)

ToIntArray returns value as []int32

func (*String) ToLongArray added in v1.2.0

func (t *String) ToLongArray() ([]int64, error)

ToLongArray returns value as []int64

func (*String) ToRune

func (t *String) ToRune() (rune, error)

ToRune returns value as rune

func (*String) ToString

func (t *String) ToString() (string, error)

ToString returns value as string

func (*String) ToUInt

func (t *String) ToUInt() (uint, error)

ToUInt returns value as uint

func (*String) ToUInt16

func (t *String) ToUInt16() (uint16, error)

ToUInt16 returns value as uint16

func (*String) ToUInt32

func (t *String) ToUInt32() (uint32, error)

ToUInt32 returns value as uint32

func (*String) ToUInt64

func (t *String) ToUInt64() (uint64, error)

ToUInt64 returns value as uint64

func (*String) ToUInt8

func (t *String) ToUInt8() (uint8, error)

ToUInt8 returns value as uint8

func (*String) Write

func (t *String) Write(n *Stream) error

Write writes tag for Stream

type Tag

type Tag interface {
	// ID returns tag id
	ID() byte

	// Name returns tag's name
	Name() string

	// SetName set name in tag
	SetName(name string)

	// Read reads tag from Stream
	Read(nbt *Stream) error

	// Write writes tag for Stream
	Write(nbt *Stream) error

	// ToBool returns value as bool
	ToBool() (bool, error)

	// ToByte returns value as byte
	ToByte() (byte, error)

	// ToRune returns value as rune
	ToRune() (rune, error)

	// ToInt returns value as int
	ToInt() (int, error)

	// ToUInt returns value as uint
	ToUInt() (uint, error)

	// ToUInt8 returns value as uint8
	ToUInt8() (uint8, error)

	// ToUInt16 returns value as uint16
	ToUInt16() (uint16, error)

	// ToUInt32 returns value as uint32
	ToUInt32() (uint32, error)

	// ToUInt64 returns value as uint64
	ToUInt64() (uint64, error)

	// ToInt8 returns value as int8
	ToInt8() (int8, error)

	// ToInt16 returns value as int16
	ToInt16() (int16, error)

	// ToInt32 returns value as int32
	ToInt32() (int32, error)

	// ToInt64 returns value as int64
	ToInt64() (int64, error)

	// ToFloat32 returns value as float32
	ToFloat32() (float32, error)

	// ToFloat64 returns value as float64
	ToFloat64() (float64, error)

	// ToByteArray returns value as []byte
	ToByteArray() ([]byte, error)

	// ToString returns value as string
	ToString() (string, error)

	// ToIntArray returns value as []int32
	ToIntArray() ([]int32, error)

	// ToLongArray returns value as []int64
	ToLongArray() ([]int64, error)
}

Tag is a nbt tag interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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