Blob/bytes
Aerospike supports two main types of Blob/bytes bins. There are general purpose Blob bins and language-specific Blob bins.
The general purpose Blob bins are byte arrays of a specific size. Any binary data of any type can be stored in a Blob bin. They also support Bitwise Operations.
Language-specific Blob bins are only accessible from the client library language that wrote them. These are useful for serializing objects in that language to the Aerospike database.
Bitwise Operations
Aerospike supports a rich set of bitwise operations which can be used on the Blob data type. These operations allow an application to manipulate a large Blob bin on the server without needing to pull the entire blob to the client, saving bandwidth.
The examples throughout this page use a 5-byte Blob bin called flags with
the value [0x01, 0x42, 0xB0, 0x04, 0x05], representing an IoT device
configuration record. Bits 0-15 store a 16-bit device ID, byte 2 holds
capability flags, and the remaining bytes hold status and version data.
| Name | Value | Description |
|---|---|---|
create_only | 0x01 | Disallow updating an existing value of this bin. |
update_only | 0x02 | Disallow creation of a new Blob bin. |
no_fail | 0x04 | If the operation should fail, continue as if it had succeeded. |
partial | 0X08 | If the number of bytes from the offset to the end of the existing Blob bin is less than the specified number of bytes, then only apply the operations from the offset to the end. |
Modify operations
add(policy, bin_name, bit_offset, n_bits, value, signed, action)Treat the n_bits bits beginning at offset in the Blob bin as an n_bits bit integer and add the integer value to it - the integer value will be converted to an n_bits bit integer. By default, fail if the result overflows. Integers in the Blob bin are stored and interpreted as big-endian integers.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Size of the integer in bits (maximum of 64 bits). |
value | integer | The unsigned integer value to be added. |
signed | boolean | Read the integer from the Blob bin as signed (true) or unsigned (false). |
action | client_specific | How to handle integer overflow.
|
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID stored as a big-endian unsigned integer. The add operation increments this integer in place on the server, avoiding a read-modify-write round trip.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first 16 bits represent 0x0142 (decimal 322). Calling add("flags", 0, 16, 10) adds 10 to get 332 (0x014C). The result is flags = [0x01, 0x4C, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)import com.aerospike.client.operation.BitOverflowAction;
Record record = client.operate(null, key, BitOperation.add(BitPolicy.Default, "flags", 0, 16, 10, false, BitOverflowAction.FAIL));// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) + 10 = 0x014C (332)import aerospikefrom aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_add("flags", 0, 16, 10, False, aerospike.BIT_OVERFLOW_FAIL)]client.operate(key, ops)# flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_add(&ops, "flags", NULL, NULL, 0, 16, 10, false, AS_BIT_OVERFLOW_FAIL);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)
record, err := client.Operate(nil, key, as.BitAddOp(as.DefaultBitPolicy(), "flags", 0, 16, 10, false, as.BitOverflowActionFail))// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)
Record record = client.Operate(null, key, BitOperation.Add(BitPolicy.Default, "flags", 0, 16, 10, false, BitOverflowAction.FAIL));// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)const bw = Aerospike.bitwise
const ops = [bw.add('flags', 0, 16, 10, false)]await client.operate(key, ops)// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]and(policy, bin_name, bit_offset, n_bits, value)Bitwise AND n_bits of the buffer with the leading n_bits of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
value | bytes | Buffer containing at least |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Byte 0 (bits 0-7) holds a device type identifier. ANDing with a mask clears specific bits while preserving others.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling and("flags", 0, 8, [0xF0]) masks the first byte with 0xF0 (1111 0000). This clears the lower four bits: 0x01 AND 0xF0 = 0x00. The result is flags = [0x00, 0x42, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.and(BitPolicy.Default, "flags", 0, 8, new byte[] {(byte) 0xF0}));// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_and("flags", 0, 8, 1, bytearray([0xF0]))]client.operate(key, ops)# flags = [0x00, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]uint8_t val[] = {0xF0};
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_and(&ops, "flags", NULL, NULL, 0, 8, 1, val);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitAndOp(as.DefaultBitPolicy(), "flags", 0, 8, []byte{0xF0}))// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.And(BitPolicy.Default, "flags", 0, 8, new byte[] { 0xF0 }));// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.and('flags', 0, 8, Buffer.from([0xF0]))]await client.operate(key, ops)// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]insert(policy, bin_name, byte_offset, value)Inserts bytes at the specified byte_offset with the contents of buffer.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
byte_offset | integer | Offset to location of insertion. |
value | bytes | Bytes to be inserted. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. To add two new bytes of status data in the middle of the blob, use insert at a byte offset. Existing bytes after the offset shift to the right, growing the blob.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes), calling insert("flags", 2, [0xAA, 0xBB]) inserts 0xAA 0xBB at byte offset 2. The result is flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes).
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.operate(null, key, BitOperation.insert(BitPolicy.Default, "flags", 2, new byte[] {(byte) 0xAA, (byte) 0xBB}));// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_insert("flags", 2, 2, bytearray([0xAA, 0xBB]))]client.operate(key, ops)# flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)uint8_t val[] = {0xAA, 0xBB};
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_insert(&ops, "flags", NULL, NULL, 2, 2, val);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
record, err := client.Operate(nil, key, as.BitInsertOp(as.DefaultBitPolicy(), "flags", 2, []byte{0xAA, 0xBB}))// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.Operate(null, key, BitOperation.Insert(BitPolicy.Default, "flags", 2, new byte[] { 0xAA, 0xBB }));// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)const bw = Aerospike.bitwise
const ops = [bw.insert('flags', 2, Buffer.from([0xAA, 0xBB]))]await client.operate(key, ops)// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)lshift(policy, bin_name, bit_offset, n_bits, shift)Bitwise shift n_bits bits of the Blob bin n_bits to the left starting at the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
shift | integer | Number of bits to shift. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID. Left-shifting multiplies the value by a power of 2. Bits shifted out on the left are lost, and zeros fill in on the right.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first two bytes are 0x0142 (decimal 322). Calling lshift("flags", 0, 16, 3) shifts the 16-bit field left by 3: 0x0142 << 3 = 0x0A10 (decimal 2576). The result is flags = [0x0A, 0x10, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
Record record = client.operate(null, key, BitOperation.lshift(BitPolicy.Default, "flags", 0, 16, 3));// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_lshift("flags", 0, 16, 3)]client.operate(key, ops)# flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_lshift(&ops, "flags", NULL, NULL, 0, 16, 3);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
record, err := client.Operate(nil, key, as.BitLShiftOp(as.DefaultBitPolicy(), "flags", 0, 16, 3))// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
Record record = client.Operate(null, key, BitOperation.Lshift(BitPolicy.Default, "flags", 0, 16, 3));// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)const bw = Aerospike.bitwise
const ops = [bw.lshift('flags', 0, 16, 3)]await client.operate(key, ops)// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]not(policy, bin_name, bit_offset, n_bits)Bitwise NOT n_bits of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. NOT inverts every bit in the specified range, flipping 0s to 1s and 1s to 0s.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling not("flags", 0, 8) inverts the first byte: NOT 0x01 (0000 0001) = 0xFE (1111 1110). The result is flags = [0xFE, 0x42, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.not(BitPolicy.Default, "flags", 0, 8));// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_not("flags", 0, 8)]client.operate(key, ops)# flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_not(&ops, "flags", NULL, NULL, 0, 8);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitNotOp(as.DefaultBitPolicy(), "flags", 0, 8))// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Not(BitPolicy.Default, "flags", 0, 8));// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.not('flags', 0, 8)]await client.operate(key, ops)// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]or(policy, bin_name, bit_offset, n_bits, value)Bitwise OR n_bits of the buffer with the leading n_bits of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
value | bytes | Buffer containing at least |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Byte 0 (bits 0-7) holds a device type identifier. ORing with a value sets specific bits without affecting others.
Given flags = [0x00, 0x42, 0xB0, 0x04, 0x05], calling or("flags", 0, 8, [0x01]) sets the lowest bit in the first byte: 0x00 OR 0x01 = 0x01. The result is flags = [0x01, 0x42, 0xB0, 0x04, 0x05].
// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.or(BitPolicy.Default, "flags", 0, 8, new byte[] {0x01}));// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# flags = [0x00, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_or("flags", 0, 8, 1, bytearray([0x01]))]client.operate(key, ops)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]uint8_t val[] = {0x01};
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_or(&ops, "flags", NULL, NULL, 0, 8, 1, val);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitOrOp(as.DefaultBitPolicy(), "flags", 0, 8, []byte{0x01}))// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Or(BitPolicy.Default, "flags", 0, 8, new byte[] { 0x01 }));// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.or('flags', 0, 8, Buffer.from([0x01]))]await client.operate(key, ops)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]remove(policy, bin_name, byte_offset, n_bytes)Remove n_bytes bytes beginning at the specified byte_offset.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
byte_offset | integer | Offset to location of removal. |
n_bytes | integer | Number of bytes to remove. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. To remove bytes from the middle of the blob, use remove at a byte offset with a count. Bytes after the removed range shift left, shrinking the blob.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes), calling remove("flags", 2, 2) removes 2 bytes starting at byte offset 2 (bytes 0xB0 and 0x04). The result is flags = [0x01, 0x42, 0x05] (3 bytes).
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.operate(null, key, BitOperation.remove(BitPolicy.Default, "flags", 2, 2));// flags = [0x01, 0x42, 0x05] (3 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_remove("flags", 2, 2)]client.operate(key, ops)# flags = [0x01, 0x42, 0x05] (3 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_remove(&ops, "flags", NULL, NULL, 2, 2);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x42, 0x05] (3 bytes)as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
record, err := client.Operate(nil, key, as.BitRemoveOp(as.DefaultBitPolicy(), "flags", 2, 2))// flags = [0x01, 0x42, 0x05] (3 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.Operate(null, key, BitOperation.Remove(BitPolicy.Default, "flags", 2, 2));// flags = [0x01, 0x42, 0x05] (3 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)const bw = Aerospike.bitwise
const ops = [bw.remove('flags', 2, 2)]await client.operate(key, ops)// flags = [0x01, 0x42, 0x05] (3 bytes)resize(policy, bin_name, n_bytes, resize_flags)Specify the size of the Blob bin to be n_bytes. This operation may (by default) create a new Bytes bin or extend or trim an existing Byte bin to the specified size of n_bytes. By default the resize operation will extend or trim from the end of the Blob bin.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
policy | library_specific | Bitwise modify policy. | ||||||||||||
bin_name | string | Name of bin. | ||||||||||||
n_bytes | integer | Number of bytes to resize to. | ||||||||||||
resize_flags | integer |
|
none An IoT device stores its configuration in a 5-byte Blob bin called flags. When the device schema grows to include additional fields, resize extends the blob to the new size. New bytes are initialized to zero and appended at the end by default.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes), calling resize("flags", 10, 0) extends the blob to 10 bytes. The result is flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.operate(null, key, BitOperation.resize(BitPolicy.Default, "flags", 10, 0));// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_resize("flags", 10)]client.operate(key, ops)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_resize(&ops, "flags", NULL, NULL, 10, AS_BIT_RESIZE_DEFAULT);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags now 10 bytes, padded with zeros at the endas_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
record, err := client.Operate(nil, key, as.BitResizeOp(as.DefaultBitPolicy(), "flags", 10, as.BitResizeFlagsDefault))// flags now 10 bytes, padded with zeros at the end// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.Operate(null, key, BitOperation.Resize(BitPolicy.Default, "flags", 10, BitResizeFlags.DEFAULT));// flags now 10 bytes, padded with zeros at the end// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)const bw = Aerospike.bitwise
const ops = [bw.resize('flags', 10)]await client.operate(key, ops)// flags now 10 bytes, padded with zeros at the endrshift(policy, bin_name, bit_offset, n_bits, shift)Bitwise shift n_bits bits of the Blob bin n_bits to the right starting at the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
shift | integer | Number of bits to shift. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID. Right-shifting divides the value by a power of 2. Bits shifted out on the right are lost, and zeros fill in on the left.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first two bytes are 0x0142 (decimal 322). Calling rshift("flags", 0, 16, 3) shifts the 16-bit field right by 3: 0x0142 >> 3 = 0x0028 (decimal 40). The result is flags = [0x00, 0x28, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
Record record = client.operate(null, key, BitOperation.rshift(BitPolicy.Default, "flags", 0, 16, 3));// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_rshift("flags", 0, 16, 3)]client.operate(key, ops)# flags = [0x00, 0x28, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_rshift(&ops, "flags", NULL, NULL, 0, 16, 3);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
record, err := client.Operate(nil, key, as.BitRShiftOp(as.DefaultBitPolicy(), "flags", 0, 16, 3))// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
Record record = client.Operate(null, key, BitOperation.Rshift(BitPolicy.Default, "flags", 0, 16, 3));// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)const bw = Aerospike.bitwise
const ops = [bw.rshift('flags', 0, 16, 3)]await client.operate(key, ops)// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]set(policy, bin_name, bit_offset, n_bits, value)Overwrites n_bits bits at the specified offset (in bits) with the first n_bits of value.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to overwrite. |
n_bits | integer | Number of bits to overwrite. |
value | bytes | Buffer containing at least |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Byte 2 (bits 16-23) holds capability flags. To enable all capabilities at once, overwrite that byte with 0xFF.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling set("flags", 16, 8, [0xFF]) replaces byte 2 with 0xFF (1111 1111), turning on every capability bit. The result is flags = [0x01, 0x42, 0xFF, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.set(BitPolicy.Default, "flags", 16, 8, new byte[] {(byte) 0xFF}));// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_set("flags", 16, 8, 1, bytearray([0xFF]))]client.operate(key, ops)# flags = [0x01, 0x42, 0xFF, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]uint8_t val[] = {0xFF};
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_set(&ops, "flags", NULL, NULL, 16, 8, 1, val);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitSetOp(as.DefaultBitPolicy(), "flags", 16, 8, []byte{0xFF}))// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Set(BitPolicy.Default, "flags", 16, 8, new byte[] { 0xFF }));// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.set('flags', 16, 8, Buffer.from([0xFF]))]await client.operate(key, ops)// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]set_int(policy, bin_name, bit_offset, n_bits, value)Overwrite n_bits bits at offset offset with uint64 converted to an n_bits bit big_endian integer.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Size of the integer in bits (maximum of 64 bits). |
value | integer | The unsigned integer value to be set. |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID. Instead of computing the raw bytes for a new ID, set_int writes an integer directly.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling set_int("flags", 0, 16, 500) writes 500 (0x01F4) into the first 16 bits as a big-endian integer. The result is flags = [0x01, 0xF4, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4
Record record = client.operate(null, key, BitOperation.setInt(BitPolicy.Default, "flags", 0, 16, 500));// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# 500 = 0x01F4from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_set_int("flags", 0, 16, 500)]client.operate(key, ops)# flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_set_int(&ops, "flags", NULL, NULL, 0, 16, 500);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4
record, err := client.Operate(nil, key, as.BitSetIntOp(as.DefaultBitPolicy(), "flags", 0, 16, 500))// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4
Record record = client.Operate(null, key, BitOperation.SetInt(BitPolicy.Default, "flags", 0, 16, 500));// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4const bw = Aerospike.bitwise
// Pass an integer (instead of a Buffer) to set() for set_intconst ops = [bw.set('flags', 0, 16, 500)]await client.operate(key, ops)// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]subtract(policy, bin_name, bit_offset, n_bits, value, signed, action)Treat the n_bits bits beginning at offset in the Blob bin as an n_bits bit integer and subtract the integer uint64 from it - the integer uint64 will be converted to an n_bits bit integer. By default, fail if the result underflows. Integers in the Blob bin are stored and interpreted as big-endian integers.
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Size of the integer in bits (maximum of 64 bits). |
value | integer | The unsigned integer value to be subtracted. |
signed | boolean | Read the integer from the Blob bin as signed (true) or unsigned (false). |
action | client_specific | How to handle integer underflow.
|
none An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID stored as a big-endian unsigned integer. The subtract operation decrements this integer in place on the server.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first 16 bits represent 0x0142 (decimal 322). Calling subtract("flags", 0, 16, 5) subtracts 5 to get 317 (0x013D). The result is flags = [0x01, 0x3D, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)import com.aerospike.client.operation.BitOverflowAction;
Record record = client.operate(null, key, BitOperation.subtract(BitPolicy.Default, "flags", 0, 16, 5, false, BitOverflowAction.FAIL));// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) - 5 = 0x013D (317)import aerospikefrom aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_subtract("flags", 0, 16, 5, False, aerospike.BIT_OVERFLOW_FAIL)]client.operate(key, ops)# flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_subtract(&ops, "flags", NULL, NULL, 0, 16, 5, false, AS_BIT_OVERFLOW_FAIL);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)
record, err := client.Operate(nil, key, as.BitSubtractOp(as.DefaultBitPolicy(), "flags", 0, 16, 5, false, as.BitOverflowActionFail))// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)
Record record = client.Operate(null, key, BitOperation.Subtract(BitPolicy.Default, "flags", 0, 16, 5, false, BitOverflowAction.FAIL));// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)const bw = Aerospike.bitwise
const ops = [bw.subtract('flags', 0, 16, 5, false)]await client.operate(key, ops)// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]xor(policy, bin_name, bit_offset, n_bits, value)Bitwise XOR n_bits of the buffer with the leading n_bits of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | library_specific | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
n_bits | integer | Number of bits to apply operation to. |
value | bytes | Buffer containing at least |
none An IoT device stores its configuration in a 5-byte Blob bin called flags. XOR flips the bits where the mask has 1s, leaving other bits unchanged. This is useful for toggling specific flags.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling xor("flags", 0, 8, [0x0F]) flips the lower four bits of the first byte: 0x01 XOR 0x0F = 0x0E (0000 0001 XOR 0000 1111 = 0000 1110). The result is flags = [0x0E, 0x42, 0xB0, 0x04, 0x05].
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.xor(BitPolicy.Default, "flags", 0, 8, new byte[] {0x0F}));// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_xor("flags", 0, 8, 1, bytearray([0x0F]))]client.operate(key, ops)# flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]uint8_t val[] = {0x0F};
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_xor(&ops, "flags", NULL, NULL, 0, 8, 1, val);
aerospike_key_operate(&as, &err, NULL, &key, &ops, NULL);// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitXorOp(as.DefaultBitPolicy(), "flags", 0, 8, []byte{0x0F}))// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Xor(BitPolicy.Default, "flags", 0, 8, new byte[] { 0x0F }));// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.xor('flags', 0, 8, Buffer.from([0x0F]))]await client.operate(key, ops)// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]Read operations
count(bin_name, bit_offset, n_bits)Count the number of bits set to 1 in the n_bits beginning at offset.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to be checked. |
n_bits | integer | Number of bits to check. |
bytes An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID. To find out how many bits are set in the device ID field, use count at offset 0 for 16 bits.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first two bytes are 0x01 0x42 (0000 0001 0100 0010 in binary). Calling count("flags", 0, 16) returns 4 — four bits are set in the device ID field.
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
Record record = client.operate(null, key, BitOperation.count("flags", 0, 16));// returns 4# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0000 0001 0100 0010from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_count("flags", 0, 16)]_, _, result = client.operate(key, ops)# result["flags"] == 4// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_count(&ops, "flags", NULL, 0, 16);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 4as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
record, err := client.Operate(nil, key, as.BitCountOp("flags", 0, 16))// record.Bins["flags"] == 4// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
Record record = client.Operate(null, key, BitOperation.Count("flags", 0, 16));// returns 4// count is not available in the Node.js bitwise operate APIget(bin_name, bit_offset, n_bits)Retrieve n_bits bits beginning at offset offset. If n_bits is not a multiple of 8 then there will be n_bits modulo 8 zeroed bits padding the end.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to be retrieved. |
n_bits | integer | Number of bits to retrieve. |
bytes An IoT device record stores its configuration in a 5-byte Blob bin called flags. Byte 2 (bits 16-23) holds capability flags such as WiFi, Bluetooth, and GPS. To read just that byte without transferring the entire blob, use get at bit offset 16 for 8 bits.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling get("flags", 16, 8) returns [0xB0] — the single capability byte.
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.get("flags", 16, 8));// returns [0xB0]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_get("flags", 16, 8)]_, _, result = client.operate(key, ops)# result["flags"] == bytearray(b'\xb0')// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_get(&ops, "flags", NULL, 16, 8);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns [0xB0]as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitGetOp("flags", 16, 8))// record.Bins["flags"] == []byte{0xB0}// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Get("flags", 16, 8));// returns [0xB0]// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.get('flags', 16, 8)]const record = await client.operate(key, ops)// record.bins.flags == Buffer<b0>get_integer(bin_name, bit_offset, n_bits, signed)Retrieve the n_bits bit big-endian integer beginning at offset offset as a 64 bit integer.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to be retrieved |
n_bits | integer | Number of bits to retrieve. |
signed | boolean | If true, treat the value at offset as a signed |
integer An IoT device stores its configuration in a 5-byte Blob bin called flags. Bits 0-15 hold a 16-bit device ID stored as a big-endian integer. To read the device ID as a number, use get_integer at offset 0 for 16 bits.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling get_integer("flags", 0, 16, false) returns 322 (0x0142 as an unsigned 16-bit integer).
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.getInt("flags", 0, 16, false));// returns 322 (0x0142 unsigned)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_get_int("flags", 0, 16, False)]_, _, result = client.operate(key, ops)# result["flags"] == 322// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_get_int(&ops, "flags", NULL, 0, 16, false);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 322 (0x0142 unsigned)as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitGetIntOp("flags", 0, 16, false))// record.Bins["flags"] == 322// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.GetInt("flags", 0, 16, false));// returns 322 (0x0142 unsigned)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.getInt('flags', 0, 16, false)]const record = await client.operate(key, ops)// record.bins.flags == 322lscan(bin_name, bit_offset, n_bits, value)Return the position relative to the offset of the first bit set to value searching from offset plus n_bits to offset. If the value isn’t found, returns -1.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first (leftmost) bit to be scanned. |
n_bits | integer | Number of bits from the |
value | boolean | If true, search for the first set bit. If false, search for the first unset bit. |
integer An IoT device stores its configuration in a 5-byte (40-bit) Blob bin called flags. To find the position of the first set bit across the entire blob, use lscan from offset 0 for all 40 bits, searching left to right.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the first byte 0x01 is 0000 0001. Calling lscan("flags", 0, 40, true) returns 7 — the first set bit is at position 7 (the least-significant bit of the first byte).
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.lscan("flags", 0, 40, true));// returns 7 (first set bit is at position 7)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_lscan("flags", 0, 40, True)]_, _, result = client.operate(key, ops)# result["flags"] == 7// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_lscan(&ops, "flags", NULL, 0, 40, true);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 7as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitLScanOp("flags", 0, 40, true))// record.Bins["flags"] == 7// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Lscan("flags", 0, 40, true));// returns 7// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.lscan('flags', 0, 40, true)]const record = await client.operate(key, ops)// record.bins.flags == 7rscan(bin_name, bit_offset, n_bits, value)Return the position relative to the offset of the first bit set to value searching from offset to offset plus n_bits. If the value isn’t found, returns -1.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first (leftmost) bit to be scanned. |
n_bits | integer | Number of bits from the |
value | boolean | If true, search for the first set bit. If false, search for the first unset bit. |
integer An IoT device stores its configuration in a 5-byte (40-bit) Blob bin called flags. To find the position of the last set bit across the entire blob, use rscan from offset 0 for all 40 bits, searching right to left.
Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], the last byte 0x05 is 0000 0101. Calling rscan("flags", 0, 40, true) returns 37 — the last set bit is at position 37 (bit index 37, counting from bit 0 at the left).
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.rscan("flags", 0, 40, true));// returns 37 (last set bit is at position 37)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_rscan("flags", 0, 40, True)]_, _, result = client.operate(key, ops)# result["flags"] == 37// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_operations_init(&ops, 1);as_operations_bit_rscan(&ops, "flags", NULL, 0, 40, true);
as_record* rec = NULL;aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns 37as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitRScanOp("flags", 0, 40, true))// record.Bins["flags"] == 37// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Rscan("flags", 0, 40, true));// returns 37// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const ops = [bw.rscan('flags', 0, 40, true)]const record = await client.operate(key, ops)// record.bins.flags == 37