SwimEx.Codec (SwimEx v0.1.0)

View Source

Codec for SWIM protocol messages.

Handles serialization and deserialization of messages and gossip events. Uses Erlang External Term Format for simplicity.

Summary

Functions

Decodes a binary payload into a message.

Encodes a message into a binary payload.

Returns the maximum transmission unit (MTU) for SWIM packets.

Types

event()

@type event() ::
  {:alive, node_id(), incarnation()}
  | {:suspect, node_id(), incarnation()}
  | {:dead, node_id(), incarnation()}

incarnation()

@type incarnation() :: non_neg_integer()

message()

@type message() ::
  {:ping, node_id(), seq :: non_neg_integer(), [event()]}
  | {:ack, node_id(), seq :: non_neg_integer(), [event()]}
  | {:ping_req, node_id(), seq :: non_neg_integer(), target :: node_id(),
     [event()]}
  | {:fwd_ack, node_id(), seq :: non_neg_integer(), source :: node_id(),
     [event()]}

node_id()

@type node_id() :: {String.t(), :inet.port_number(), String.t()}

Functions

decode(bin)

@spec decode(binary()) :: {:ok, message()} | {:error, :invalid}

Decodes a binary payload into a message.

Returns {:ok, message} or {:error, :invalid}.

encode(msg)

@spec encode(message()) :: {:ok, binary()} | {:error, :too_large}

Encodes a message into a binary payload.

Returns {:error, :too_large} if the resulting binary exceeds the MTU.

mtu()

@spec mtu() :: non_neg_integer()

Returns the maximum transmission unit (MTU) for SWIM packets.