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
39 * This file contains definitions of the constants and packet formats
40 * defined in the binary specification. Please note that you _MUST_ remember
41 * to convert each multibyte field to / from network byte order to / from
50 * Definition of the legal "magic" values used in a packet.
51 * See section 3.1 Magic byte
54 PROTOCOL_BINARY_REQ
= 0x80,
55 PROTOCOL_BINARY_RES
= 0x81
56 } protocol_binary_magic
;
59 * Definition of the valid response status numbers.
60 * See section 3.2 Response Status
63 PROTOCOL_BINARY_RESPONSE_SUCCESS
= 0x00,
64 PROTOCOL_BINARY_RESPONSE_KEY_ENOENT
= 0x01,
65 PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS
= 0x02,
66 PROTOCOL_BINARY_RESPONSE_E2BIG
= 0x03,
67 PROTOCOL_BINARY_RESPONSE_EINVAL
= 0x04,
68 PROTOCOL_BINARY_RESPONSE_NOT_STORED
= 0x05,
69 PROTOCOL_BINARY_RESPONSE_DELTA_BADVAL
= 0x06,
70 PROTOCOL_BINARY_RESPONSE_AUTH_ERROR
= 0x20,
71 PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE
= 0x21,
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_CMD_TOUCH
= 0x1c,
109 PROTOCOL_BINARY_CMD_GAT
= 0x1d,
110 PROTOCOL_BINARY_CMD_GATQ
= 0x1e,
111 PROTOCOL_BINARY_CMD_GATK
= 0x23,
112 PROTOCOL_BINARY_CMD_GATKQ
= 0x24,
114 PROTOCOL_BINARY_CMD_SASL_LIST_MECHS
= 0x20,
115 PROTOCOL_BINARY_CMD_SASL_AUTH
= 0x21,
116 PROTOCOL_BINARY_CMD_SASL_STEP
= 0x22,
118 /* These commands are used for range operations and exist within
119 * this header for use in other projects. Range operations are
120 * not expected to be implemented in the memcached server itself.
122 PROTOCOL_BINARY_CMD_RGET
= 0x30,
123 PROTOCOL_BINARY_CMD_RSET
= 0x31,
124 PROTOCOL_BINARY_CMD_RSETQ
= 0x32,
125 PROTOCOL_BINARY_CMD_RAPPEND
= 0x33,
126 PROTOCOL_BINARY_CMD_RAPPENDQ
= 0x34,
127 PROTOCOL_BINARY_CMD_RPREPEND
= 0x35,
128 PROTOCOL_BINARY_CMD_RPREPENDQ
= 0x36,
129 PROTOCOL_BINARY_CMD_RDELETE
= 0x37,
130 PROTOCOL_BINARY_CMD_RDELETEQ
= 0x38,
131 PROTOCOL_BINARY_CMD_RINCR
= 0x39,
132 PROTOCOL_BINARY_CMD_RINCRQ
= 0x3a,
133 PROTOCOL_BINARY_CMD_RDECR
= 0x3b,
134 PROTOCOL_BINARY_CMD_RDECRQ
= 0x3c
135 /* End Range operations */
137 } protocol_binary_command
;
140 * Definition of the data types in the packet
141 * See section 3.4 Data Types
144 PROTOCOL_BINARY_RAW_BYTES
= 0x00
145 } protocol_binary_datatypes
;
148 * Definition of the header structure for a request packet.
164 } protocol_binary_request_header
;
167 * Definition of the header structure for a response packet.
183 } protocol_binary_response_header
;
186 * Definition of a request-packet containing no extras
190 protocol_binary_request_header header
;
192 uint8_t bytes
[sizeof(protocol_binary_request_header
)];
193 } protocol_binary_request_no_extras
;
196 * Definition of a response-packet containing no extras
200 protocol_binary_response_header header
;
202 uint8_t bytes
[sizeof(protocol_binary_response_header
)];
203 } protocol_binary_response_no_extras
;
206 * Definition of the packet used by the get, getq, getk and getkq command.
209 typedef protocol_binary_request_no_extras protocol_binary_request_get
;
210 typedef protocol_binary_request_no_extras protocol_binary_request_getq
;
211 typedef protocol_binary_request_no_extras protocol_binary_request_getk
;
212 typedef protocol_binary_request_no_extras protocol_binary_request_getkq
;
215 * Definition of the packet returned from a successful get, getq, getk and
221 protocol_binary_response_header header
;
226 uint8_t bytes
[sizeof(protocol_binary_response_header
) + 4];
227 } protocol_binary_response_get
;
229 typedef protocol_binary_response_get protocol_binary_response_getq
;
230 typedef protocol_binary_response_get protocol_binary_response_getk
;
231 typedef protocol_binary_response_get protocol_binary_response_getkq
;
234 * Definition of the packet used by the delete command
237 typedef protocol_binary_request_no_extras protocol_binary_request_delete
;
240 * Definition of the packet returned by the delete command
243 typedef protocol_binary_response_no_extras protocol_binary_response_delete
;
246 * Definition of the packet used by the flush command
248 * Please note that the expiration field is optional, so remember to see
249 * check the header.bodysize to see if it is present.
253 protocol_binary_request_header header
;
258 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 4];
259 } protocol_binary_request_flush
;
262 * Definition of the packet returned by the flush command
265 typedef protocol_binary_response_no_extras protocol_binary_response_flush
;
268 * Definition of the packet used by set, add and replace
273 protocol_binary_request_header header
;
279 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 8];
280 } protocol_binary_request_set
;
281 typedef protocol_binary_request_set protocol_binary_request_add
;
282 typedef protocol_binary_request_set protocol_binary_request_replace
;
285 * Definition of the packet returned by set, add and replace
288 typedef protocol_binary_response_no_extras protocol_binary_response_set
;
289 typedef protocol_binary_response_no_extras protocol_binary_response_add
;
290 typedef protocol_binary_response_no_extras protocol_binary_response_replace
;
293 * Definition of the noop packet
296 typedef protocol_binary_request_no_extras protocol_binary_request_noop
;
299 * Definition of the packet returned by the noop command
302 typedef protocol_binary_response_no_extras protocol_binary_response_noop
;
305 * Definition of the structure used by the increment and decrement
311 protocol_binary_request_header header
;
318 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 20];
319 } protocol_binary_request_incr
;
320 typedef protocol_binary_request_incr protocol_binary_request_decr
;
323 * Definition of the response from an incr or decr command
329 protocol_binary_response_header header
;
334 uint8_t bytes
[sizeof(protocol_binary_response_header
) + 8];
335 } protocol_binary_response_incr
;
336 typedef protocol_binary_response_incr protocol_binary_response_decr
;
339 * Definition of the quit
342 typedef protocol_binary_request_no_extras protocol_binary_request_quit
;
345 * Definition of the packet returned by the quit command
348 typedef protocol_binary_response_no_extras protocol_binary_response_quit
;
351 * Definition of the packet used by append and prepend command
354 typedef protocol_binary_request_no_extras protocol_binary_request_append
;
355 typedef protocol_binary_request_no_extras protocol_binary_request_prepend
;
358 * Definition of the packet returned from a successful append or prepend
361 typedef protocol_binary_response_no_extras protocol_binary_response_append
;
362 typedef protocol_binary_response_no_extras protocol_binary_response_prepend
;
365 * Definition of the packet used by the version command
368 typedef protocol_binary_request_no_extras protocol_binary_request_version
;
371 * Definition of the packet returned from a successful version command
374 typedef protocol_binary_response_no_extras protocol_binary_response_version
;
378 * Definition of the packet used by the stats command.
381 typedef protocol_binary_request_no_extras protocol_binary_request_stats
;
384 * Definition of the packet returned from a successful stats command
387 typedef protocol_binary_response_no_extras protocol_binary_response_stats
;
390 * Definition of the packet used by the touch command.
394 protocol_binary_request_header header
;
399 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 4];
400 } protocol_binary_request_touch
;
403 * Definition of the packet returned from the touch command
405 typedef protocol_binary_response_no_extras protocol_binary_response_touch
;
408 * Definition of the packet used by the GAT(Q) command.
412 protocol_binary_request_header header
;
417 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 4];
418 } protocol_binary_request_gat
;
420 typedef protocol_binary_request_gat protocol_binary_request_gatq
;
421 typedef protocol_binary_request_gat protocol_binary_request_gatk
;
422 typedef protocol_binary_request_gat protocol_binary_request_gatkq
;
425 * Definition of the packet returned from the GAT(Q)
427 typedef protocol_binary_response_get protocol_binary_response_gat
;
428 typedef protocol_binary_response_get protocol_binary_response_gatq
;
429 typedef protocol_binary_response_get protocol_binary_response_gatk
;
430 typedef protocol_binary_response_get protocol_binary_response_gatkq
;
433 * Definition of a request for a range operation.
434 * See http://code.google.com/p/memcached/wiki/RangeOps
436 * These types are used for range operations and exist within
437 * this header for use in other projects. Range operations are
438 * not expected to be implemented in the memcached server itself.
442 protocol_binary_response_header header
;
447 uint32_t max_results
;
450 uint8_t bytes
[sizeof(protocol_binary_request_header
) + 4];
451 } protocol_binary_request_rangeop
;
453 typedef protocol_binary_request_rangeop protocol_binary_request_rget
;
454 typedef protocol_binary_request_rangeop protocol_binary_request_rset
;
455 typedef protocol_binary_request_rangeop protocol_binary_request_rsetq
;
456 typedef protocol_binary_request_rangeop protocol_binary_request_rappend
;
457 typedef protocol_binary_request_rangeop protocol_binary_request_rappendq
;
458 typedef protocol_binary_request_rangeop protocol_binary_request_rprepend
;
459 typedef protocol_binary_request_rangeop protocol_binary_request_rprependq
;
460 typedef protocol_binary_request_rangeop protocol_binary_request_rdelete
;
461 typedef protocol_binary_request_rangeop protocol_binary_request_rdeleteq
;
462 typedef protocol_binary_request_rangeop protocol_binary_request_rincr
;
463 typedef protocol_binary_request_rangeop protocol_binary_request_rincrq
;
464 typedef protocol_binary_request_rangeop protocol_binary_request_rdecr
;
465 typedef protocol_binary_request_rangeop protocol_binary_request_rdecrq
;
470 #endif /* PROTOCOL_BINARY_H */