forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codes.go
373 lines (324 loc) · 10.5 KB
/
codes.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package memcache
// Types including Stringer interface implementation and constants for common
// codes.
// Memcache Command Classification
type commandTypeCode uint8
const (
memcacheUnknownType commandTypeCode = iota
memcacheLoadMsg
memcacheStoreMsg
memcacheDeleteMsg
memcacheCounterMsg
memcacheInfoMsg
memcacheSlabCtrlMsg
memcacheLruCrawlerMsg
memcacheStatsMsg
memcacheSuccessResp
memcacheFailResp
memcacheAuthMsg
)
var commandTypeCodeStrings = []string{
"UNKNOWN",
"Load",
"Store",
"Delete",
"Counter",
"Info",
"SlabCtrl",
"LRUCrawler",
"Stats",
"Success",
"Fail",
"Auth",
}
// commandCode defines shared text and binary protocol message type codes.
type commandCode uint8
const (
memcacheCmdUNKNOWN commandCode = iota
memcacheCmdNoOp
memcacheCmdSet
memcacheCmdAdd
memcacheCmdReplace
memcacheCmdAppend
memcacheCmdPrepend
memcacheCmdCas
memcacheCmdGet
memcacheCmdGets
memcacheCmdIncr
memcacheCmdDecr
memcacheResCounterOp
memcacheCmdTouch
memcacheCmdDelete
memcacheCmdSlabs
memcacheCmdSlabsReassign
memcacheCmdSlabsAutomove
memcacheCmdLru
memcacheCmdLruEnable
memcacheCmdLruDisable
memcacheCmdLruSleep
memcacheCmdLruToCrawl
memcacheCmdLruCrawl
memcacheCmdStats
memcacheResStat
memcacheCmdFlushAll
memcacheCmdVerbosity
memcacheCmdQuit
memcacheCmdVersion
memcacheCmdSaslList
memcacheCmdSaslAuth
memcacheCmdSaslStep
memcacheResOK
memcacheResValue
memcacheResEnd
memcacheResStored
memcacheResNotStored
memcacheResExists
memcacheResNotFound
memcacheResTouched
memcacheResDeleted
memcacheErrError
memcacheErrClientError
memcacheErrServerError
memcacheErrBusy
memcacheErrBadClass
memcacheErrNoSpare
memcacheErrNotFull
memcacheErrUnsafe
memcacheErrSame
memcacheResVersion
)
var commandCodeStrings = []string{
"UNKNOWN",
"noop",
"set",
"add",
"replace",
"append",
"prepend",
"cas",
"get",
"gets",
"incr",
"decr",
"<counter_op_res>",
"touch",
"delete",
"slabs",
"slabs reassign",
"slabs automove",
"lru_crawler",
"lru_crawler enable",
"lru_crawler disable",
"lru_crawler sleep",
"lru_crawler tocrawl",
"lru_crawler crawl",
"stats",
"STAT",
"flush_all",
"verbosity",
"quit",
"version",
"sasl_list",
"sasl_auth",
"sasl_step",
"OK",
"VALUE",
"END",
"STORED",
"NOT_STORED",
"EXISTS",
"NOT_FOUND",
"TOCHED",
"DELETED",
"ERROR",
"CLIENT_ERROR",
"SERVER_ERROR",
"BUSY",
"BADCLASS",
"NOSPARE",
"NOTFULL",
"UNSAFE",
"SAME",
"VERSION",
}
// memcacheOpcode stores memcache binary protocol opcodes.
type memcacheOpcode uint8
const (
opcodeGet memcacheOpcode = 0x00
opcodeSet memcacheOpcode = 0x01
opcodeAdd memcacheOpcode = 0x02
opcodeReplace memcacheOpcode = 0x03
opcodeDelete memcacheOpcode = 0x04
opcodeIncrement memcacheOpcode = 0x05
opcodeDecrement memcacheOpcode = 0x06
opcodeQuit memcacheOpcode = 0x07
opcodeFlush memcacheOpcode = 0x08
opcodeGetQ memcacheOpcode = 0x09
opcodeNoOp memcacheOpcode = 0x0a
opcodeVersion memcacheOpcode = 0x0b
opcodeGetK memcacheOpcode = 0x0c
opcodeGetKQ memcacheOpcode = 0x0d
opcodeAppend memcacheOpcode = 0x0e
opcodePrepend memcacheOpcode = 0x0f
opcodeStat memcacheOpcode = 0x10
opcodeSetQ memcacheOpcode = 0x11
opcodeAddQ memcacheOpcode = 0x12
opcodeReplaceQ memcacheOpcode = 0x13
opcodeDeleteQ memcacheOpcode = 0x14
opcodeIncrementQ memcacheOpcode = 0x15
opcodeDecrementQ memcacheOpcode = 0x16
opcodeQuitQ memcacheOpcode = 0x17
opcodeFlushQ memcacheOpcode = 0x18
opcodeAppendQ memcacheOpcode = 0x19
opcodePrependQ memcacheOpcode = 0x1a
opcodeVerbosity memcacheOpcode = 0x1b // not in memcached source
opcodeTouch memcacheOpcode = 0x1c
opcodeGat memcacheOpcode = 0x1d
opcodeGatQ memcacheOpcode = 0x1e
opcodeSaslListMechs memcacheOpcode = 0x20
opcodeSaslAuth memcacheOpcode = 0x21
opcodeSaslStep memcacheOpcode = 0x22
opcodeGatK memcacheOpcode = 0x23
opcodeGatKQ memcacheOpcode = 0x24
opcodeRGet memcacheOpcode = 0x30 // range op not supported by memcached?
opcodeRSet memcacheOpcode = 0x31 // range op not supported by memcached?
opcodeRSetQ memcacheOpcode = 0x32 // range op not supported by memcached?
opcodeRAppend memcacheOpcode = 0x33 // range op not supported by memcached?
opcodeRAppendQ memcacheOpcode = 0x34 // range op not supported by memcached?
opcodeRPrepend memcacheOpcode = 0x35 // range op not supported by memcached?
opcodeRPrependQ memcacheOpcode = 0x36 // range op not supported by memcached?
opcodeRDelete memcacheOpcode = 0x37 // range op not supported by memcached?
opcodeRDeleteQ memcacheOpcode = 0x38 // range op not supported by memcached?
opcodeRIncr memcacheOpcode = 0x39 // range op not supported by memcached
opcodeRIncrQ memcacheOpcode = 0x3a // range op not supported by memcached?
opcodeRDecr memcacheOpcode = 0x3b // range op not supported by memcached?
opcodeRDecrQ memcacheOpcode = 0x3c // range op not supported by memcached?
/* These codes have been found on wiki only:
* https://code.google.com/p/memcached/wiki/BinaryProtocolRevamped
*
* But no reference in source code
*/
opcodeSetVBucket memcacheOpcode = 0x3d
opcodeGetVBucket memcacheOpcode = 0x3e
opcodeDelVBucket memcacheOpcode = 0x3f
opcodeTapConnect memcacheOpcode = 0x40
opcodeTapMutation memcacheOpcode = 0x41
opcodeTapDelete memcacheOpcode = 0x42
opcodeTapFlush memcacheOpcode = 0x43
opcodeTapOpaque memcacheOpcode = 0x44
opcodeTapVBucketSet memcacheOpcode = 0x45
opcodeTapCheckpointStart memcacheOpcode = 0x46
opcodeTapCheckpointEnd memcacheOpcode = 0x47
)
var opcodeNames = map[memcacheOpcode]string{
opcodeGet: "Get",
opcodeSet: "Set",
opcodeAdd: "Add",
opcodeReplace: "Replace",
opcodeDelete: "Delete",
opcodeIncrement: "Increment",
opcodeDecrement: "Decrement",
opcodeQuit: "Quit",
opcodeFlush: "Flush",
opcodeGetQ: "GetQ",
opcodeNoOp: "No-op",
opcodeVersion: "Version",
opcodeGetK: "GetK",
opcodeGetKQ: "GetKQ",
opcodeAppend: "Append",
opcodePrepend: "Prepend",
opcodeStat: "Stat",
opcodeSetQ: "SetQ",
opcodeAddQ: "AddQ",
opcodeReplaceQ: "ReplaceQ",
opcodeDeleteQ: "DeleteQ",
opcodeIncrementQ: "IncrementQ",
opcodeDecrementQ: "DecrementQ",
opcodeQuitQ: "QuitQ",
opcodeFlushQ: "FlushQ",
opcodeAppendQ: "AppendQ",
opcodePrependQ: "PrependQ",
opcodeVerbosity: "Verbosity",
opcodeTouch: "Touch",
opcodeGat: "GAT",
opcodeGatQ: "GATQ",
opcodeSaslListMechs: "SASL list mechs",
opcodeSaslAuth: "SASL Auth",
opcodeSaslStep: "SASL Step",
opcodeGatK: "GatK",
opcodeGatKQ: "GatKQ",
opcodeRGet: "RGet",
opcodeRSet: "RSet",
opcodeRSetQ: "RSetQ",
opcodeRAppend: "RAppend",
opcodeRAppendQ: "RAppendQ",
opcodeRPrepend: "RPrepend",
opcodeRPrependQ: "RPrependQ",
opcodeRDelete: "RDelete",
opcodeRDeleteQ: "RDeleteQ",
opcodeRIncr: "RIncr",
opcodeRIncrQ: "RIncrQ",
opcodeRDecr: "RDecr",
opcodeRDecrQ: "RDecrQ",
opcodeSetVBucket: "Set VBucket",
opcodeGetVBucket: "Get VBucket",
opcodeDelVBucket: "Del VBucket",
opcodeTapConnect: "TAP Connect",
opcodeTapMutation: "TAP Mutation",
opcodeTapDelete: "TAP Delete",
opcodeTapFlush: "TAP Flush",
opcodeTapOpaque: "TAP Opaque",
opcodeTapVBucketSet: "TAP VBucket Set",
opcodeTapCheckpointStart: "TAP Checkpoint Start",
opcodeTapCheckpointEnd: "TAP Checkpoint End",
}
type memcacheStatusCode uint16
const (
statusCodeNoError memcacheStatusCode = 0x00
statusCodeKeyNotFound memcacheStatusCode = 0x01
statusCodeKeyExists memcacheStatusCode = 0x02
statusCodeValueTooLarge memcacheStatusCode = 0x03
statusCodeInvalidArguments memcacheStatusCode = 0x04
statusCodeItemNotStored memcacheStatusCode = 0x05
statusCodeIncrDecrOnNonNumericValue memcacheStatusCode = 0x06
statusCodeVbucketBelongsToAnotherServer memcacheStatusCode = 0x07
statusCodeAuthenticationError memcacheStatusCode = 0x20 // doc says 0x08, but memcached headers say 0x20
statusCodeAuthenticationContinue memcacheStatusCode = 0x21 // doc says 0x09, but memcached headers say 0x21
// error codes
statusCodeUnknownCommand memcacheStatusCode = 0x81
statusCodeOutOfMemory memcacheStatusCode = 0x82
statusCodeNotSupported memcacheStatusCode = 0x83
statusCodeInternalError memcacheStatusCode = 0x84
statusCodeBusy memcacheStatusCode = 0x85
statusCodeTemporaryFailure memcacheStatusCode = 0x86
)
var statusCodeNames = map[memcacheStatusCode]string{
statusCodeNoError: "Success",
statusCodeKeyNotFound: "Key not found",
statusCodeKeyExists: "Key exists",
statusCodeValueTooLarge: "Value too large",
statusCodeInvalidArguments: "Invalid arguments",
statusCodeItemNotStored: "Item not stored",
statusCodeIncrDecrOnNonNumericValue: "Incr/Decr on non-numeric value.",
statusCodeVbucketBelongsToAnotherServer: "The vbucket belongs to another server",
statusCodeAuthenticationError: "Authentication error",
statusCodeAuthenticationContinue: "Authentication continue",
statusCodeUnknownCommand: "Unknown command",
statusCodeOutOfMemory: "Out of memory",
statusCodeNotSupported: "Not supported",
statusCodeInternalError: "Internal error",
statusCodeBusy: "Busy",
statusCodeTemporaryFailure: "Temporary failure",
}
func (c commandTypeCode) String() string {
return commandTypeCodeStrings[c]
}
func (c commandCode) String() string {
return commandCodeStrings[c]
}
func (c memcacheOpcode) String() string {
return opcodeNames[c]
}
func (c memcacheStatusCode) String() string {
return statusCodeNames[c]
}