Skip to content

Blob bin operations

Aerospike blob (bytes) bins support bitwise read and modify operations inside expressions (filters, operate pipelines, and policies that accept expression filters). Use them to read bit ranges, count or scan bits, resize or patch bytes, and apply bitwise math without round-tripping the whole blob to the client.

This reference lists each bit_ expression* (for example bit_get, bit_count, bit_set, bit_add) with multi-language examples. For the underlying datatype and non-expression APIs, see Blob (bytes).

Composing expressions

In each operation, the blob bin operand (blob_bin_expr in the argument tables) can be any blob-valued expression, not only Exp.blobBin(...). The bit_set reference includes an Example that uses BitExp.get on the result of BitExp.set—a read on a temporary blob after a modify. Many other modify (and some read) operations show similar composition: their examples nest another expression as the blob bin operand.

Modify

bit_add

bit_add(policy, bit_offset, bit_size, value, action_flags, bin)
Description

Invokes the add operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value integer_expr
action_flags library_specific
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where adding 1 to the unsigned 8-bit field at bit offset 16 (overflow FAIL) matches reading the next byte at offset 24.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitOverflowAction;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(16),
Exp.val(8),
BitExp.add(
BitPolicy.Default,
Exp.val(16),
Exp.val(8),
Exp.val(1),
false,
BitOverflowAction.FAIL,
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(24), Exp.val(8), Exp.blobBin("device_flags"))));

bit_and

bit_and(policy, bit_offset, bit_size, value, bin)
Description

Invokes the and operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value blob_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where AND-ing bits 16–23 with 0x01 leaves the first byte unchanged.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(0),
Exp.val(8),
BitExp.and(
BitPolicy.Default,
Exp.val(16),
Exp.val(8),
Exp.val(new byte[] {0x01}),
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(0), Exp.val(8), Exp.blobBin("device_flags"))));

bit_insert

bit_insert(policy, bytes_offset, blob, bin)
Description

Invokes the insert operation.

Arguments
NameType
policy library_specific
bytes_offset integer_expr
blob blob_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where inserting 0xFF at byte offset 1 makes the unsigned 8-bit integer at bit offset 8 equal 0xFF.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.getInt(
Exp.val(8),
Exp.val(8),
false,
BitExp.insert(
BitPolicy.Default,
Exp.val(1),
Exp.val(new byte[] {(byte) 0xff}),
Exp.blobBin("device_flags"))),
Exp.val(0xff)));

bit_lshift

bit_lshift(policy, bit_offset, bit_size, shift_bit_count, bin)
Description

Invokes the lshift operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
shift_bit_count integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where shifting the first byte left by two bits preserves the following six bits relative to the unmodified blob (TestBitExp pattern).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(0),
Exp.val(6),
BitExp.lshift(
BitPolicy.Default, Exp.val(0), Exp.val(8), Exp.val(2), Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(2), Exp.val(6), Exp.blobBin("device_flags"))));

bit_not

bit_not(policy, bit_offset, bit_size, bin)
Description

Invokes the not operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where NOT-ing one bit at offset 6 makes the first byte match the original second byte (0x42).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(0),
Exp.val(8),
BitExp.not(BitPolicy.Default, Exp.val(6), Exp.val(1), Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));

bit_or

bit_or(policy, bit_offset, bit_size, value, bin)
Description

Invokes the or operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value blob_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where OR-ing 0x01 into bits 24–31 makes the 8-bit slice at offset 24 match the slice at offset 32.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(24),
Exp.val(8),
BitExp.or(
BitPolicy.Default,
Exp.val(24),
Exp.val(8),
Exp.val(new byte[] {0x01}),
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(32), Exp.val(8), Exp.blobBin("device_flags"))));

bit_remove

bit_remove(policy, bytes_offset, byte_size, bin)
Description

Invokes the remove operation.

Arguments
NameType
policy library_specific
bytes_offset integer_expr
byte_size integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where removing the first byte leaves 0x42 as the unsigned 8-bit value at bit offset 0.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.getInt(
Exp.val(0),
Exp.val(8),
false,
BitExp.remove(BitPolicy.Default, Exp.val(0), Exp.val(1), Exp.blobBin("device_flags"))),
Exp.val(0x42)));

bit_resize

bit_resize(policy, bytes_size, flags, bin)
Description

Invokes the resize operation.

Arguments
NameType
policy library_specific
bytes_size integer_expr
flags library_specific
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where the first byte after resizing device_flags to six bytes (default resize flags) is still 0x01 — modify expressions evaluate on a temporary blob value.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(0),
Exp.val(8),
BitExp.resize(BitPolicy.Default, Exp.val(6), 0, Exp.blobBin("device_flags"))),
Exp.val(new byte[] {0x01})));

bit_rshift

bit_rshift(policy, bit_offset, bit_size, shift_bit_count, bin)
Description

Invokes the rshift operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
shift_bit_count integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where shifting bits 24–31 right by two leaves the following six bits unchanged relative to the original blob.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(26),
Exp.val(6),
BitExp.rshift(
BitPolicy.Default, Exp.val(24), Exp.val(8), Exp.val(2), Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(24), Exp.val(6), Exp.blobBin("device_flags"))));

bit_set

bit_set(policy, bit_offset, bit_size, value, bin)
Description

Invokes the set operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value blob_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where setting one bit at offset 31 makes the 8-bit slice at offset 24 match the original slice at offset 32.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(24),
Exp.val(8),
BitExp.set(
BitPolicy.Default,
Exp.val(31),
Exp.val(1),
Exp.val(new byte[] {(byte) 0x80}),
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(32), Exp.val(8), Exp.blobBin("device_flags"))));

bit_set_int

bit_set_int(policy, bit_offset, bit_size, value, bin)
Description

Invokes the set_integer operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where writing integer 0x42 into bits 24–31 makes that 8-bit slice match the original second byte of device_flags.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(24),
Exp.val(8),
BitExp.setInt(
BitPolicy.Default, Exp.val(24), Exp.val(8), Exp.val(0x42), Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(8), Exp.val(8), Exp.blobBin("device_flags"))));

bit_subtract

bit_subtract(policy, bit_offset, bit_size, value, action_flags, bin)
Description

Invokes the subtract operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value integer_expr
action_flags library_specific
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where subtracting 1 from the unsigned 8-bit field at bit offset 24 (overflow FAIL) matches the field at offset 16.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitOverflowAction;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(24),
Exp.val(8),
BitExp.subtract(
BitPolicy.Default,
Exp.val(24),
Exp.val(8),
Exp.val(1),
false,
BitOverflowAction.FAIL,
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));

bit_xor

bit_xor(policy, bit_offset, bit_size, value, bin)
Description

Invokes the xor operation.

Arguments
NameType
policy library_specific
bit_offset integer_expr
bit_size integer_expr
value blob_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where XOR-ing the first byte with 0x02 yields the same 8-bit slice as bits 16–23 of the original device_flags.

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.operation.BitPolicy;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(
Exp.val(0),
Exp.val(8),
BitExp.xor(
BitPolicy.Default,
Exp.val(0),
Exp.val(8),
Exp.val(new byte[] {0x02}),
Exp.blobBin("device_flags"))),
BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags"))));

Read

bit_count

bit_count(offset, bit_size, bin)
Description

Invokes the count operation.

Arguments
NameType
offset integer_expr
bit_size integer_expr
bin blob_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter where the second byte of device_flags (bits 8–15) has more than one bit set (0x42 in the TestBitExp example pattern).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
Expression exp = Exp.build(
Exp.gt(BitExp.count(Exp.val(8), Exp.val(8), Exp.blobBin("device_flags")), Exp.val(1)));

bit_get

bit_get(offset, bit_size, bin)
Description

Invokes the get operation.

Arguments
NameType
offset integer_expr
bit_size integer_expr
bin blob_bin_expr
Returns
blob_bin
Introduced
5.2.0.4
Example

Filter where bits 16–23 of blob bin device_flags read as one byte equal 0x03 (example layout matches Aerospike client TestBitExp five-byte pattern 01 42 03 04 05).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
Expression exp = Exp.build(
Exp.eq(
BitExp.get(Exp.val(16), Exp.val(8), Exp.blobBin("device_flags")),
Exp.val(new byte[] {0x03})));

bit_get_int

bit_get_int(offset, bit_size, is_signed, bin)
Description

Invokes the get_integer operation.

Arguments
NameType
offset integer_expr
bit_size integer_expr
is_signed boolean_value
bin blob_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter where the signed 8-bit integer at bit offset 32 in device_flags equals 5 (fifth byte 0x05 in the TestBitExp pattern).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
Expression exp = Exp.build(
Exp.eq(
BitExp.getInt(Exp.val(32), Exp.val(8), true, Exp.blobBin("device_flags")),
Exp.val(5)));

bit_lscan

bit_lscan(offset, bit_size, value, bin)
Description

Invokes the lscan operation.

Arguments
NameType
offset integer_expr
bit_size integer_expr
value boolean_expr
bin blob_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter where a left scan for a set bit in the fourth byte of device_flags (bits 32–39) returns index 5 (TestBitExp pattern).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
Expression exp = Exp.build(
Exp.eq(
BitExp.lscan(Exp.val(32), Exp.val(8), Exp.val(true), Exp.blobBin("device_flags")),
Exp.val(5)));

bit_rscan

bit_rscan(offset, bit_size, value, bin)
Description

Invokes the rscan operation.

Arguments
NameType
offset integer_expr
bit_size integer_expr
value boolean_expr
bin blob_bin_expr
Returns
integer_bin
Introduced
5.2.0.4
Example

Filter where a right scan for a set bit in the fourth byte of device_flags returns index 7 (TestBitExp pattern).

import com.aerospike.client.exp.BitExp;
import com.aerospike.client.exp.Expression;
import com.aerospike.client.exp.Exp;
Expression exp = Exp.build(
Exp.eq(
BitExp.rscan(Exp.val(32), Exp.val(8), Exp.val(true), Exp.blobBin("device_flags")),
Exp.val(7)));
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?