/
types.go
121 lines (95 loc) · 3.66 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package topicsTypes
import (
"errors"
"regexp"
"github.com/VolantMQ/mqttp"
"github.com/VolantMQ/volantmq/types"
)
//var (
// // ErrUnknownProvider unknown provider
// ErrUnknownProvider = errors.New("Unknown provider")
//)
const (
// MWC is the multi-level wildcard
MWC = "#"
// SWC is the single level wildcard
SWC = "+"
// SEP is the topic level separator
//SEP = "/"
// SYS is the starting character of the system level topics
//SYS = "$"
// Both wildcards
//BWC = "#+"
)
var (
// TopicSubscribeRegexp regular expression that all subcriptions must be validated
TopicSubscribeRegexp = regexp.MustCompile(`^(([^+#]*|\+)(/([^+#]*|\+))*(/#)?|#)$`)
// TopicPublishRegexp regular expression that all publish to topic must be validated
TopicPublishRegexp = regexp.MustCompile(`^[^#+]*$`)
)
var (
//ErrInvalidConnectionType = errors.New("invalid connection type")
////ErrInvalidSubscriber error = errors.New("service: Invalid subscriber")
//ErrBufferNotReady = errors.New("buffer is not ready")
// ErrInvalidArgs invalid arguments provided
ErrInvalidArgs = errors.New("topics: invalid arguments")
// ErrUnexpectedObjectType invalid arguments provided
ErrUnexpectedObjectType = errors.New("topics: unexpected object type")
// ErrUnknownProvider if provider is unknown
ErrUnknownProvider = errors.New("topics: unknown provider")
// ErrAlreadyExists object already exists
ErrAlreadyExists = errors.New("topics: already exists")
// ErrNotFound object not found
ErrNotFound = errors.New("topics: not found")
// ErrNotOpen storage is not open
//ErrNotOpen = errors.New("not open")
//ErrOverflow = errors.New("overflow")
)
// Subscriber used inside each session as an object to provide to topic manager upon subscribe
type Subscriber interface {
Acquire()
Release()
Publish(*packet.Publish, packet.QosType, packet.SubscriptionOptions, []uint32) error
Hash() uintptr
}
// Subscribers used by topic manager to return list of subscribers matching topic
type Subscribers []Subscriber
// Provider interface
type Provider interface {
Subscribe(string, Subscriber, *SubscriptionParams) (packet.QosType, []*packet.Publish, error)
UnSubscribe(string, Subscriber) error
Publish(interface{}) error
Retain(types.RetainObject) error
Retained(string) ([]*packet.Publish, error)
Close() error
}
// SubscriberInterface used by subscriber to handle messages
type SubscriberInterface interface {
Publish(interface{}) error
Subscribe(string, Subscriber, *SubscriptionParams) (packet.QosType, []*packet.Publish, error)
UnSubscribe(string, Subscriber) error
Retain(types.RetainObject) error
Retained(string) ([]*packet.Publish, error)
}
// SubscriptionParams parameters of the subscription
type SubscriptionParams struct {
// Subscription id
// V5.0 ONLY
ID uint32
// Ops requested subscription options
Ops packet.SubscriptionOptions
// Granted QoS granted by topics manager
Granted packet.QosType
}
var (
// ErrMultiLevel multi-level wildcard
ErrMultiLevel = errors.New("multi-level wildcard found in topic and it's not at the last level")
// ErrInvalidSubscriber invalid subscriber object
ErrInvalidSubscriber = errors.New("subscriber cannot be nil")
// ErrInvalidWildcardPlus Wildcard character '+' must occupy entire topic level
ErrInvalidWildcardPlus = errors.New("wildcard character '+' must occupy entire topic level")
// ErrInvalidWildcardSharp Wildcard character '#' must occupy entire topic level
ErrInvalidWildcardSharp = errors.New("wildcard character '#' must occupy entire topic level")
// ErrInvalidWildcard Wildcard characters '#' and '+' must occupy entire topic level
ErrInvalidWildcard = errors.New("wildcard characters '#' and '+' must occupy entire topic level")
)