macula_protocol_types (macula v0.14.3)

View Source

Protocol message type definitions and constants for Macula mesh. Defines all message types that can be sent over QUIC streams.

Summary

Functions

Get numeric ID for a message type.

Get message type name from numeric ID.

Types

bridge_data_msg/0

-type bridge_data_msg() :: #{payload := term(), source_node_id => binary(), metadata => map()}.

bridge_rpc_msg/0

-type bridge_rpc_msg() ::
          #{procedure := binary(),
            args := map(),
            call_id := binary(),
            source_level := atom(),
            timeout => integer()}.

call_msg/0

-type call_msg() ::
          #{procedure := binary(), args := binary(), call_id := binary(), timeout => integer()}.

cast_msg/0

-type cast_msg() :: #{procedure := binary(), args := binary()}.

connect_msg/0

-type connect_msg() ::
          #{version := binary(),
            node_id := binary(),
            realm_id := binary(),
            capabilities := [atom()],
            endpoint => binary()}.

disconnect_msg/0

-type disconnect_msg() :: #{reason := atom(), message := binary()}.

message/0

-type message() ::
          {connect, connect_msg()} |
          {disconnect, disconnect_msg()} |
          {ping, ping_msg()} |
          {pong, pong_msg()} |
          {publish, publish_msg()} |
          {subscribe, subscribe_msg()} |
          {unsubscribe, unsubscribe_msg()} |
          {pubsub_route, pubsub_route_msg()} |
          {call, call_msg()} |
          {reply, reply_msg()} |
          {cast, cast_msg()} |
          {rpc_route, rpc_route_msg()}.

message_type/0

-type message_type() ::
          connect | disconnect | ping | pong | publish | subscribe | unsubscribe | pubsub_route | call |
          reply | cast | rpc_route | rpc_request | rpc_reply | swim_ping | swim_ack | swim_ping_req |
          find_node | find_node_reply | store | find_value | find_value_reply | nat_probe |
          nat_probe_reply | punch_request | punch_coordinate | punch_execute | punch_result |
          relay_request | relay_data | bridge_rpc | bridge_data.

ping_msg/0

-type ping_msg() :: #{timestamp := integer()}.

pong_msg/0

-type pong_msg() :: #{timestamp := integer(), server_time := integer()}.

publish_msg/0

-type publish_msg() ::
          #{topic := binary(),
            payload := binary(),
            qos := 0 | 1 | 2,
            retain := boolean(),
            message_id := binary()}.

pubsub_route_msg/0

-type pubsub_route_msg() :: #{binary() => term()}.

reply_msg/0

-type reply_msg() ::
          #{call_id := binary(), result => binary(), error => #{code := binary(), message := binary()}}.

rpc_route_msg/0

-type rpc_route_msg() :: #{binary() => term()}.

subscribe_msg/0

-type subscribe_msg() :: #{topics := [binary()], qos := 0 | 1 | 2}.

unsubscribe_msg/0

-type unsubscribe_msg() :: #{topics := [binary()]}.

Functions

message_type_id(_)

-spec message_type_id(message_type()) -> byte().

Get numeric ID for a message type.

message_type_name(_)

-spec message_type_name(byte()) -> {ok, message_type()} | {error, unknown_type}.

Get message type name from numeric ID.