protocol

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPacketID = errors.New("invalid packet id")
)

Functions

func ReadNBytes

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

ReadNBytes read N bytes from bytes.Reader

func ReadPacketBytes

func ReadPacketBytes(r DecodeReader) ([]byte, error)

ReadPacketBytes decodes a byte stream and cuts the first Packet as a byte array out

func ScanFields

func ScanFields(r DecodeReader, fields ...FieldDecoder) error

ScanFields decodes a byte stream into fields

Types

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 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 Identifier

type Identifier = String

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

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 OptionalByteArray

type OptionalByteArray []byte

OptionalByteArray is []byte without prefix VarInt as length

func (*OptionalByteArray) Decode

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

Decode a OptionalByteArray

func (OptionalByteArray) Encode

func (b OptionalByteArray) Encode() []byte

Encode a OptionalByteArray

type Packet

type Packet struct {
	ID   byte
	Data []byte
}

Packet is the raw representation of message that is send between the client and the server

func MarshalPacket

func MarshalPacket(ID byte, fields ...FieldEncoder) Packet

MarshalPacket transforms an ID and Fields into a Packet

func PeekPacket

func PeekPacket(p PeekReader) (Packet, error)

PeekPacket decodes and decompresses a byte stream and peeks the first Packet

func ReadPacket

func ReadPacket(r DecodeReader) (Packet, error)

ReadPacket decodes and decompresses a byte stream and cuts the first Packet out

func (*Packet) Marshal

func (pk *Packet) Marshal() ([]byte, error)

Marshal encodes the packet and all it's fields

func (Packet) Scan

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

Scan decodes and copies the Packet data into the fields

type PeekReader

type PeekReader interface {
	Peek(n int) ([]byte, error)
	io.Reader
}

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() []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 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() []byte

Encode a VarInt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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