topic

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2018 License: Apache-2.0 Imports: 5 Imported by: 12

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 topics 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 {
	// The separator character. Default: "/"
	Separator string

	// The single level wildcard character. Default: "+"
	WildcardOne string

	// The multi level wildcard character. Default "#"
	WildcardSome string
	// contains filtered or unexported fields
}

A Tree implements a thread-safe topic tree.

func NewTree

func NewTree() *Tree

NewTree returns a new Tree.

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 will run Match and return the first value or nil.

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 will run Search and return the first value or nil.

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.

Jump to

Keyboard shortcuts

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