macula_core_types (macula v0.20.5)

View Source

Core type definitions and encoding/decoding for Macula. Provides fundamental types like node IDs, realm IDs, and addresses.

Summary

Types

32-byte unique node identifier

32-byte realm identifier

Functions

Decode binary address format to {IP, Port} tuple.

Encode an IP address and port to binary format. Format: - 1 byte: IP version (4 or 6) - 4 or 16 bytes: IP address - 2 bytes: port (big-endian)

Generate a unique node ID. Uses cryptographically strong random bytes for uniqueness.

Generate a deterministic realm ID from a realm name. Same name always produces the same ID (uses SHA-256 hash).

Types

address/0

-type address() :: {ip_address(), port_number()}.

ip_address/0

-type ip_address() :: inet:ip_address().

node_id/0

-type node_id() :: binary().

32-byte unique node identifier

port_number/0

-type port_number() :: inet:port_number().

realm_id/0

-type realm_id() :: binary().

32-byte realm identifier

Functions

decode_address(_)

-spec decode_address(binary()) -> {ok, address()} | {error, invalid_address}.

Decode binary address format to {IP, Port} tuple.

encode_address(_)

-spec encode_address(address()) -> binary().

Encode an IP address and port to binary format. Format: - 1 byte: IP version (4 or 6) - 4 or 16 bytes: IP address - 2 bytes: port (big-endian)

node_id()

-spec node_id() -> node_id().

Generate a unique node ID. Uses cryptographically strong random bytes for uniqueness.

realm_id(RealmName)

-spec realm_id(binary()) -> realm_id().

Generate a deterministic realm ID from a realm name. Same name always produces the same ID (uses SHA-256 hash).