Search documentation of macula

# macula_pubsub_topic (macula v0.44.2)

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

## Types

pattern/0
topic/0

## Functions

matches(Topic, Pattern)

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

namespace(Topic)

Extract namespace (first segment).

normalize(Topic)

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

segment_count(Topic)

Count number of segments in topic.

validate(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