2
* Copyright (c) <2008>, Sun Microsystems, Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
* * Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* * Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* * Neither the name of the nor the
13
* names of its contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ``AS IS'' AND ANY
17
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
* DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
20
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
* Summary: Constants used by to implement the binary protocol.
30
* Copy: See Copyright for the status of this software.
32
* Author: Trond Norbye <trond.norbye@sun.com>
35
#ifndef PROTOCOL_BINARY_H
36
#define PROTOCOL_BINARY_H
41
* This file contains definitions of the constants and packet formats
42
* defined in the binary specification. Please note that you _MUST_ remember
43
* to convert each multibyte field to / from network byte order to / from
52
* Definition of the legal "magic" values used in a packet.
53
* See section 3.1 Magic byte
56
PROTOCOL_BINARY_REQ = 0x80,
57
PROTOCOL_BINARY_RES = 0x81
58
} protocol_binary_magic;
61
* Definition of the valid response status numbers.
62
* See section 3.2 Response Status
65
PROTOCOL_BINARY_RESPONSE_SUCCESS = 0x00,
66
PROTOCOL_BINARY_RESPONSE_KEY_ENOENT = 0x01,
67
PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS = 0x02,
68
PROTOCOL_BINARY_RESPONSE_E2BIG = 0x03,
69
PROTOCOL_BINARY_RESPONSE_EINVAL = 0x04,
70
PROTOCOL_BINARY_RESPONSE_NOT_STORED = 0x05,
71
PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL = 0x06,
72
PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND = 0x81,
73
PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82
74
} protocol_binary_response_status;
77
* Defintion of the different command opcodes.
78
* See section 3.3 Command Opcodes
81
PROTOCOL_BINARY_CMD_GET = 0x00,
82
PROTOCOL_BINARY_CMD_SET = 0x01,
83
PROTOCOL_BINARY_CMD_ADD = 0x02,
84
PROTOCOL_BINARY_CMD_REPLACE = 0x03,
85
PROTOCOL_BINARY_CMD_DELETE = 0x04,
86
PROTOCOL_BINARY_CMD_INCREMENT = 0x05,
87
PROTOCOL_BINARY_CMD_DECREMENT = 0x06,
88
PROTOCOL_BINARY_CMD_QUIT = 0x07,
89
PROTOCOL_BINARY_CMD_FLUSH = 0x08,
90
PROTOCOL_BINARY_CMD_GETQ = 0x09,
91
PROTOCOL_BINARY_CMD_NOOP = 0x0a,
92
PROTOCOL_BINARY_CMD_VERSION = 0x0b,
93
PROTOCOL_BINARY_CMD_GETK = 0x0c,
94
PROTOCOL_BINARY_CMD_GETKQ = 0x0d,
95
PROTOCOL_BINARY_CMD_APPEND = 0x0e,
96
PROTOCOL_BINARY_CMD_PREPEND = 0x0f,
97
PROTOCOL_BINARY_CMD_STAT = 0x10,
98
PROTOCOL_BINARY_CMD_SETQ = 0x11,
99
PROTOCOL_BINARY_CMD_ADDQ = 0x12,
100
PROTOCOL_BINARY_CMD_REPLACEQ = 0x13,
101
PROTOCOL_BINARY_CMD_DELETEQ = 0x14,
102
PROTOCOL_BINARY_CMD_INCREMENTQ = 0x15,
103
PROTOCOL_BINARY_CMD_DECREMENTQ = 0x16,
104
PROTOCOL_BINARY_CMD_QUITQ = 0x17,
105
PROTOCOL_BINARY_CMD_FLUSHQ = 0x18,
106
PROTOCOL_BINARY_CMD_APPENDQ = 0x19,
107
PROTOCOL_BINARY_CMD_PREPENDQ = 0x1a
108
} protocol_binary_command;
111
* Definition of the data types in the packet
112
* See section 3.4 Data Types
115
PROTOCOL_BINARY_RAW_BYTES = 0x00
116
} protocol_binary_datatypes;
119
* Definition of the header structure for a request packet.
135
} protocol_binary_request_header;
138
* Definition of the header structure for a response packet.
154
} protocol_binary_response_header;
157
* Definition of a request-packet containing no extras
161
protocol_binary_request_header header;
163
uint8_t bytes[sizeof(protocol_binary_request_header)];
164
} protocol_binary_request_no_extras;
167
* Definition of a response-packet containing no extras
171
protocol_binary_response_header header;
173
uint8_t bytes[sizeof(protocol_binary_response_header)];
174
} protocol_binary_response_no_extras;
177
* Definition of the packet used by the get, getq, getk and getkq command.
180
typedef protocol_binary_request_no_extras protocol_binary_request_get;
181
typedef protocol_binary_request_no_extras protocol_binary_request_getq;
182
typedef protocol_binary_request_no_extras protocol_binary_request_getk;
183
typedef protocol_binary_request_no_extras protocol_binary_request_getkq;
186
* Definition of the packet returned from a successful get, getq, getk and
192
protocol_binary_response_header header;
197
uint8_t bytes[sizeof(protocol_binary_response_header) + 4];
198
} protocol_binary_response_get;
200
typedef protocol_binary_response_get protocol_binary_response_getq;
201
typedef protocol_binary_response_get protocol_binary_response_getk;
202
typedef protocol_binary_response_get protocol_binary_response_getkq;
205
* Definition of the packet used by the delete command
208
typedef protocol_binary_request_no_extras protocol_binary_request_delete;
211
* Definition of the packet returned by the delete command
214
typedef protocol_binary_response_no_extras protocol_binary_response_delete;
217
* Definition of the packet used by the flush command
219
* Please note that the expiration field is optional, so remember to see
220
* check the header.bodysize to see if it is present.
224
protocol_binary_request_header header;
229
uint8_t bytes[sizeof(protocol_binary_request_header) + 4];
230
} protocol_binary_request_flush;
233
* Definition of the packet returned by the flush command
236
typedef protocol_binary_response_no_extras protocol_binary_response_flush;
239
* Definition of the packet used by set, add and replace
244
protocol_binary_request_header header;
250
uint8_t bytes[sizeof(protocol_binary_request_header) + 8];
251
} protocol_binary_request_set;
252
typedef protocol_binary_request_set protocol_binary_request_add;
253
typedef protocol_binary_request_set protocol_binary_request_replace;
256
* Definition of the packet returned by set, add and replace
259
typedef protocol_binary_response_no_extras protocol_binary_response_set;
260
typedef protocol_binary_response_no_extras protocol_binary_response_add;
261
typedef protocol_binary_response_no_extras protocol_binary_response_replace;
264
* Definition of the noop packet
267
typedef protocol_binary_request_no_extras protocol_binary_request_noop;
270
* Definition of the packet returned by the noop command
273
typedef protocol_binary_response_no_extras protocol_binary_response_noop;
276
* Definition of the structure used by the increment and decrement
282
protocol_binary_request_header header;
289
uint8_t bytes[sizeof(protocol_binary_request_header) + 20];
290
} protocol_binary_request_incr;
291
typedef protocol_binary_request_incr protocol_binary_request_decr;
294
* Definition of the response from an incr or decr command
300
protocol_binary_response_header header;
305
uint8_t bytes[sizeof(protocol_binary_response_header) + 8];
306
} protocol_binary_response_incr;
307
typedef protocol_binary_response_incr protocol_binary_response_decr;
310
* Definition of the quit
313
typedef protocol_binary_request_no_extras protocol_binary_request_quit;
316
* Definition of the packet returned by the quit command
319
typedef protocol_binary_response_no_extras protocol_binary_response_quit;
322
* Definition of the packet used by append and prepend command
325
typedef protocol_binary_request_no_extras protocol_binary_request_append;
326
typedef protocol_binary_request_no_extras protocol_binary_request_prepend;
329
* Definition of the packet returned from a successful append or prepend
332
typedef protocol_binary_response_no_extras protocol_binary_response_append;
333
typedef protocol_binary_response_no_extras protocol_binary_response_prepend;
336
* Definition of the packet used by the version command
339
typedef protocol_binary_request_no_extras protocol_binary_request_version;
342
* Definition of the packet returned from a successful version command
345
typedef protocol_binary_response_no_extras protocol_binary_response_version;
349
* Definition of the packet used by the stats command.
352
typedef protocol_binary_request_no_extras protocol_binary_request_stats;
355
* Definition of the packet returned from a successful stats command
358
typedef protocol_binary_response_no_extras protocol_binary_response_stats;
362
#endif /* PROTOCOL_BINARY_H */