packets

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxPacketLength = errors.New("mcproto: counterpart sent a packet which was too big")
)

Functions

This section is empty.

Types

type MinecraftPacket

type MinecraftPacket struct {
	// PacketID is a VarInt identifier of the packet
	// refer to wiki.vg for all the packet ids
	PacketID int32

	// Remaining data of the packet, excluding packetid
	Data []byte
}

Basic struct containing the PacketID and many methods for serialization.

func FromRawPacket

func FromRawPacket(rawPacket *MinecraftRawPacket) (*MinecraftPacket, error)

FromRawPacket returns a new MinecraftPacket, and takes a rawpacket as an input. rawPacket.ReadAll() is called to decode the packetid and the packet data

func (*MinecraftPacket) DeserializeData

func (p *MinecraftPacket) DeserializeData(inter interface{}) error

DeserializeData deserializes the data buffer into the struct fields which have a type struct tag

func (*MinecraftPacket) SerializeCompressed

func (p *MinecraftPacket) SerializeCompressed(writer io.Writer, compressionTreshold int) error

SerializeCompressed serializes the fields into a buffer, and if the buffer exceeds compressionTreshold in length, it proceeds to compress it using zlib. Writes a complete packet into writer

func (*MinecraftPacket) SerializeData

func (p *MinecraftPacket) SerializeData(inter interface{}) error

SerializeData serializes all the fields in the struct with a type struct tag into the data buffer

func (*MinecraftPacket) SerializeUncompressed

func (p *MinecraftPacket) SerializeUncompressed(writer io.Writer) error

SerializeUncompress serializes the fields into a buffer and writes a complete packet in writer using the uncompressed format. Never uses compression

type MinecraftRawPacket

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

func FromCompressedReader

func FromCompressedReader(reader io.Reader) (*MinecraftRawPacket, error)

FromCompressedReader reads a packet in its compressed format, but it does not necessarily mean the packet must be compressed. Can be uncompressed later with NewReader

func FromUncompressedReader

func FromUncompressedReader(reader io.Reader) (*MinecraftRawPacket, error)

FromUncompressedReader reads a packet in its uncompressed format (without dataLength) and returns a new MinecraftRawPacket

func (*MinecraftRawPacket) Data added in v1.0.3

func (rp *MinecraftRawPacket) Data() []byte

func (*MinecraftRawPacket) NewReader

func (rp *MinecraftRawPacket) NewReader() (io.ReadCloser, error)

NewReader opens a bytes.Buffer or zlib readcloser depending if the packet is compressed or not

func (*MinecraftRawPacket) ReadAll

func (rp *MinecraftRawPacket) ReadAll() (packetId int32, data []byte, err error)

ReadAll reads all the available content in the packet, returning data as an uncompressed byte slice

func (*MinecraftRawPacket) ReadPacketId

func (rp *MinecraftRawPacket) ReadPacketId() (int32, error)

ReadPacketId opens a reader, reads the packet id but doesn't go further

func (*MinecraftRawPacket) WriteCompressed

func (rp *MinecraftRawPacket) WriteCompressed(writer io.Writer) error

WriteCompressed calculates the packetlength based on the dataLength and the dimension of the compressed/uncompressed data.

func (*MinecraftRawPacket) WriteUncompressed

func (rp *MinecraftRawPacket) WriteUncompressed(writer io.Writer) error

Write compress calculates packet length and writes the complete packet to writer using the uncompressed format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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