Documentation ¶
Index ¶
- Variables
- type MinecraftPacket
- type MinecraftRawPacket
- func (rp *MinecraftRawPacket) NewReader() (io.ReadCloser, error)
- func (rp *MinecraftRawPacket) ReadAll() (packetId int32, data []byte, err error)
- func (rp *MinecraftRawPacket) ReadPacketId() (int32, error)
- func (rp *MinecraftRawPacket) WriteCompressed(writer io.Writer) error
- func (rp *MinecraftRawPacket) WriteUncompressed(writer io.Writer) error
Constants ¶
This section is empty.
Variables ¶
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 ¶ added in v0.3.1
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 ¶ added in v0.3.1
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 ¶ added in v0.3.1
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 ¶ added in v0.3.1
type MinecraftRawPacket struct {
// contains filtered or unexported fields
}
func FromCompressedReader ¶ added in v0.3.1
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 ¶ added in v0.3.1
func FromUncompressedReader(reader io.Reader) (*MinecraftRawPacket, error)
FromUncompressedReader reads a packet in its uncompressed format (without dataLength) and returns a new MinecraftRawPacket
func (*MinecraftRawPacket) NewReader ¶ added in v0.3.1
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 ¶ added in v0.3.1
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 ¶ added in v0.3.1
func (rp *MinecraftRawPacket) ReadPacketId() (int32, error)
ReadPacketId opens a reader, reads the packet id but doesn't go further
func (*MinecraftRawPacket) WriteCompressed ¶ added in v0.3.1
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 ¶ added in v0.3.1
func (rp *MinecraftRawPacket) WriteUncompressed(writer io.Writer) error
Write compress calculates packet length and writes the complete packet to writer using the uncompressed format