Minecraft v0.1.0 Minecraft.Packet View Source

Base serialization and deserialization routines for packets.

Link to this section Summary

Functions

Decodes a string

Decodes a variable-size integer

Decodes a variable-size long

Given a raw binary packet, deserializes it into a Packet struct

Encodes a string

Encodes a variable-size integer

Serializes a packet into binary data

Serializes a packet binary into the standard packet format

Link to this section Types

Link to this type varint() View Source
varint() :: -2_147_483_648..2_147_483_647
Link to this type varlong() View Source
varlong() :: -9_223_372_036_854_775_808..9_223_372_036_854_775_807

Link to this section Functions

Link to this function decode_string(data) View Source
decode_string(binary()) :: {decoded :: binary(), rest :: binary()}

Decodes a string.

Link to this function decode_varint(data) View Source
decode_varint(binary()) ::
  {decoded :: varint(), rest :: binary()} | {:error, :too_long | :too_short}

Decodes a variable-size integer.

Link to this function decode_varlong(data) View Source
decode_varlong(binary()) ::
  {decoded :: varlong(), rest :: binary()} | {:error, :too_long | :too_short}

Decodes a variable-size long.

Link to this function deserialize(data, state, type \\ :client) View Source
deserialize(binary(), state :: atom(), type :: :client | :server) ::
  {packet :: term(), rest :: binary()} | {:error, :invalid_packet}

Given a raw binary packet, deserializes it into a Packet struct.

Link to this function encode_string(string) View Source
encode_string(binary()) :: binary()

Encodes a string.

Link to this function encode_varint(value) View Source
encode_varint(varint()) :: binary() | {:error, :too_large}

Encodes a variable-size integer.

Link to this function serialize(request) View Source
serialize(packet :: struct()) :: {:ok, binary()} | {:error, term()}

Serializes a packet into binary data.

Link to this function serialize(packet_id, packet_binary) View Source
serialize(packet_id :: integer(), binary()) ::
  {:ok, binary()} | {:error, term()}

Serializes a packet binary into the standard packet format:

FieldTypeDescription
LengthVarIntLength of packet data + length of the packet ID
Packet IDVarInt
DataBinaryThe serialized packet data