Blob/bytes
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
Blob/bytes 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.
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.
These operations have expression counterparts, which evaluate to a value instead of writing it. See Bit expressions for the set, and Operations and expressions for which to reach for.
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. |
create_only is valid only on resize and insert, the two
operations that can create the bin. The other bitwise modify operations reject it.
Most bitwise operations read or modify bits and return bits or an integer.
b64_encode is the exception: it returns the base64 text of the
blob, or of a byte span within it, as a String, and its offset and size
arguments are expressed in bytes rather than bits. It requires Aerospike
Database 8.2.0 or later. The decode direction,
b64_decode, is a string
operation.
Modify operations
add(policy, bin_name, bit_offset, bit_size, value, signed, action)Treat the bit_size bits beginning at offset in the Blob bin as a bit_size bit integer and add the integer value to it - the integer value will be converted to a bit_size 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 | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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 | Overflow action | 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.sdk.operation.BitOverflowAction;
try (RecordStream rs = session.upsert(key) .bin("flags").bitAdd(0, 16, 10, false, BitOverflowAction.FAIL) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) + 10 = 0x014C (332)from aerospike_sdk import BitwiseOverflowActions
session.upsert(key).bin("flags").bit_add( 0, 16, 10, False, BitwiseOverflowActions.FAIL).execute()# flags = [0x01, 0x4C, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy, BitwiseOverflowActions};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) + 10 = 0x014C (332)
client.operate(&WritePolicy::default(), &key, &[bitwise::add("flags", 0, 16, 10, false, BitwiseOverflowActions::Fail, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)const bw = Aerospike.bitwise
const ops = [bw.add('flags', 0, 16, 10, false) .onOverflow(bw.overflow.FAIL)]await 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)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]and(policy, bin_name, bit_offset, bit_size, value)Bitwise AND bit_size of the buffer with the leading bit_size of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | integer | Number of bits to apply operation to. |
value | blob | 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]
try (RecordStream rs = session.upsert(key) .bin("flags").bitAnd(0, 8, new byte[] {(byte) 0xF0}) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
session.upsert(key).bin("flags").bit_and(0, 8, bytes([0xF0])).execute()# flags = [0x00, 0x42, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
client.operate(&WritePolicy::default(), &key, &[bitwise::and("flags", 0, 8, Value::Blob(vec![0xF0]), &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]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]// 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 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]insert(policy, bin_name, byte_offset, value)Inserts bytes at the specified byte_offset with the contents of buffer.
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
byte_offset | integer | Offset to location of insertion. |
value | blob | 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)
try (RecordStream rs = session.upsert(key) .bin("flags").bitInsert(2, new byte[] {(byte) 0xAA, (byte) 0xBB}) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
session.upsert(key).bin("flags").bit_insert(2, bytes([0xAA, 0xBB])).execute()# flags = [0x01, 0x42, 0xAA, 0xBB, 0xB0, 0x04, 0x05] (7 bytes)// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
client.operate(&WritePolicy::default(), &key, &[bitwise::insert("flags", 2, Value::Blob(vec![0xAA, 0xBB]), &BitPolicy::default())]).await?;// 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)// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)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)// 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 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)lshift(policy, bin_name, bit_offset, bit_size, shift)Bitwise shift bit_size bits of the Blob bin bit_size to the left starting at the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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)
try (RecordStream rs = session.upsert(key) .bin("flags").bitLshift(0, 16, 3) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
session.upsert(key).bin("flags").bit_lshift(0, 16, 3).execute()# flags = [0x0A, 0x10, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) << 3 = 0x0A10 (2576)
client.operate(&WritePolicy::default(), &key, &[bitwise::lshift("flags", 0, 16, 3, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)const bw = Aerospike.bitwise
const ops = [bw.lshift('flags', 0, 16, 3)]await 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 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]not(policy, bin_name, bit_offset, bit_size)Bitwise NOT bit_size of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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]
try (RecordStream rs = session.upsert(key) .bin("flags").bitNot(0, 8) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
session.upsert(key).bin("flags").bit_not(0, 8).execute()# flags = [0xFE, 0x42, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
client.operate(&WritePolicy::default(), &key, &[bitwise::not("flags", 0, 8, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]const bw = Aerospike.bitwise
const ops = [bw.not('flags', 0, 8)]await 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 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]or(policy, bin_name, bit_offset, bit_size, value)Bitwise OR bit_size of the buffer with the leading bit_size of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | integer | Number of bits to apply operation to. |
value | blob | 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]
try (RecordStream rs = session.upsert(key) .bin("flags").bitOr(0, 8, new byte[] {0x01}) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# flags = [0x00, 0x42, 0xB0, 0x04, 0x05]
session.upsert(key).bin("flags").bit_or(0, 8, bytes([0x01])).execute()# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x00, 0x42, 0xB0, 0x04, 0x05]
client.operate(&WritePolicy::default(), &key, &[bitwise::or("flags", 0, 8, Value::Blob(vec![0x01]), &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]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]// 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 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]remove(policy, bin_name, byte_offset, byte_size)Remove byte_size bytes beginning at the specified byte_offset.
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
byte_offset | integer | Offset to location of removal. |
byte_size | 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)
try (RecordStream rs = session.upsert(key) .bin("flags").bitRemove(2, 2) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x42, 0x05] (3 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
session.upsert(key).bin("flags").bit_remove(2, 2).execute()# flags = [0x01, 0x42, 0x05] (3 bytes)// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
client.operate(&WritePolicy::default(), &key, &[bitwise::remove("flags", 2, 2, &BitPolicy::default())]).await?;// 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)// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)const bw = Aerospike.bitwise
const ops = [bw.remove('flags', 2, 2)]await 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 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)resize(policy, bin_name, byte_size, resize_flags)Specify the size of the Blob bin to be byte_size. This operation may (by default) create a new Bytes bin or extend or trim an existing Byte bin to the specified size of byte_size. By default the resize operation will extend or trim from the end of the Blob bin.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
policy | Bit policy | Bitwise modify policy. | ||||||||||||
bin_name | string | Name of bin. | ||||||||||||
byte_size | integer | Number of bytes to resize to. | ||||||||||||
resize_flags | Resize flags |
|
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)import com.aerospike.client.sdk.operation.BitResizeFlags;
try (RecordStream rs = session.upsert(key) .bin("flags").bitResize(10, BitResizeFlags.DEFAULT) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)from aerospike_sdk import BitwiseResizeFlags
session.upsert(key).bin("flags").bit_resize(10, BitwiseResizeFlags.DEFAULT).execute()# flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)// Requires: use aerospike::operations::bitwise::{self, BitPolicy, BitwiseResizeFlags};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
client.operate(&WritePolicy::default(), &key, &[bitwise::resize("flags", 10, Some(BitwiseResizeFlags::Default), &BitPolicy::default())]).await?;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
Record record = client.Operate(null, key, BitOperation.Resize(BitPolicy.Default, "flags", 10, BitResizeFlags.DEFAULT));// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)
record, err := client.Operate(nil, key, as.BitResizeOp(as.DefaultBitPolicy(), "flags", 10, as.BitResizeFlagsDefault))// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)const bw = Aerospike.bitwise
const ops = [bw.resize('flags', 10, bw.resizeFlags.DEFAULT)]await 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 = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)import com.aerospike.client.operation.BitResizeFlags;
Record record = client.operate(null, key, BitOperation.resize(BitPolicy.Default, "flags", 10, BitResizeFlags.DEFAULT));// flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05] (5 bytes)import aerospikefrom aerospike_helpers.operations import bitwise_operations as bw
ops = [bw.bit_resize("flags", 10, resize_flags=aerospike.BIT_RESIZE_DEFAULT)]client.operate(key, ops)# flags = [0x01, 0x42, 0xB0, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00] (10 bytes)rshift(policy, bin_name, bit_offset, bit_size, shift)Bitwise shift bit_size bits of the Blob bin bit_size to the right starting at the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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)
try (RecordStream rs = session.upsert(key) .bin("flags").bitRshift(0, 16, 3) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x00, 0x28, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
session.upsert(key).bin("flags").bit_rshift(0, 16, 3).execute()# flags = [0x00, 0x28, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) >> 3 = 0x0028 (40)
client.operate(&WritePolicy::default(), &key, &[bitwise::rshift("flags", 0, 16, 3, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)const bw = Aerospike.bitwise
const ops = [bw.rshift('flags', 0, 16, 3)]await 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 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]set(policy, bin_name, bit_offset, bit_size, value)Overwrites bit_size bits at the specified offset (in bits) with the first bit_size of value.
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to overwrite. |
bit_size | integer | Number of bits to overwrite. |
value | blob | 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]
try (RecordStream rs = session.upsert(key) .bin("flags").bitSet(16, 8, new byte[] {(byte) 0xFF}) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x42, 0xFF, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
session.upsert(key).bin("flags").bit_set(16, 8, bytes([0xFF])).execute()# flags = [0x01, 0x42, 0xFF, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
client.operate(&WritePolicy::default(), &key, &[bitwise::set("flags", 16, 8, Value::Blob(vec![0xFF]), &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]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]// 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 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]set_int(policy, bin_name, bit_offset, bit_size, value)Overwrite bit_size bits at offset offset with uint64 converted to an bit_size bit big_endian integer.
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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
try (RecordStream rs = session.upsert(key) .bin("flags").bitSetInt(0, 16, 500) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# 500 = 0x01F4
session.upsert(key).bin("flags").bit_set_int(0, 16, 500).execute()# flags = [0x01, 0xF4, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// 500 = 0x01F4
client.operate(&WritePolicy::default(), &key, &[bitwise::set_int("flags", 0, 16, 500, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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 = 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]// 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 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]subtract(policy, bin_name, bit_offset, bit_size, value, signed, action)Treat the bit_size bits beginning at offset in the Blob bin as a bit_size bit integer and subtract the integer uint64 from it - the integer uint64 will be converted to a bit_size 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 | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | 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 | Overflow action | 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.sdk.operation.BitOverflowAction;
try (RecordStream rs = session.upsert(key) .bin("flags").bitSubtract(0, 16, 5, false, BitOverflowAction.FAIL) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0x0142 (322) - 5 = 0x013D (317)from aerospike_sdk import BitwiseOverflowActions
session.upsert(key).bin("flags").bit_subtract( 0, 16, 5, False, BitwiseOverflowActions.FAIL).execute()# flags = [0x01, 0x3D, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy, BitwiseOverflowActions};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0x0142 (322) - 5 = 0x013D (317)
client.operate(&WritePolicy::default(), &key, &[bitwise::subtract("flags", 0, 16, 5, false, BitwiseOverflowActions::Fail, &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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)const bw = Aerospike.bitwise
const ops = [bw.subtract('flags', 0, 16, 5, false) .onOverflow(bw.overflow.FAIL)]await 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)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]xor(policy, bin_name, bit_offset, bit_size, value)Bitwise XOR bit_size of the buffer with the leading bit_size of the Blob bin starting from the specified offset (in bits).
| Name | Type | Description |
|---|---|---|
policy | Bit policy | Bitwise modify policy. |
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first bit to apply operation. |
bit_size | integer | Number of bits to apply operation to. |
value | blob | 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]
try (RecordStream rs = session.upsert(key) .bin("flags").bitXor(0, 8, new byte[] {0x0F}) .execute()) { Record rec = rs.next().recordOrThrow();}// flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
session.upsert(key).bin("flags").bit_xor(0, 8, bytes([0x0F])).execute()# flags = [0x0E, 0x42, 0xB0, 0x04, 0x05]// Requires: use aerospike::operations::bitwise::{self, BitPolicy};// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
client.operate(&WritePolicy::default(), &key, &[bitwise::xor("flags", 0, 8, Value::Blob(vec![0x0F]), &BitPolicy::default())]).await?;// 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]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]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]// 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 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]Read operations
b64_encode(bin_name[, byte_offset][, byte_size][, subflags])Return the base64 text of the Blob bin, or of a byte span within it, as a String.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
byte_offset | integer | Offset (in bytes) to the first byte to encode, unlike the bit offsets the other bitwise operations take. A negative value counts back from the end of the blob. Optional; defaults to |
byte_size | integer | Number of bytes to encode, counting forward from |
subflags | integer |
|
string Encoding the whole flags bin returns its base64 text as a String. Given flags = [0x01, 0x42, 0xB0, 0x04, 0x05], calling b64_encode("flags") returns "AUKwBAU=".
This is the encode direction. b64_decode is the decode direction and takes a String bin back to a blob.
Supplying byte_offset and byte_size encodes part of the blob without reading the whole bin. b64_encode("flags", 1, 2) encodes bytes 1 and 2 (0x42, 0xB0) and returns "QrA=".
Setting the invert_size subflag measures byte_size from the end of the blob instead, so a byte_size of 0 runs through to the end: b64_encode("flags", 1, 0, invert_size) encodes bytes 1 through 4 and returns "QrAEBQ==".
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
try (RecordStream rs = session.query(key) .bin("flags").bitB64Encode() .execute()) { Record rec = rs.next().recordOrThrow(); // returns "AUKwBAU="}
// Bytes 1-2 only.try (RecordStream rs = session.query(key) .bin("flags").bitB64Encode(1, 2) .execute()) { Record rec = rs.next().recordOrThrow(); // returns "QrA="}
// Byte 1 through the end (invertSize with a byteSize of 0).try (RecordStream rs = session.query(key) .bin("flags").bitB64Encode(1, 0, true) .execute()) { Record rec = rs.next().recordOrThrow(); // returns "QrAEBQ=="}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
stream = session.query(key).bin("flags").bit_b64_encode().execute()# returns "AUKwBAU="
# Bytes 1-2 only.span = session.query(key).bin("flags").bit_b64_encode(1, 2).execute()# returns "QrA="
# Byte 1 through the end (invert_size with a byte_size of 0).tail = session.query(key).bin("flags").bit_b64_encode(1, 0, True).execute()# returns "QrAEBQ=="// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::b64_encode("flags")]).await?;// returns "AUKwBAU="
// Bytes 1-2 only.let span = client.operate(&WritePolicy::default(), &key, &[bitwise::b64_encode_range("flags", 1, 2, false)]).await?;// returns "QrA="
// Byte 1 through the end (invert_size with a byte_size of 0).let tail = client.operate(&WritePolicy::default(), &key, &[bitwise::b64_encode_range("flags", 1, 0, true)]).await?;// returns "QrAEBQ=="// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.B64Encode("flags"));// returns "AUKwBAU="
// Bytes 1-2 only.Record span = client.Operate(null, key, BitOperation.B64Encode("flags", 1, 2));// returns "QrA="
// Byte 1 through the end (invertSize with a byteSize of 0).Record tail = client.Operate(null, key, BitOperation.B64Encode("flags", 1, 0, true));// returns "QrAEBQ=="// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitB64EncodeOp("flags"))// record.Bins["flags"] == "AUKwBAU="
// Bytes 1-2 only.span, err := client.Operate(nil, key, as.BitB64EncodeRangeOp("flags", 1, 2, false))// span.Bins["flags"] == "QrA="
// Byte 1 through the end (invertSize with a byteSize of 0).tail, err := client.Operate(nil, key, as.BitB64EncodeRangeOp("flags", 1, 0, true))// tail.Bins["flags"] == "QrAEBQ=="// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]const bw = Aerospike.bitwise
const record = await client.operate(key, [bw.b64Encode('flags')])// record.bins.flags == "AUKwBAU="
// Bytes 1-2 only.const span = await client.operate(key, [bw.b64EncodeRange('flags', 1, 2)])// span.bins.flags == "QrA="
// Byte 1 through the end (invertSize with a byteSize of 0).const tail = await client.operate(key, [bw.b64EncodeRange('flags', 1, 0, true)])// tail.bins.flags == "QrAEBQ=="// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
as_operations ops;as_record* rec = NULL;
as_operations_init(&ops, 1);as_operations_bit_b64_encode(&ops, "flags", NULL);aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns "AUKwBAU="as_operations_destroy(&ops);as_record_destroy(rec);rec = NULL;
// Bytes 1-2 only.as_operations_init(&ops, 1);as_operations_bit_b64_encode_range(&ops, "flags", NULL, 1, 2, false);aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns "QrA="as_operations_destroy(&ops);as_record_destroy(rec);rec = NULL;
// Byte 1 through the end (invert_size with a byte_size of 0).as_operations_init(&ops, 1);as_operations_bit_b64_encode_range(&ops, "flags", NULL, 1, 0, true);aerospike_key_operate(&as, &err, NULL, &key, &ops, &rec);// returns "QrAEBQ=="as_operations_destroy(&ops);as_record_destroy(rec);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.b64Encode("flags"));// returns "AUKwBAU="
// Bytes 1-2 only.Record span = client.operate(null, key, BitOperation.b64Encode("flags", 1, 2));// returns "QrA="
// Byte 1 through the end (invertSize with a byteSize of 0).Record tail = client.operate(null, key, BitOperation.b64Encode("flags", 1, 0, true));// returns "QrAEBQ=="# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]from aerospike_helpers.operations import bitwise_operations as bw
_, _, result = client.operate(key, [bw.bit_b64_encode("flags")])# result["flags"] == "AUKwBAU="
# Bytes 1-2 only._, _, span = client.operate(key, [bw.bit_b64_encode("flags", 1, 2)])# span["flags"] == "QrA="
# Byte 1 through the end (invert_size with a byte_size of 0)._, _, tail = client.operate(key, [bw.bit_b64_encode("flags", 1, 0, True)])# tail["flags"] == "QrAEBQ=="count(bin_name, bit_offset, bit_size)Count the number of bits set to 1 in the bit_size 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. |
bit_size | integer | Number of bits to check. |
integer 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 3 — three bits are set in the device ID field.
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
try (RecordStream rs = session.query(key) .bin("flags").bitCount(0, 16) .execute()) { Record rec = rs.next().recordOrThrow(); // returns 3}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]# bits 0-15: 0000 0001 0100 0010
stream = session.query(key).bin("flags").bit_count(0, 16).execute()# returns 3// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]// bits 0-15: 0000 0001 0100 0010
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::count("flags", 0, 16)]).await?;// returns 3// 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 3// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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"] == 3// count is not available in the Node.js bitwise operate API// 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 3as_operations_destroy(&ops);// 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 3# 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"] == 3get(bin_name, bit_offset, bit_size)Retrieve bit_size bits beginning at offset offset. If bit_size is not a multiple of 8 then there will be bit_size 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. |
bit_size | 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]
try (RecordStream rs = session.query(key) .bin("flags").bitGet(16, 8) .execute()) { Record rec = rs.next().recordOrThrow(); // returns [0xB0]}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
stream = session.query(key).bin("flags").bit_get(16, 8).execute()# returns b'\xb0'// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::get("flags", 16, 8)]).await?;// returns Value::Blob(vec![0xB0])// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Get("flags", 16, 8));// returns [0xB0]// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]const bw = Aerospike.bitwise
const ops = [bw.get('flags', 16, 8)]const record = await client.operate(key, ops)// record.bins.flags == <Buffer b0>// 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 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"] == b'\xb0'get_integer(bin_name, bit_offset, bit_size, signed)Retrieve the bit_size 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 |
bit_size | 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]
try (RecordStream rs = session.query(key) .bin("flags").bitGetInt(0, 16, false) .execute()) { Record rec = rs.next().recordOrThrow(); // returns 322 (0x0142 unsigned)}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
stream = session.query(key).bin("flags").bit_get_int(0, 16, False).execute()# returns 322 (0x0142 unsigned)// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::get_int("flags", 0, 16, false)]).await?;// returns 322 (0x0142 unsigned)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.GetInt("flags", 0, 16, false));// returns 322 (0x0142 unsigned)// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]const bw = Aerospike.bitwise
const ops = [bw.getInt('flags', 0, 16, false)]const record = await client.operate(key, ops)// record.bins.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 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"] == 322lscan(bin_name, bit_offset, bit_size, value)Return the position of the first bit equal to value, scanning the bit_size bits at bit_offset from left to right. The position is relative to bit_offset, so 0 is the bit at bit_offset itself. Returns -1 if no bit matches.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first (leftmost) bit to be scanned. |
bit_size | 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]
try (RecordStream rs = session.query(key) .bin("flags").bitLscan(0, 40, true) .execute()) { Record rec = rs.next().recordOrThrow(); // returns 7 (first set bit is at position 7)}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
stream = session.query(key).bin("flags").bit_lscan(0, 40, True).execute()# returns 7 (first set bit is at position 7)// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::lscan("flags", 0, 40, true)]).await?;// returns 7 (first set bit is at position 7)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Lscan("flags", 0, 40, true));// returns 7// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// 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]
// The Node.js client's lscan scans from the right, not the left, so this// example has no Node.js form.// 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 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"] == 7rscan(bin_name, bit_offset, bit_size, value)Return the position of the last bit equal to value, scanning the bit_size bits at bit_offset from right to left. The position is relative to bit_offset, so 0 is the bit at bit_offset itself. Returns -1 if no bit matches.
| Name | Type | Description |
|---|---|---|
bin_name | string | Name of bin. |
bit_offset | integer | Offset (in bits) to the first (leftmost) bit to be scanned. |
bit_size | integer | Number of bits from the |
value | boolean | If true, search for the last set bit. If false, search for the last 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, so its set bits are at positions 37 and 39. Calling rscan("flags", 0, 40, true) returns 39 — the rightmost set bit, counting from position 0 at the left of the scanned range.
// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
try (RecordStream rs = session.query(key) .bin("flags").bitRscan(0, 40, true) .execute()) { Record rec = rs.next().recordOrThrow(); // returns 39 (last set bit is at position 39)}# flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
stream = session.query(key).bin("flags").bit_rscan(0, 40, True).execute()# returns 39 (last set bit is at position 39)// Requires: use aerospike::operations::bitwise;// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
let record = client.operate(&WritePolicy::default(), &key, &[bitwise::rscan("flags", 0, 40, true)]).await?;// returns 39 (last set bit is at position 39)// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.Operate(null, key, BitOperation.Rscan("flags", 0, 40, true));// returns 39// Requires: import as "github.com/aerospike/aerospike-client-go/v8"// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
record, err := client.Operate(nil, key, as.BitRScanOp("flags", 0, 40, true))// record.Bins["flags"] == 39// 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 == 39// 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 39as_operations_destroy(&ops);// flags = [0x01, 0x42, 0xB0, 0x04, 0x05]
Record record = client.operate(null, key, BitOperation.rscan("flags", 0, 40, true));// returns 39 (last set bit is at position 39)# 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"] == 39