Skip to main content

Module codec

Module codec 

Source
Expand description

Packet framing, compression, and high-level encode/decode functions.

The Minecraft wire format is:

  • Without compression: [VarInt: packet_length][VarInt: packet_id][payload]
  • With compression (below threshold): [VarInt: packet_length][0x00][VarInt: packet_id][payload]
  • With compression (above threshold): [VarInt: packet_length][VarInt: uncompressed_size][zlib(packet_id + payload)]

Constants§

MAX_UNCOMPRESSED_SIZE
Maximum allowed uncompressed packet size (8 MiB).

Functions§

encode_packet_data
Encode a typed packet into raw bytes (packet ID + fields), without framing.
read_compressed_frame
Decode the inner frame data when compression is enabled.
read_packet_id
Read a packet ID from frame data.
try_read_frame
Try to extract a single frame from the given buffer.
write_compressed_frame
Wrap packet data with the compression format.
write_frame
Write a frame (length-prefixed) into the destination buffer. inner is the already-encoded packet data (packet ID + payload).