macula_utils (macula v0.20.5)
View SourceCommon utility functions for Macula.
This module contains pure utility functions used across the Macula codebase to improve testability and eliminate duplication.
All functions in this module are pure (no side effects) and can be tested independently.
Summary
Functions
Decode JSON binary to map/list.
Encode map/list to JSON binary.
Ensure value is binary.
Generate a random node ID.
Get next message ID from counter. Returns {MessageId, NewCounter}.
Normalize provider map from binary keys to atom keys.
Parse host:port string with default port.
Parse URL to extract host and port.
Check if a published topic matches a subscription topic pattern. Supports configurable wildcards (defaults: dot-separated with * and **): - WildcardSingle (e.g., '*') matches a single segment - WildcardMulti (e.g., '**') matches multiple segments - Separator (e.g., '.') splits topic into segments - exact match otherwise
Functions
Decode JSON binary to map/list.
Encode map/list to JSON binary.
Ensure value is binary.
-spec generate_node_id() -> binary().
Generate a random node ID.
-spec next_message_id(non_neg_integer()) -> {binary(), non_neg_integer()}.
Get next message ID from counter. Returns {MessageId, NewCounter}.
Normalize provider map from binary keys to atom keys.
-spec parse_host_port(string(), inet:port_number()) -> {string(), inet:port_number()}.
Parse host:port string with default port.
-spec parse_url(binary()) -> {string(), inet:port_number()}.
Parse URL to extract host and port.
-spec topic_matches(binary() | list(), binary() | list(), binary(), binary(), binary()) -> boolean().
Check if a published topic matches a subscription topic pattern. Supports configurable wildcards (defaults: dot-separated with * and **): - WildcardSingle (e.g., '*') matches a single segment - WildcardMulti (e.g., '**') matches multiple segments - Separator (e.g., '.') splits topic into segments - exact match otherwise