forked from dustin/gotap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_constants.go
126 lines (110 loc) · 2.34 KB
/
mc_constants.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
package mc_constants
import "fmt"
type HeaderMagic int
const (
REQ_MAGIC = 0x80
RES_MAGIC = 0x81
)
type CommandCode int
const (
GET = 0x00
SET = 0x01
ADD = 0x02
REPLACE = 0x03
DELETE = 0x04
INCREMENT = 0x05
DECREMENT = 0x06
QUIT = 0x07
FLUSH = 0x08
GETQ = 0x09
NOOP = 0x0a
VERSION = 0x0b
GETK = 0x0c
GETKQ = 0x0d
APPEND = 0x0e
PREPEND = 0x0f
STAT = 0x10
SETQ = 0x11
ADDQ = 0x12
REPLACEQ = 0x13
DELETEQ = 0x14
INCREMENTQ = 0x15
DECREMENTQ = 0x16
QUITQ = 0x17
FLUSHQ = 0x18
APPENDQ = 0x19
PREPENDQ = 0x1a
RGET = 0x30
RSET = 0x31
RSETQ = 0x32
RAPPEND = 0x33
RAPPENDQ = 0x34
RPREPEND = 0x35
RPREPENDQ = 0x36
RDELETE = 0x37
RDELETEQ = 0x38
RINCR = 0x39
RINCRQ = 0x3a
RDECR = 0x3b
RDECRQ = 0x3c
TAP_CONNECT = 0x40
TAP_MUTATION = 0x41
TAP_DELETE = 0x42
TAP_FLUSH = 0x43
TAP_OPAQUE = 0x44
TAP_VBUCKET_SET = 0x45
TAP_CHECKPOINT_START = 0x46
TAP_CHECKPOINT_END = 0x47
)
type TapFlags uint32
const (
BACKFILL = 0x01
DUMP = 0x02
LIST_VBUCKETS = 0x04
TAKEOVER_VBUCKETS = 0x08
SUPPORT_ACK = 0x10
REQUEST_KEYS_ONLY = 0x20
CHECKPOINT = 0x40
REGISTERED_CLIENT = 0x80
)
type ResponseStatus int
const (
SUCCESS = 0x00
KEY_ENOENT = 0x01
KEY_EEXISTS = 0x02
E2BIG = 0x03
EINVAL = 0x04
NOT_STORED = 0x05
DELTA_BADVAL = 0x06
UNKNOWN_COMMAND = 0x81
ENOMEM = 0x82
)
type MCRequest struct {
Opcode uint8
Cas uint64
Opaque uint32
VBucket uint16
Extras, Key, Body []byte
ResponseChannel chan MCResponse
}
func (req MCRequest) String() string {
return fmt.Sprintf("{MCRequest opcode=%x, key='%s'}",
req.Opcode, req.Key)
}
type MCResponse struct {
OpCode uint8
Status uint16
Cas uint64
Extras, Key, Body []byte
Fatal bool
}
func (res MCResponse) String() string {
return fmt.Sprintf("{MCResponse status=%x keylen=%d, extralen=%d, bodylen=%d}",
res.Status, len(res.Key), len(res.Extras), len(res.Body))
}
type MCItem struct {
Cas uint64
Flags, Expiration uint32
Data []byte
}
const HDR_LEN = 24