topic

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Overview

Package topic implements common methods to handle MQTT topics.

Index

Constants

This section is empty.

Variables

View Source
var ErrWildcards = errors.New("invalid use of wildcards")

ErrWildcards is returned by Parse if a topic contains invalid wildcards.

View Source
var ErrZeroLength = errors.New("zero length topic")

ErrZeroLength is returned by Parse if a topics has a zero length.

Functions

func ContainsWildcards

func ContainsWildcards(topic string) bool

ContainsWildcards tests if the supplied topic contains wildcards. The topic is expected to be tested and normalized using Parse beforehand.

func Parse

func Parse(topic string, allowWildcards bool) (string, error)

Parse removes duplicate and trailing slashes from the supplied string and returns the normalized topic.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

A Tree implements a thread-safe topic tree.

func NewStandardTree added in v0.13.0

func NewStandardTree() *Tree

NewStandardTree returns a new Tree using the standard MQTT separator and wildcards.

func NewTree

func NewTree(separator, wildcardOne, wildcardSome string) *Tree

NewTree returns a new Tree using the specified separator and wildcards.

func (*Tree) Add

func (t *Tree) Add(topic string, value interface{})

Add registers the value for the supplied topic. This function will automatically grow the tree. If value already exists for the given topic it will not be added again.

func (*Tree) All

func (t *Tree) All() []interface{}

All will return all stored values in the tree.

func (*Tree) Clear

func (t *Tree) Clear(value interface{})

Clear will unregister the supplied value from all topics. This function will automatically shrink the tree.

func (*Tree) Count

func (t *Tree) Count() int

Count will count all stored values in the tree. It will not filter out duplicate values and thus might return a different result to `len(All())`.

func (*Tree) Empty

func (t *Tree) Empty(topic string)

Empty will unregister all values from the supplied topic. This function will automatically shrink the tree.

func (*Tree) Get

func (t *Tree) Get(topic string) []interface{}

Get gets the values from the topic that exactly matches the supplied topics.

func (*Tree) Match

func (t *Tree) Match(topic string) []interface{}

Match will return a set of values from topics that match the supplied topic. The result set will be cleared from duplicate values.

Note: In contrast to Search, Match does not respect wildcards in the query but in the stored tree.

func (*Tree) MatchFirst

func (t *Tree) MatchFirst(topic string) interface{}

MatchFirst behaves similar to Match but only returns the first found value.

func (*Tree) Remove

func (t *Tree) Remove(topic string, value interface{})

Remove un-registers the value from the supplied topic. This function will automatically shrink the tree.

func (*Tree) Reset

func (t *Tree) Reset()

Reset will completely clear the tree.

func (*Tree) Search

func (t *Tree) Search(topic string) []interface{}

Search will return a set of values from topics that match the supplied topic. The result set will be cleared from duplicate values.

Note: In contrast to Match, Search respects wildcards in the query but not in the stored tree.

func (*Tree) SearchFirst

func (t *Tree) SearchFirst(topic string) interface{}

SearchFirst behaves similar to Search but only returns the first found value.

func (*Tree) Set

func (t *Tree) Set(topic string, value interface{})

Set sets the supplied value as the only value for the supplied topic. This function will automatically grow the tree.

func (*Tree) String

func (t *Tree) String() string

String will return a string representation of the tree structure. The number following the nodes show the number of stored values at that level.

Jump to

Keyboard shortcuts

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