Пример #1
0
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, CTX[] ctx, int v1)
        {
            Packer packer = new Packer();

            CDT.Init(packer, ctx, command, 1);
            packer.PackNumber(v1);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Пример #2
0
        public static byte[] Pack(int command, params CTX[] ctx)
        {
            Packer packer = new Packer();

            Init(packer, ctx);
            packer.PackArrayBegin(1);
            packer.PackNumber(command);
            return(packer.ToByteArray());
        }
Пример #3
0
        public static byte[] Pack(int command, Exp v1)
        {
            Packer packer = new Packer();

            packer.PackArrayBegin(2);
            packer.PackNumber(command);
            v1.Pack(packer);
            return(packer.ToByteArray());
        }
Пример #4
0
        protected internal static Operation SetMapPolicy(string binName, int attributes)
        {
            Packer packer = new Packer();

            packer.PackRawShort(SET_TYPE);
            packer.PackArrayBegin(1);
            packer.PackNumber(attributes);
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #5
0
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, int v1)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(1);
            packer.PackNumber(v1);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Пример #6
0
        /// <summary>
        /// Create default list insert items operation.
        /// Server inserts each input list item starting at specified index of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation InsertItems(string binName, int index, IList list, params CTX[] ctx)
        {
            Packer packer = new Packer();

            CDT.Init(packer, ctx, INSERT_ITEMS, 2);
            packer.PackNumber(index);
            packer.PackList(list);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create HLL set union operation.
        /// Server sets union of specified HLL objects with HLL bin.
        /// Server does not return a value.
        /// </summary>
        /// <param name="policy">write policy, use <seealso cref="HLLPolicy.Default"/> for default</param>
        /// <param name="binName">name of bin</param>
        /// <param name="list">list of HLL objects</param>
        public static Operation SetUnion(HLLPolicy policy, string binName, IList <Value.HLLValue> list)
        {
            Packer packer = new Packer();

            Init(packer, SET_UNION, 2);
            packer.PackList((IList)list);
            packer.PackNumber(policy.flags);
            return(new Operation(Operation.Type.HLL_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #8
0
            public override void Pack(Packer packer)
            {
                packer.PackArrayBegin(exps.Length + 1);
                packer.PackNumber(cmd);

                foreach (Exp exp in exps)
                {
                    exp.Pack(packer);
                }
            }
Пример #9
0
 protected internal static Operation CreateOperation(int command, int attributes, string binName, Value value1, Value value2)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     packer.PackArrayBegin(3);
     value1.Pack(packer);
     value2.Pack(packer);
     packer.PackNumber(attributes);
     return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
 }
        /// <summary>
        /// Create default list insert items operation.
        /// Server inserts each input list item starting at specified index of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation InsertItems(string binName, int index, IList list)
        {
            Packer packer = new Packer();

            packer.PackRawShort(INSERT_ITEMS);
            packer.PackArrayBegin(2);
            packer.PackNumber(index);
            packer.PackList(list);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #11
0
        /// <summary>
        /// Create list increment operation.
        /// Server increments list[index] by 1.
        /// Server returns list[index] after incrementing.
        /// </summary>
        public static Operation Increment(string binName, int index)
        {
            Packer packer = new Packer();

            packer.PackRawShort(INCREMENT);
            packer.PackArrayBegin(1);
            packer.PackNumber(index);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
Пример #12
0
        /// <summary>
        /// Create list get range operation.
        /// Server returns items starting at index to the end of list.
        /// </summary>
        public static Operation GetRange(string binName, int index)
        {
            Packer packer = new Packer();

            packer.PackRawShort(GET_RANGE);
            packer.PackArrayBegin(1);
            packer.PackNumber(index);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes)));
        }
Пример #13
0
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, Value value, MapReturnType returnType)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(2);
            packer.PackNumber((int)returnType);
            value.Pack(packer);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Пример #14
0
        private static byte[] PackList(int command, IList <Value.HLLValue> list)
        {
            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(2);
            packer.PackNumber(command);
            packer.PackList((IList)list);
            return(packer.ToByteArray());
        }
Пример #15
0
        /// <summary>
        /// Create list set operation.
        /// Server sets item value at specified index in list bin.
        /// Server does not return a result by default.
        /// </summary>
        public static Operation Set(string binName, int index, Value value)
        {
            Packer packer = new Packer();

            packer.PackRawShort(SET);
            packer.PackArrayBegin(2);
            packer.PackNumber(index);
            value.Pack(packer);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
Пример #16
0
        protected internal static Operation CreateOperation(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(3);
            value1.Pack(packer);
            value2.Pack(packer);
            packer.PackNumber(attributes);
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #17
0
        public static byte[] Pack(int command, Exp v1, Exp v2, Exp v3, params CTX[] ctx)
        {
            Packer packer = new Packer();

            Init(packer, ctx);
            packer.PackArrayBegin(4);
            packer.PackNumber(command);
            v1.Pack(packer);
            v2.Pack(packer);
            v3.Pack(packer);
            return(packer.ToByteArray());
        }
Пример #18
0
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// 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 <see cref="Aerospike.Client.MapPolicy"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map, params CTX[] ctx)
        {
            Packer packer = new Packer();

            if (policy.flags != 0)
            {
                PackUtil.Init(packer, ctx);
                packer.PackArrayBegin(4);
                packer.PackNumber(MapOperation.PUT_ITEMS);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
                packer.PackNumber(policy.flags);
            }
            else
            {
                if (policy.itemsCommand == REPLACE_ITEMS)
                {
                    // Replace doesn't allow map attributes because it does not create on non-existing key.
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(2);
                    packer.PackNumber(policy.itemsCommand);
                    packer.PackMap(map);
                }
                else
                {
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(3);
                    packer.PackNumber(policy.itemsCommand);
                    packer.PackMap(map);
                    packer.PackNumber(policy.attributes);
                }
            }
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes)));
        }
Пример #19
0
        internal static void Init(Packer packer, CTX[] ctx, int command, int count, int flag)
        {
            packer.PackArrayBegin(3);
            packer.PackNumber(0xff);
            packer.PackArrayBegin(ctx.Length * 2);

            CTX c;
            int last = ctx.Length - 1;

            for (int i = 0; i < last; i++)
            {
                c = ctx[i];
                packer.PackNumber(c.id);
                c.value.Pack(packer);
            }

            c = ctx[last];
            packer.PackNumber(c.id | flag);
            c.value.Pack(packer);

            packer.PackArrayBegin(count + 1);
            packer.PackNumber(command);
        }
        /// <summary>
        /// Create map create operation.
        /// Server creates map at given context level.
        /// </summary>
        public static Operation Create(string binName, MapOrder order, params 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, MapWriteMode.UPDATE), binName));
            }

            Packer packer = new Packer();

            CDT.Init(packer, ctx, SET_TYPE, 1, CTX.GetFlag(order));
            packer.PackNumber((int)order);
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #21
0
        /// <summary>
        /// Create default list append items operation.
        /// Server appends each input list item to end of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation AppendItems(string binName, IList list, params CTX[] ctx)
        {
            // Compiler bug prevents calling of this method.
            // byte[] bytes = PackUtil.Pack(ListOperation.APPEND_ITEMS, list, ctx);
            // Duplicate method instead.
            Packer packer = new Packer();

            PackUtil.Init(packer, ctx);
            packer.PackArrayBegin(2);
            packer.PackNumber(ListOperation.APPEND_ITEMS);
            packer.PackList(list);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
Пример #22
0
        /// <summary>
        /// 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.
        /// </summary>
        public static Operation Create(string binName, ListOrder order, bool pad, params 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, CTX.GetFlag(order, pad));
            packer.PackNumber((int)order);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #23
0
        protected internal static Operation CreateRangeOperation(int command, Operation.Type type, string binName, CTX[] ctx, Value begin, Value end, int returnType)
        {
            Packer packer = new Packer();

            if (begin == null)
            {
                begin = Value.AsNull;
            }

            if (end == null)
            {
                CDT.Init(packer, ctx, command, 2);
                packer.PackNumber(returnType);
                begin.Pack(packer);
            }
            else
            {
                CDT.Init(packer, ctx, command, 3);
                packer.PackNumber(returnType);
                begin.Pack(packer);
                end.Pack(packer);
            }
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Пример #24
0
        internal static byte[] PackRangeOperation(int command, int returnType, Value begin, Value end, CTX[] ctx)
        {
            Packer packer = new Packer();

            PackUtil.Init(packer, ctx);
            packer.PackArrayBegin((end != null) ? 4 : 3);
            packer.PackNumber(command);
            packer.PackNumber(returnType);

            if (begin != null)
            {
                begin.Pack(packer);
            }
            else
            {
                packer.PackNil();
            }

            if (end != null)
            {
                end.Pack(packer);
            }
            return(packer.ToByteArray());
        }
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the mode used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
        /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map)
        {
            Packer packer = new Packer();

            packer.PackRawShort(policy.itemsCommand);

            if (policy.itemsCommand == REPLACE_ITEMS)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(1);
                packer.PackMap(map);
            }
            else
            {
                packer.PackArrayBegin(2);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Пример #26
0
        protected internal static Operation CreatePut(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);

            if (command == MapBase.REPLACE)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(2);
                value1.Pack(packer);
                value2.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                value1.Pack(packer);
                value2.Pack(packer);
                packer.PackNumber(attributes);
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
 /// <summary>
 /// Create list get range operation.
 /// Server returns "count" items starting at specified index in list bin.
 /// </summary>
 public static Operation GetRange(string binName, int index, int count)
 {
     Packer packer = new Packer();
     packer.PackRawShort(GET_RANGE);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackNumber(count);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes));
 }
Пример #28
0
 public override void Pack(Packer packer)
 {
     packer.PackArrayBegin(1);
     packer.PackNumber(cmd);
 }
Пример #29
0
 public override void Pack(Packer packer)
 {
     packer.PackNumber(val);
 }
Пример #30
0
        protected internal static Operation CreateRangeOperation(int command, Operation.Type type, string binName, Value begin, Value end, MapReturnType returnType)
        {
            Packer packer = new Packer();
            packer.PackRawShort(command);

            if (begin == null)
            {
                begin = Value.AsNull;
            }

            if (end == null)
            {
                packer.PackArrayBegin(2);
                packer.PackNumber((int)returnType);
                begin.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                packer.PackNumber((int)returnType);
                begin.Pack(packer);
                end.Pack(packer);
            }
            return new Operation(type, binName, Value.Get(packer.ToByteArray()));
        }
 /// <summary>
 /// Create list set operation.
 /// Server sets item value at specified index in list bin.
 /// Server does not return a result by default.
 /// </summary>
 public static Operation Set(string binName, int index, Value value)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SET);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     value.Pack(packer);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 /// <summary>
 /// Create list remove range operation.
 /// Server removes items starting at specified index to the end of list.
 /// Server returns number of items removed.
 /// </summary>
 public static Operation RemoveRange(string binName, int index)
 {
     Packer packer = new Packer();
     packer.PackRawShort(REMOVE_RANGE);
     packer.PackArrayBegin(1);
     packer.PackNumber(index);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 private static void Init(Packer packer, int command, int count)
 {
     packer.PackArrayBegin(count + 1);
     packer.PackNumber(command);
 }
 /// <summary>
 /// Create list trim operation.
 /// Server removes "count" items in list bin that do not fall into range specified
 /// by index and count range.  If the range is out of bounds, then all items will be removed.
 /// Server returns list size after trim.
 /// </summary>
 public static Operation Trim(string binName, int index, int count)
 {
     Packer packer = new Packer();
     packer.PackRawShort(TRIM);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackNumber(count);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
Пример #35
0
 public override void Pack(Packer packer)
 {
     packer.PackNumber(value);
 }
Пример #36
0
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the mode used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode 
        /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map)
        {
            Packer packer = new Packer();
            packer.PackRawShort(policy.itemsCommand);

            if (policy.itemsCommand == MapBase.REPLACE_ITEMS)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(1);
                packer.PackMap(map);
            }
            else
            {
                packer.PackArrayBegin(2);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
            }
            return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
        }
Пример #37
0
 protected internal static Operation SetMapPolicy(string binName, int attributes)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SET_TYPE);
     packer.PackArrayBegin(1);
     packer.PackNumber(attributes);
     return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
 }
Пример #38
0
 public override void Pack(Packer packer)
 {
     packer.PackArrayBegin(2);
     packer.PackNumber(cmd);
     packer.PackString(str);
 }
 /// <summary>
 /// Create list insert items operation.
 /// Server inserts each input list item starting at specified index of list bin. 
 /// Server returns list size.
 /// </summary>
 public static Operation InsertItems(string binName, int index, IList list)
 {
     Packer packer = new Packer();
     packer.PackRawShort(INSERT_ITEMS);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackList(list);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
Пример #40
0
 protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, Value value, MapReturnType returnType)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     packer.PackArrayBegin(2);
     packer.PackNumber((int)returnType);
     value.Pack(packer);
     return new Operation(type, binName, Value.Get(packer.ToByteArray()));
 }
Пример #41
0
        protected internal static Operation CreatePut(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();
            packer.PackRawShort(command);

            if (command == MapBase.REPLACE)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(2);
                value1.Pack(packer);
                value2.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                value1.Pack(packer);
                value2.Pack(packer);
                packer.PackNumber(attributes);
            }
            return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
        }