topics

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2022 License: EPL-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package topics contains tools related to MQTT-SN topics handling.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PredefinedTopics

type PredefinedTopics map[string]map[uint16]string

PredefinedTopics implements a map of MQTT-SN predefined topics. It maps clientID -> (topicID -> topicName).

func ParsePredefinedTopicOptions

func ParsePredefinedTopicOptions(options ...string) (PredefinedTopics, error)

ParsePredefinedTopicOptions parses a command line predefined topics definition in "client_id;topic;topic_id" format.

Example
option1 := "*;test/topic1;1"
option2 := "client;test/topic2;2"

topics, _ := ParsePredefinedTopicOptions(option1, option2)

fmt.Println(topics)
Output:

map[*:map[1:test/topic1] client:map[2:test/topic2]]

func ReadPredefinedTopicsFile

func ReadPredefinedTopicsFile(file string) (PredefinedTopics, error)

ReadPredefinedTopicsFile reads a predefined topics definition file in YAML format.

Example
f, _ := ioutil.TempFile("/tmp", "example_predefined_topics.yaml")
defer os.Remove(f.Name())

f.Write([]byte(`
"*":
  1: any/topic1
  2: any/topic2
client1:
  3: client1/topic1
  4: client1/topic2`))
f.Close()

topics, _ := ReadPredefinedTopicsFile(f.Name())
fmt.Println(topics)
Output:

map[*:map[1:any/topic1 2:any/topic2] client1:map[3:client1/topic1 4:client1/topic2]]

func (PredefinedTopics) Add

func (t PredefinedTopics) Add(clientID, topicName string, topicID uint16)

Add adds a new predefined topic to the map.

func (PredefinedTopics) GetTopicID

func (t PredefinedTopics) GetTopicID(clientID, topic string) (uint16, bool)

GetTopicID returns a topic ID for the given clientID and topic.

func (PredefinedTopics) GetTopicName

func (t PredefinedTopics) GetTopicName(clientID string, topicID uint16) (string, bool)

GetTopicName returns a topic name for the given clientID and topicID.

func (PredefinedTopics) Merge

func (t PredefinedTopics) Merge(src PredefinedTopics)

Merge merges another predefined topics map in. If there are collisions, the given map (src) values take precedence.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL