poa_backend v0.1.0 POABackend.Protocol.Message View Source

The message received from the Agent (inspired in Plug.Conn).

This module defines the Message received from the Agent and the main functions in order to work with it.

Message Fields

  • agent_id - The Agent Id which sent the message to the backend.
  • data_type - The kind of data the message is carring. For now only ethereum_metric type is defined.
  • message_type - This is the message type according to the custom protocol. Only data and bye are defined for now
  • assigns - Shared user data as a map
  • data - The message payloda. It is a map

Link to this section Summary

Types

t()

The Message struct

Functions

Assigns a value to a key in the connection

Returns a new Message Struct

Returns a new Message Struct initialized. The params in order are: agent_id, data_type, message_type and data

Link to this section Types

Link to this type t() View Source
t() :: %POABackend.Protocol.Message{
  agent_id: String.t() | nil,
  assigns: %{optional(atom()) => any()},
  data: Map.t() | nil,
  data_type: POABackend.CustomProtocol.DataType.t() | nil,
  message_type: POABackend.CustomProtocol.MessageType.t() | nil
}

The Message struct.

That keeps all the message data and metadata

Link to this section Functions

Link to this function assign(message, key, value) View Source
assign(t(), atom(), term()) :: t()

Assigns a value to a key in the connection.

Examples

iex> alias POABackend.Protocol.Message
iex> message = Message.new()
iex> message.assigns[:hello]
nil
iex> message = Message.assign(message, :hello, :world)
iex> message.assigns[:hello]
:world

Returns a new Message Struct

Link to this function new(agent_id, data_type, message_type, data) View Source
new(
  String.t(),
  POABackend.CustomProtocol.DataType.t(),
  POABackend.CustomProtocol.MessageType.t(),
  Map.t()
) :: t()

Returns a new Message Struct initialized. The params in order are: agent_id, data_type, message_type and data