Documentation ¶
Index ¶
- Variables
- type HandshakePacket
- 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("minecomm: packet length too big")
)
Functions ¶
This section is empty.
Types ¶
type HandshakePacket ¶
type HandshakePacket struct { MinecraftPacket ProtocolVersion int32 `mc:"varint"` ServerAddress string `mc:"string"` ServerPort uint16 `mc:"inherit"` NextState int32 `mc:"varint"` }
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 }
MinecraftPacket 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 raw packet as an input. rawPacket.ReadAll() is called to decode the packetid and the packet data
func (*MinecraftPacket) SerializeCompressed ¶
func (p *MinecraftPacket) SerializeCompressed(writer io.Writer, compressionThreshold int) error
SerializeCompressed serializes the fields into a buffer, and if the buffer exceeds compressionThreshold in length, it proceeds to compress it using zlib. Writes a complete packet into writer
func (*MinecraftPacket) SerializeUncompressed ¶
func (p *MinecraftPacket) SerializeUncompressed(writer io.Writer) error
SerializeUncompressed 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) 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 packet length based on the dataLength and the dimension of the compressed/uncompressed data.
func (*MinecraftRawPacket) WriteUncompressed ¶
func (rp *MinecraftRawPacket) WriteUncompressed(writer io.Writer) error
WriteUncompressed calculates packet length and writes the complete packet to writer using the uncompressed format