20 #include <aerospike/as_buffer.h>
27 #include <citrusleaf/cf_byte_order.h>
28 #include <citrusleaf/cf_digest.h>
39 #define AS_FIELD_NAMESPACE 0
40 #define AS_FIELD_SETNAME 1
41 #define AS_FIELD_KEY 2
42 #define AS_FIELD_DIGEST 4
43 #define AS_FIELD_DIGEST_ARRAY 6
44 #define AS_FIELD_TASK_ID 7
45 #define AS_FIELD_SCAN_OPTIONS 8
46 #define AS_FIELD_SCAN_TIMEOUT 9
47 #define AS_FIELD_INDEX_RANGE 22
48 #define AS_FIELD_INDEX_FILTER 23
49 #define AS_FIELD_INDEX_LIMIT 24
50 #define AS_FIELD_INDEX_ORDER 25
51 #define AS_FIELD_INDEX_TYPE 26
52 #define AS_FIELD_UDF_PACKAGE_NAME 30
53 #define AS_FIELD_UDF_FUNCTION 31
54 #define AS_FIELD_UDF_ARGLIST 32
55 #define AS_FIELD_UDF_OP 33
56 #define AS_FIELD_QUERY_BINS 40
57 #define AS_FIELD_BATCH_INDEX 41
58 #define AS_FIELD_BATCH_INDEX_WITH_SET 42
59 #define AS_FIELD_PREDEXP 43
62 #define AS_MSG_INFO1_READ (1 << 0) // contains a read operation
63 #define AS_MSG_INFO1_GET_ALL (1 << 1) // get all bins, period
65 #define AS_MSG_INFO1_BATCH_INDEX (1 << 3) // batch read
66 #define AS_MSG_INFO1_XDR (1 << 4) // operation is being performed by XDR
67 #define AS_MSG_INFO1_GET_NOBINDATA (1 << 5) // do not get information about bins and its data
68 #define AS_MSG_INFO1_CONSISTENCY_ALL (1 << 6) // read consistency level - bit 0
72 #define AS_MSG_INFO2_WRITE (1 << 0) // contains a write semantic
73 #define AS_MSG_INFO2_DELETE (1 << 1) // delete record
74 #define AS_MSG_INFO2_GENERATION (1 << 2) // pay attention to the generation
75 #define AS_MSG_INFO2_GENERATION_GT (1 << 3) // apply write if new generation >= old, good for restore
76 #define AS_MSG_INFO2_DURABLE_DELETE (1 << 4) // transaction resulting in record deletion leaves tombstone (Enterprise only).
77 #define AS_MSG_INFO2_CREATE_ONLY (1 << 5) // write record only if it doesn't exist
79 #define AS_MSG_INFO2_RESPOND_ALL_OPS (1 << 7) // return a result for every operation.
82 #define AS_MSG_INFO3_LAST (1 << 0) // this is the last of a multi-part message
83 #define AS_MSG_INFO3_COMMIT_MASTER (1 << 1) // write commit level - bit 0
85 #define AS_MSG_INFO3_UPDATE_ONLY (1 << 3) // update existing record only, do not create new record
86 #define AS_MSG_INFO3_CREATE_OR_REPLACE (1 << 4) // completely replace existing record, or create new record
87 #define AS_MSG_INFO3_REPLACE_ONLY (1 << 5) // completely replace existing record, do not create new record
92 #define AS_MESSAGE_VERSION 2L
93 #define AS_MESSAGE_TYPE 3L
94 #define AS_COMPRESSED_MESSAGE_TYPE 4L
97 #define AS_INFO_MESSAGE_VERSION 2L
98 #define AS_INFO_MESSAGE_TYPE 1L
101 #define AS_HEADER_SIZE 30
102 #define AS_FIELD_HEADER_SIZE 5
103 #define AS_OPERATION_HEADER_SIZE 8
105 #define AS_STACK_BUF_SIZE (1024 * 16)
116 return cf_malloc(size);
122 return cf_free(memory);
129 #define as_command_init(_sz) (_sz > AS_STACK_BUF_SIZE) ? (uint8_t*)local_malloc(_sz) : (uint8_t*)alloca(_sz)
135 #define as_command_free(_buf, _sz) if (_sz > AS_STACK_BUF_SIZE) {local_free(_buf);}
145 typedef struct as_command_node_s {
156 typedef struct as_command_parse_result_data_s {
222 size_t s = strlen(name);
249 uint32_t timeout_ms, uint16_t
n_fields, uint16_t n_bins,
bool durable_delete);
255 static inline uint8_t*
257 uint32_t timeout_ms, uint16_t
n_fields, uint16_t n_bins)
265 memset(&cmd[10], 0, 12);
266 *(uint32_t*)&cmd[22] = cf_swap_to_be32(timeout_ms);
267 *(uint16_t*)&cmd[26] = cf_swap_to_be16(n_fields);
268 *(uint16_t*)&cmd[28] = cf_swap_to_be16(n_bins);
276 static inline uint8_t*
279 *(uint32_t*)p = cf_swap_to_be32(size+1);
289 static inline uint8_t*
306 static inline uint8_t*
310 *(uint64_t*)p = cf_swap_to_be64(val);
311 return p +
sizeof(uint64_t);
318 static inline uint8_t*
322 memcpy(p, buffer->data, buffer->size);
323 return p + buffer->size;
330 static inline uint8_t*
349 static inline uint8_t*
359 *(uint32_t*)cmd = cf_swap_to_be32((uint32_t)name_len + 4);
382 uint64_t len = end - begin;
384 *(uint64_t*)begin = cf_swap_to_be64(proto);
395 uint64_t len = end - begin;
397 *(uint64_t*)begin = cf_swap_to_be64(proto);
427 uint8_t* command,
size_t command_len,
as_parse_results_fn parse_results_fn,
void* parse_results_data