macula_pubsub_topic (macula v0.20.5)

View Source

Topic utilities for pub/sub system. Handles topic validation, pattern matching, and normalization. Supports MQTT-style wildcards: * (single-level) and # (multi-level).

Summary

Functions

Check if topic matches pattern. Patterns can contain: - * matches exactly one segment - # matches zero or more segments

Extract namespace (first segment).

Normalize topic (lowercase, trim, remove double dots).

Count number of segments in topic.

Validate topic syntax. Valid topics: - Non-empty - Segments separated by dots - Segments contain alphanumeric, underscore, hyphen, wildcards - No leading or trailing dots

Types

pattern/0

-type pattern() :: binary().

topic/0

-type topic() :: binary().

Functions

matches(Topic, Pattern)

-spec matches(topic(), pattern()) -> boolean().

Check if topic matches pattern. Patterns can contain: - * matches exactly one segment - # matches zero or more segments

namespace(Topic)

-spec namespace(topic()) -> binary().

Extract namespace (first segment).

normalize(Topic)

-spec normalize(topic()) -> topic().

Normalize topic (lowercase, trim, remove double dots).

segment_count(Topic)

-spec segment_count(topic()) -> non_neg_integer().

Count number of segments in topic.

validate(Topic)

-spec validate(topic()) -> ok | {error, invalid_topic}.

Validate topic syntax. Valid topics: - Non-empty - Segments separated by dots - Segments contain alphanumeric, underscore, hyphen, wildcards - No leading or trailing dots