Soulless.Protocol.GenericPacket behaviour (Soulless v0.2.0)

View Source

Summary

Types

cache()

@type cache() :: %{required(non_neg_integer()) => module() | rpc()}

kind()

@type kind() :: :notice | :request | :response

kind_or_unknown()

@type kind_or_unknown() :: :notice | :request | :response | :unknown

rpc()

@type rpc() :: [
  request_module: lq_module :: module(),
  response_module: lq_module :: module(),
  rpc: rpc_name()
]

rpc_name()

@type rpc_name() :: String.t()

t()

@type t() :: %Soulless.Protocol.GenericPacket{
  body: struct() | nil,
  kind: kind() | nil,
  request_id: (non_neg_integer() | nil) | nil,
  rpc: (rpc_name() | nil) | nil
}

Callbacks

decode_wrapper(body)

@callback decode_wrapper(body :: binary()) :: {:ok, struct()} | {:error, any()}

get_rpc_by_identifier(rpc_name)

@callback get_rpc_by_identifier(rpc_name()) ::
  {:ok, rpc()} | {:error, error :: String.t()}

get_type_by_identifier(rpc_name)

@callback get_type_by_identifier(rpc_name()) ::
  {:ok, lq_module :: module()} | {:error, String.t()}

post_body_decode(body)

@callback post_body_decode(body :: struct()) :: {:ok, struct()} | {:error, any()}

pre_body_encode(body)

@callback pre_body_encode(body :: struct()) :: struct()

wrap_and_encode(rpc_name, body)

@callback wrap_and_encode(rpc_name(), body :: binary()) :: binary()

Functions

parse(callback_module, binary, module_cache)

@spec parse(module(), binary(), cache()) ::
  {:ok, {t(), cache()}} | {:error, String.t()}

parse_raw_packet(binary)

@spec parse_raw_packet(binary()) ::
  {:ok, Soulless.Protocol.GenericPacket.Raw.t()} | {:error, String.t()}

serialize(callback_module, message, module_cache)

@spec serialize(module(), t(), cache()) :: {nonempty_binary(), cache()}