SimpleMqtt.Topics (simple_mqtt v0.1.0) View Source

Link to this section Summary

Functions

Checks whether the published topic matches the subscribed topic.

Parses topic for published message.

Parses filter for subscribed topics.

Link to this section Types

Specs

published_topic() :: [String.t()]

Specs

subscribed_topic() :: [String.t()]

Link to this section Functions

Specs

Checks whether the published topic matches the subscribed topic.

Examples

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "switch_1", "on"]) true

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "switch_1", "off"]) false

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "+", "on"]) true

iex> SimpleMqtt.Topics.matches?(["things", "a", "on"], ["things", "a", "+"]) true

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "+", "off"]) false

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "switch_1", "#"]) true

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["things", "#"]) true

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["#"]) true

iex> SimpleMqtt.Topics.matches?(["things", "switch_1", "on"], ["devices", "#"]) false

Link to this function

parse_published_topic(topic)

View Source

Specs

parse_published_topic(String.t()) :: {:ok, published_topic()} | :error

Parses topic for published message.

Examples

iex> SimpleMqtt.Topics.parse_published_topic("things/switch_1/on")

iex> SimpleMqtt.Topics.parse_published_topic("/things/switch_1/on")

iex> SimpleMqtt.Topics.parse_published_topic("") :error

iex> SimpleMqtt.Topics.parse_published_topic("/+") :error

Link to this function

parse_subscribed_topic(topic)

View Source

Specs

parse_subscribed_topic(String.t()) :: {:ok, subscribed_topic()} | :error

Parses filter for subscribed topics.

Examples

iex> SimpleMqtt.Topics.parse_subscribed_topic("things/switch_1/on")

iex> SimpleMqtt.Topics.parse_subscribed_topic("/things/switch_1/on")

iex> SimpleMqtt.Topics.parse_subscribed_topic("") :error

iex> SimpleMqtt.Topics.parse_subscribed_topic("+")

iex> SimpleMqtt.Topics.parse_subscribed_topic("+/switch_1/on")

iex> SimpleMqtt.Topics.parse_subscribed_topic("switch_1/+/on")

iex> SimpleMqtt.Topics.parse_subscribed_topic("things/#")

iex> SimpleMqtt.Topics.parse_subscribed_topic("#")

iex> SimpleMqtt.Topics.parse_subscribed_topic("#/switch_1/on") :error