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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165// Copyright 2016 Péter Szilágyi. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package deepstream
const (
// messageSeparator is the control character separating individual messages in
// the textual wire protocol.
messageSeparator = byte(30)
// messagePartSeparator is the control character separating individual parts of
// a single message in the textual wire protocol.
messagePartSeparator = byte(31)
)
// connectionState represents the current state of a connection.
type connectionState int
const ()
type topic int
func (t topic) String() string {
return string(topicLabels[t])
}
const (
topicConnection topic = iota
topicAuth
topicError
topicEvent
topicRecord
topicRPC
topicPrivate
)
// topicLabels contains the textual representation of different topics in the
// underlying wire protocol.
var topicLabels = map[topic][]byte{
topicConnection: []byte("C"),
topicAuth: []byte("A"),
topicError: []byte("X"),
topicEvent: []byte("E"),
topicRecord: []byte("R"),
topicRPC: []byte("P"),
topicPrivate: []byte("PRIVATE/"),
}
type action int
func (a action) String() string {
return string(actionLabels[a])
}
const (
actionAck action = iota
actionRead
actionRedirect
actionChallenge
actionChallengeResponse
actionPing
actionPong
actionCreate
actionUpdate
actionPatch
actionDelete
actionSubscribe
actionUnsubscribe
actionHas
actionSnapshot
actionListen
actionUnlisten
actionListenAccept
actionListenReject
actionSubscriptionHasProvider
actionProviderUpdate
actionQuery
actionCreateorread
actionEvent
actionError
actionRequest
actionResponse
actionRejection
)
// actionLabels contains the textual representation of different actions in the
// underlying wire protocol.
var actionLabels = map[action][]byte{
actionAck: []byte("A"),
actionRead: []byte("R"),
actionRedirect: []byte("RED"),
actionChallenge: []byte("CH"),
actionChallengeResponse: []byte("CHR"),
actionPing: []byte("PI"),
actionPong: []byte("PO"),
actionCreate: []byte("C"),
actionUpdate: []byte("U"),
actionPatch: []byte("P"),
actionDelete: []byte("D"),
actionSubscribe: []byte("S"),
actionUnsubscribe: []byte("US"),
actionHas: []byte("H"),
actionSnapshot: []byte("SN"),
actionListen: []byte("L"),
actionUnlisten: []byte("UL"),
actionListenAccept: []byte("LA"),
actionListenReject: []byte("LR"),
actionSubscriptionHasProvider: []byte("SH"),
actionProviderUpdate: []byte("PU"),
actionQuery: []byte("Q"),
actionCreateorread: []byte("CR"),
actionEvent: []byte("EVT"),
actionError: []byte("E"),
actionRequest: []byte("REQ"),
actionResponse: []byte("RES"),
actionRejection: []byte("REJ"),
}
type kind int
func (k kind) String() string {
return string(kindLabels[k])
}
const (
kindString kind = iota
kindObject
kindNumber
kindNull
kindTrue
kindFalse
kindUndefined
)
// actionLabels contains the textual representation of different kinds in the
// underlying wire protocol.
var kindLabels = map[kind][]byte{
kindString: []byte("S"),
kindObject: []byte("O"),
kindNumber: []byte("N"),
kindNull: []byte("L"),
kindTrue: []byte("T"),
kindFalse: []byte("F"),
kindUndefined: []byte("U"),
}
var (
topicMapping = make(map[string]topic)
actionMapping = make(map[string]action)
kindMapping = make(map[string]kind)
)
func init() {
for topic, label := range topicLabels {
topicMapping[string(label)] = topic
}
for action, label := range actionLabels {
actionMapping[string(label)] = action
}
for kind, label := range kindLabels {
kindMapping[string(label)] = kind
}
}