Documentation ¶
Overview ¶
Package topic implements common methods to handle MQTT topics.
Index ¶
- Variables
- func ContainsWildcards(topic string) bool
- func Parse(topic string, allowWildcards bool) (string, error)
- type Tree
- func (t *Tree) Add(topic string, value interface{})
- func (t *Tree) All() []interface{}
- func (t *Tree) Clear(value interface{})
- func (t *Tree) Count() int
- func (t *Tree) Empty(topic string)
- func (t *Tree) Get(topic string) []interface{}
- func (t *Tree) Match(topic string) []interface{}
- func (t *Tree) MatchFirst(topic string) interface{}
- func (t *Tree) Remove(topic string, value interface{})
- func (t *Tree) Reset()
- func (t *Tree) Search(topic string) []interface{}
- func (t *Tree) SearchFirst(topic string) interface{}
- func (t *Tree) Set(topic string, value interface{})
- func (t *Tree) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrWildcards = errors.New("invalid use of wildcards")
ErrWildcards is returned by Parse if a topic contains invalid wildcards.
var ErrZeroLength = errors.New("zero length topic")
ErrZeroLength is returned by Parse if a topics has a zero length.
Functions ¶
func ContainsWildcards ¶
ContainsWildcards tests if the supplied topic contains wildcards. The topics is expected to be tested and normalized using Parse beforehand.
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 (*Tree) Add ¶
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 ¶
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 ¶
Empty will unregister all values from the supplied topic. This function will automatically shrink the tree.
func (*Tree) Match ¶
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 ¶
MatchFirst will run Match and return the first value or nil.
func (*Tree) Remove ¶
Remove un-registers the value from the supplied topic. This function will automatically shrink the tree.
func (*Tree) Search ¶
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 ¶
SearchFirst will run Search and return the first value or nil.