/** ****************************************************************************************************** * Initialize and set the bytes for serialization * * @param bytes The as_bytes object to be set. * @param bytes_string The string which is to be loaded into the * as_bytes object. * @param bytes_string_len The length of bytes_string * @param bytes_type The type of bytes: AS_BYTES_BLOB or * AS_BYTES_PYTHON. * @param error_p The error object ****************************************************************************************************** */ void set_as_bytes(as_bytes **bytes, uint8_t *bytes_string, int32_t bytes_string_len, int32_t bytes_type, as_error *error_p) { if((!bytes) || (!bytes_string)) { as_error_update(error_p, AEROSPIKE_ERR, "Unable to set as_bytes"); goto CLEANUP; } as_bytes_init(*bytes, bytes_string_len); if (!as_bytes_set(*bytes, 0, bytes_string, bytes_string_len)) { as_error_update(error_p, AEROSPIKE_ERR, "Unable to set as_bytes"); } else { as_bytes_set_type(*bytes, bytes_type); } CLEANUP: if ( error_p->code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(error_p, &py_err); PyObject *exception_type = raise_exception(error_p); PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); } return; }
/** * Append raw bytes of given size. * * ~~~~~~~~~~{.c} * uint8_t value[3] = {'a','b','c'}; * * as_bytes_append(&bytes, value, 3); * ~~~~~~~~~~ * * The `bytes` must be sufficiently sized for the data being written. * To ensure the `bytes` is allocated sufficiently, you will need to call * `as_bytes_ensure()`. * * @param bytes The bytes to append to. * @param value The buffer to read from. * @param size The number of bytes to read from the value. * * @return On success, true. Otherwise an error occurred. */ bool as_bytes_append(as_bytes * bytes, const uint8_t * value, uint32_t size) { return as_bytes_set(bytes, bytes->size, value, size); }