use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.
the class MapOperation method putItems.
/**
* Create map put items operation
* Server writes each map item to map bin and returns map size.
* <p>
* The required map policy dictates the type of map to create when it does not exist.
* The map policy also specifies the flags used when writing items to the map.
* See policy {@link com.aerospike.client.cdt.MapPolicy}.
*/
public static Operation putItems(MapPolicy policy, String binName, Map<Value, Value> map, CTX... ctx) {
Packer packer = new Packer();
if (policy.flags != 0) {
Pack.init(packer, ctx);
packer.packArrayBegin(4);
packer.packInt(MapOperation.PUT_ITEMS);
packer.packValueMap(map);
packer.packInt(policy.attributes);
packer.packInt(policy.flags);
} else {
if (policy.itemsCommand == REPLACE_ITEMS) {
// Replace doesn't allow map attributes because it does not create on non-existing key.
Pack.init(packer, ctx);
packer.packArrayBegin(2);
packer.packInt(policy.itemsCommand);
packer.packValueMap(map);
} else {
Pack.init(packer, ctx);
packer.packArrayBegin(3);
packer.packInt(policy.itemsCommand);
packer.packValueMap(map);
packer.packInt(policy.attributes);
}
}
byte[] bytes = packer.toByteArray();
return new Operation(Operation.Type.MAP_MODIFY, binName, Value.get(bytes));
}
use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.
the class MapExp method put.
/**
* Create expression that writes key/value item to map bin.
*/
public static Exp put(MapPolicy policy, Exp key, Exp value, Exp bin, CTX... ctx) {
Packer packer = new Packer();
if (policy.flags != 0) {
Pack.init(packer, ctx);
packer.packArrayBegin(5);
packer.packInt(PUT);
key.pack(packer);
value.pack(packer);
packer.packInt(policy.attributes);
packer.packInt(policy.flags);
} else {
if (policy.itemCommand == REPLACE) {
// Replace doesn't allow map attributes because it does not create on non-existing key.
Pack.init(packer, ctx);
packer.packArrayBegin(3);
packer.packInt(policy.itemCommand);
key.pack(packer);
value.pack(packer);
} else {
Pack.init(packer, ctx);
packer.packArrayBegin(4);
packer.packInt(policy.itemCommand);
key.pack(packer);
value.pack(packer);
packer.packInt(policy.attributes);
}
}
byte[] bytes = packer.toByteArray();
return addWrite(bin, bytes, ctx);
}
use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.
the class MapExp method putItems.
/**
* Create expression that writes each map item to map bin.
*/
public static Exp putItems(MapPolicy policy, Exp map, Exp bin, CTX... ctx) {
Packer packer = new Packer();
if (policy.flags != 0) {
Pack.init(packer, ctx);
packer.packArrayBegin(4);
packer.packInt(PUT_ITEMS);
map.pack(packer);
packer.packInt(policy.attributes);
packer.packInt(policy.flags);
} else {
if (policy.itemsCommand == REPLACE_ITEMS) {
// Replace doesn't allow map attributes because it does not create on non-existing key.
Pack.init(packer, ctx);
packer.packArrayBegin(2);
packer.packInt(policy.itemsCommand);
map.pack(packer);
} else {
Pack.init(packer, ctx);
packer.packArrayBegin(3);
packer.packInt(policy.itemsCommand);
map.pack(packer);
packer.packInt(policy.attributes);
}
}
byte[] bytes = packer.toByteArray();
return addWrite(bin, bytes, ctx);
}
use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.
the class BitOperation method packMath.
private static byte[] packMath(int command, BitPolicy policy, int bitOffset, int bitSize, long value, boolean signed, BitOverflowAction action) {
Packer packer = new Packer();
// Pack.init() only required when CTX is used and server does not support CTX for bit operations.
// Pack.init(packer, ctx);
packer.packArrayBegin(6);
packer.packInt(command);
packer.packInt(bitOffset);
packer.packInt(bitSize);
packer.packLong(value);
packer.packInt(policy.flags);
int flags = action.flags;
if (signed) {
flags |= INT_FLAGS_SIGNED;
}
packer.packInt(flags);
return packer.toByteArray();
}