packet

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(data []byte) []byte

Compress 压缩数据

func ReadNBytes

func ReadNBytes(r DecodeReader, n int) (bs []byte, err error)

ReadNBytes read N bytes from bytes.Reader

Types

type Angle

type Angle int8

Angle is rotation angle in steps of 1/256 of a full turn

func (*Angle) Decode

func (b *Angle) Decode(r DecodeReader) error

Decodes an Angle

type Ary

type Ary struct {
	Len Field
	Ary interface{}
}

func (Ary) Decode

func (a Ary) Decode(r DecodeReader) error

func (Ary) Encode

func (a Ary) Encode() (data []byte)

type Boolean

type Boolean bool

Boolean of True is encoded as 0x01, false as 0x00.

func (*Boolean) Decode

func (b *Boolean) Decode(r DecodeReader) error

Decode a Boolean

func (Boolean) Encode

func (b Boolean) Encode() []byte

Encode a Boolean

type Byte

type Byte int8

Byte is signed 8-bit integer, two's complement

func (*Byte) Decode

func (b *Byte) Decode(r DecodeReader) error

Decode a Byte

func (Byte) Encode

func (b Byte) Encode() []byte

Encode a Byte

type ByteArray

type ByteArray []byte

ByteArray is []byte with prefix VarInt as length

func (*ByteArray) Decode

func (b *ByteArray) Decode(r DecodeReader) error

Decode a ByteArray

func (ByteArray) Encode

func (b ByteArray) Encode() []byte

Encode a ByteArray

type Chat

type Chat = String

Chat is encoded as a String with max length of 32767.

type DecodeReader

type DecodeReader interface {
	io.ByteReader
	io.Reader
}

DecodeReader is both io.Reader and io.ByteReader

type Double

type Double float64

A Double is a double-precision 64-bit IEEE 754 floating point number

func (*Double) Decode

func (d *Double) Decode(r DecodeReader) error

Decode a Double

func (Double) Encode

func (d Double) Encode() []byte

Encode a Double

type Field

type Field interface {
	FieldEncoder
	FieldDecoder
}

A Field is both FieldEncoder and FieldDecoder

type FieldDecoder

type FieldDecoder interface {
	Decode(r DecodeReader) error
}

A FieldDecoder can Decode from minecraft protocol

type FieldEncoder

type FieldEncoder interface {
	Encode() []byte
}

A FieldEncoder can be encode as minecraft protocol used.

type Float

type Float float32

A Float is a single-precision 32-bit IEEE 754 floating point number

func (*Float) Decode

func (f *Float) Decode(r DecodeReader) error

Decode a Float

func (Float) Encode

func (f Float) Encode() []byte

Encode a Float

type Identifier

type Identifier = String

Identifier is encoded as a String with max length of 32767.

type Int

type Int int32

Int is signed 32-bit integer, two's complement

func (*Int) Decode

func (i *Int) Decode(r DecodeReader) error

Decode a Int

func (Int) Encode

func (i Int) Encode() []byte

Encode a Int

type Long

type Long int64

Long is signed 64-bit integer, two's complement

func (*Long) Decode

func (l *Long) Decode(r DecodeReader) error

Decode a Long

func (Long) Encode

func (l Long) Encode() []byte

Encode a Long

type NBT

type NBT struct {
	V interface{}
}

NBT encode a value as Named Binary Tag

func (NBT) Decode

func (n NBT) Decode(r DecodeReader) error

Decode a NBT

type Opt

type Opt struct {
	Has   func() bool
	Field interface{}
}

func (Opt) Decode

func (o Opt) Decode(r DecodeReader) error

func (Opt) Encode

func (o Opt) Encode() []byte

type Packet

type Packet struct {
	ID   int32
	Data []byte
}

Packet define a net data package

func Marshal

func Marshal(id data.PktID, fields ...FieldEncoder) (pk Packet)

Marshal generate Packet with the ID and Fields

func RecvPacket

func RecvPacket(r DecodeReader, useZlib bool) (*Packet, error)

RecvPacket receive a packet from server

func UnCompress

func UnCompress(data []byte) (*Packet, error)

UnCompress 读取一个压缩的包

func (*Packet) Pack

func (p *Packet) Pack(threshold int) (pack []byte)

Pack 打包一个数据包

func (Packet) Scan

func (p Packet) Scan(fields ...FieldDecoder) error

Scan decode the packet and fill data into fields

type Position

type Position struct {
	X, Y, Z int
}

Position x as a 26-bit integer, followed by y as a 12-bit integer, followed by z as a 26-bit integer (all signed, two's complement)

func (*Position) Decode

func (p *Position) Decode(r DecodeReader) error

Decode a Position

func (Position) Encode

func (p Position) Encode() []byte

Encode a Position

type Short

type Short int16

Short is signed 16-bit integer, two's complement

func (*Short) Decode

func (s *Short) Decode(r DecodeReader) error

Decode a Short

func (Short) Encode

func (s Short) Encode() []byte

Encode a Signed Short

type String

type String string

String is sequence of Unicode scalar values

func (*String) Decode

func (s *String) Decode(r DecodeReader) error

Decode a String

func (String) Encode

func (s String) Encode() (p []byte)

Encode a String

type UUID

type UUID uuid.UUID

UUID encoded as an unsigned 128-bit integer

func (*UUID) Decode

func (u *UUID) Decode(r DecodeReader) error

Decode a UUID

func (UUID) Encode

func (u UUID) Encode() []byte

Encode a UUID

type UnsignedByte

type UnsignedByte uint8

UnsignedByte is unsigned 8-bit integer

func (*UnsignedByte) Decode

func (ub *UnsignedByte) Decode(r DecodeReader) error

Decode a UnsignedByte

func (UnsignedByte) Encode

func (ub UnsignedByte) Encode() []byte

Encode a UnsignedByte

type UnsignedShort

type UnsignedShort uint16

UnsignedShort is unsigned 16-bit integer

func (*UnsignedShort) Decode

func (us *UnsignedShort) Decode(r DecodeReader) error

Decode a UnsignedShort

func (UnsignedShort) Encode

func (us UnsignedShort) Encode() []byte

Encode a Unsigned Short

type VarInt

type VarInt int32

VarInt is variable-length data encoding a two's complement signed 32-bit integer

func (*VarInt) Decode

func (v *VarInt) Decode(r DecodeReader) error

Decode a VarInt

func (VarInt) Encode

func (v VarInt) Encode() (vi []byte)

Encode a VarInt

type VarLong

type VarLong int64

VarLong is variable-length data encoding a two's complement signed 64-bit integer

func (*VarLong) Decode

func (v *VarLong) Decode(r DecodeReader) error

Decode a VarLong

func (VarLong) Encode

func (v VarLong) Encode() (vi []byte)

Encode a VarLong

Jump to

Keyboard shortcuts

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