View Source ElvenGard.Network.PacketSerializer (ElvenGard.Network v0.1.0)

Packet Serializer DSL for defining packet structures.

This module provides a DSL (Domain-Specific Language) for defining packet serializers for both received and sent packets in a network protocol. It enables users to create structured packets with specified fields and decode binary data into packet structs.

To learn more about the available macros and how to define packet serializers, refer to the Packet Serializer DSL guide.

packet-macros

Packet Macros

The defpacket macros (defpacket/1, defpacket/2, and defpacket/3) allow users to define packet structures. They require a packet ID and an alias (which is the name of the generated packet structure). The guard (with the when keyword) and do-block (for defining fields) are optional.

Users can specify guards in packet macros to conditionally match packets based on a condition (often using socket assigns).

packet-structure-serialization-and-deserialization

Packet Structure, Serialization, and Deserialization

The defpacket macros can generate a packet structure, a deserialize/3 function for deserializing binary data into the packet structure, and a serialize/1 function for generating the serialized binary representation of the packet.

The deserialize/3 function should be used for decoding received packets, and the serialize/1 function should be used for generating packets to be sent over the network.

field-macros

Field Macros

The field macros are used to define fields within a packet:

  • field/2: Define a field with a name and type.
  • field/3: Define a field with a name, type, and decoding options.

decorators

Decorators

The following decorators can be used to specify serialization and deserialization properties:

  • @serializable true: Marks the packet as serializable for sending over the network.
  • @deserializable true: Marks the packet as deserializable for receiving from the network.

Link to this section Summary

Link to this section Functions

Link to this macro

defpacket(id, list)

View Source (macro)
Link to this macro

defpacket(id, list1, list2)

View Source (macro)
Link to this macro

field(name, type, opts \\ [])

View Source (macro)
Link to this macro

import_packets(mod)

View Source (macro)