Search in sources :

Example 21 with Packer

use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.

the class MapOperation method put.

/**
 * Create map put operation.
 * Server writes key/value 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 put(MapPolicy policy, String binName, Value key, Value value, CTX... ctx) {
    Packer packer = new Packer();
    if (policy.flags != 0) {
        Pack.init(packer, ctx);
        packer.packArrayBegin(5);
        packer.packInt(MapOperation.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 new Operation(Operation.Type.MAP_MODIFY, binName, Value.get(bytes));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 22 with Packer

use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.

the class MapOperation method create.

/**
 * Create map create operation.
 * Server creates map at given context level.
 */
public static Operation create(String binName, MapOrder order, CTX... ctx) {
    // If context not defined, the set order for top-level bin map.
    if (ctx == null || ctx.length == 0) {
        return setMapPolicy(new MapPolicy(order, 0), binName);
    }
    Packer packer = new Packer();
    CDT.init(packer, ctx, SET_TYPE, 1, order.flag);
    packer.packInt(order.attributes);
    return new Operation(Operation.Type.MAP_MODIFY, binName, Value.get(packer.toByteArray()));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 23 with Packer

use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.

the class CDT method packRangeOperation.

protected static byte[] packRangeOperation(int command, int returnType, Value begin, Value end, CTX[] ctx) {
    Packer packer = new Packer();
    Pack.init(packer, ctx);
    packer.packArrayBegin((end != null) ? 4 : 3);
    packer.packInt(command);
    packer.packInt(returnType);
    if (begin != null) {
        begin.pack(packer);
    } else {
        packer.packNil();
    }
    if (end != null) {
        end.pack(packer);
    }
    return packer.toByteArray();
}
Also used : Packer(com.aerospike.client.util.Packer)

Example 24 with Packer

use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.

the class ListOperation method create.

/**
 * Create list create operation.
 * Server creates list at given context level. The context is allowed to be beyond list
 * boundaries only if pad is set to true.  In that case, nil list entries will be inserted to
 * satisfy the context position.
 */
public static Operation create(String binName, ListOrder order, boolean pad, CTX... ctx) {
    // If context not defined, the set order for top-level bin list.
    if (ctx == null || ctx.length == 0) {
        return setOrder(binName, order);
    }
    Packer packer = new Packer();
    CDT.init(packer, ctx, SET_TYPE, 1, order.getFlag(pad));
    packer.packInt(order.attributes);
    return new Operation(Operation.Type.CDT_MODIFY, binName, Value.get(packer.toByteArray()));
}
Also used : Operation(com.aerospike.client.Operation) Packer(com.aerospike.client.util.Packer)

Example 25 with Packer

use of com.aerospike.client.util.Packer in project aerospike-client-java by aerospike.

the class BitExp method packGetInt.

private static byte[] packGetInt(Exp bitOffset, Exp bitSize, boolean signed) {
    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(signed ? 4 : 3);
    packer.packInt(GET_INT);
    bitOffset.pack(packer);
    bitSize.pack(packer);
    if (signed) {
        packer.packInt(INT_FLAGS_SIGNED);
    }
    return packer.toByteArray();
}
Also used : Packer(com.aerospike.client.util.Packer)

Aggregations

Packer (com.aerospike.client.util.Packer)44 Operation (com.aerospike.client.Operation)36