uint8_t* as_command_parse_bins(as_record* rec, uint8_t* p, uint32_t n_bins, bool deserialize) { as_bin* bin = rec->bins.entries; // Parse bins for (uint32_t i = 0; i < n_bins; i++, bin++) { uint32_t op_size = cf_swap_from_be32(*(uint32_t*)p); p += 5; uint8_t type = *p; p += 2; uint8_t name_size = *p++; uint8_t name_len = (name_size <= AS_BIN_NAME_MAX_LEN)? name_size : AS_BIN_NAME_MAX_LEN; memcpy(bin->name, p, name_len); bin->name[name_len] = 0; p += name_size; uint32_t value_size = (op_size - (name_size + 4)); switch (type) { case AS_BYTES_UNDEF: { bin->valuep = (as_bin_value*)&as_nil; break; } case AS_BYTES_INTEGER: { int64_t value; if (as_command_bytes_to_int(p, value_size, &value) == 0) { as_integer_init((as_integer*)&bin->value, value); bin->valuep = &bin->value; } break; } case AS_BYTES_DOUBLE: { double value = cf_swap_from_big_float64(*(double*)p); as_double_init((as_double*)&bin->value, value); bin->valuep = &bin->value; break; } case AS_BYTES_STRING: { char* value = malloc(value_size + 1); memcpy(value, p, value_size); value[value_size] = 0; as_string_init_wlen((as_string*)&bin->value, (char*)value, value_size, true); bin->valuep = &bin->value; break; } case AS_BYTES_LIST: case AS_BYTES_MAP: { if (deserialize) { as_val* value = 0; as_buffer buffer; buffer.data = p; buffer.size = value_size; as_serializer ser; as_msgpack_init(&ser); as_serializer_deserialize(&ser, &buffer, &value); as_serializer_destroy(&ser); bin->valuep = (as_bin_value*)value; } else { void* value = malloc(value_size); memcpy(value, p, value_size); as_bytes_init_wrap((as_bytes*)&bin->value, value, value_size, true); bin->value.bytes.type = (as_bytes_type)type; bin->valuep = &bin->value; } break; } default: { void* value = malloc(value_size); memcpy(value, p, value_size); as_bytes_init_wrap((as_bytes*)&bin->value, value, value_size, true); bin->value.bytes.type = (as_bytes_type)type; bin->valuep = &bin->value; break; } } rec->bins.size++; p += value_size; } return p; }
uint8_t* as_command_parse_key(uint8_t* p, uint32_t n_fields, as_key* key) { uint32_t len; uint32_t size; for (uint32_t i = 0; i < n_fields; i++) { len = cf_swap_from_be32(*(uint32_t*)p) - 1; p += 4; switch (*p++) { case AS_FIELD_DIGEST: size = (len < AS_DIGEST_VALUE_SIZE) ? len : AS_DIGEST_VALUE_SIZE; key->digest.init = true; memcpy(key->digest.value, p, size); break; case AS_FIELD_NAMESPACE: size = (len < (AS_NAMESPACE_MAX_SIZE-1)) ? len : (AS_NAMESPACE_MAX_SIZE-1); memcpy(key->ns, p, size); key->ns[size] = 0; break; case AS_FIELD_SETNAME: size = (len < (AS_SET_MAX_SIZE-1)) ? len : (AS_SET_MAX_SIZE-1); memcpy(key->set, p, size); key->set[size] = 0; break; case AS_FIELD_KEY: len--; uint8_t type = *p++; switch (type) { case AS_BYTES_INTEGER: { int64_t value; if (as_command_bytes_to_int(p, len, &value) == 0) { as_integer_init((as_integer*)&key->value, value); key->valuep = &key->value; } break; } case AS_BYTES_DOUBLE: { double value = cf_swap_from_big_float64(*(double*)p); as_double_init((as_double*)&key->value, value); key->valuep = &key->value; break; } case AS_BYTES_STRING: { char* value = malloc(len+1); memcpy(value, p, len); value[len] = 0; as_string_init_wlen((as_string*)&key->value, value, len, true); key->valuep = &key->value; break; } case AS_BYTES_BLOB: { void* value = malloc(len); memcpy(value, p, len); as_bytes_init_wrap((as_bytes*)&key->value, (uint8_t*)value, len, true); key->valuep = &key->value; break; } default: { as_log_error("Invalid key type: %d", type); break; } } break; } p += len; } return p; }
bool as_operations_add_list_append_double(as_operations *ops, const as_bin_name name, double value) { as_double v; as_double_init(&v, value); return AS_OPERATIONS_CDT_OP(ops, name, AS_CDT_OP_LIST_APPEND, &v); }
bool as_operations_add_list_set_double(as_operations *ops, const as_bin_name name, int64_t index, double value) { as_double v; as_double_init(&v, value); return AS_OPERATIONS_CDT_OP(ops, name, AS_CDT_OP_LIST_SET, index, &v); }
static void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, PyObject *py_value, as_binop *binop, char *bin, as_static_pool *static_pool) { as_bin *binop_bin = &binop->bin; if (PyInt_Check(py_value)) { int val = PyInt_AsLong(py_value); as_integer_init((as_integer *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else if (PyLong_Check(py_value)) { long val = PyLong_AsLong(py_value); as_integer_init((as_integer *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else if (PyString_Check(py_value)) { char * val = PyString_AsString(py_value); as_string_init((as_string *) &binop_bin->value, val, false); binop_bin->valuep = &binop_bin->value; } else if (PyUnicode_Check(py_value)) { PyObject *py_ustr1 = PyUnicode_AsUTF8String(py_value); char * val = PyString_AsString(py_ustr1); as_string_init((as_string *) &binop_bin->value, val, false); binop_bin->valuep = &binop_bin->value; } else if (PyFloat_Check(py_value)) { int64_t val = PyFloat_AsDouble(py_value); if (aerospike_has_double(self->as)) { as_double_init((as_double *) &binop_bin->value, val); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } } else if (PyList_Check(py_value)) { as_list * list = NULL; pyobject_to_list(self, err, py_value, &list, static_pool, SERIALIZER_PYTHON); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) list; } else if (PyDict_Check(py_value)) { as_map * map = NULL; pyobject_to_map(self, err, py_value, &map, static_pool, SERIALIZER_PYTHON); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) map; } else if (!strcmp(py_value->ob_type->tp_name, "aerospike.Geospatial")) { PyObject* py_data = PyObject_GenericGetAttr(py_value, PyString_FromString("geo_data")); char *geo_value = PyString_AsString(AerospikeGeospatial_DoDumps(py_data, err)); if (aerospike_has_geo(self->as)) { as_geojson_init((as_geojson *) &binop_bin->value, geo_value, false); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_data, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } } else if (!strcmp(py_value->ob_type->tp_name, "aerospike.null")) { ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) &as_nil; } else if (PyByteArray_Check(py_value)) { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); as_bytes_init_wrap((as_bytes *) &binop_bin->value, bytes->value, bytes->size, false); binop_bin->valuep = &binop_bin->value; } else { as_bytes *bytes; GET_BYTES_POOL(bytes, static_pool, err); serialize_based_on_serializer_policy(self, SERIALIZER_PYTHON, &bytes, py_value, err); ((as_val *) &binop_bin->value)->type = AS_UNKNOWN; binop_bin->valuep = (as_bin_value *) bytes; } strcpy(binop_bin->name, bin); }