/// <summary>
 /// Create list append operation.
 /// Server appends value to end of list bin.
 /// Server returns list size.
 /// </summary>
 public static Operation Append(string binName, Value value)
 {
     Packer packer = new Packer();
     packer.PackRawShort(APPEND);
     packer.PackArrayBegin(1);
     value.Pack(packer);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, IList list, MapReturnType returnType)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     packer.PackArrayBegin(2);
     packer.PackNumber((int)returnType);
     packer.PackList(list);
     return new Operation(type, binName, Value.Get(packer.ToByteArray()));
 }
 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()));
 }
Beispiel #4
0
 public override void Pack(Packer packer)
 {
     packer.PackArrayBegin(2);
     packer.PackNumber(cmd);
     packer.PackString(str);
 }
 public override void Pack(Packer packer)
 {
     packer.PackNumber(value);
 }
 public override void Pack(Packer packer)
 {
     packer.PackBytes(bytes, offset, length);
 }
 public static byte[] Pack(IList val)
 {
     Packer packer = new Packer();
     packer.PackList(val);
     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 == 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()));
        }
Beispiel #9
0
 public override void Pack(Packer packer)
 {
     packer.PackGeoJSON(val);
 }
 public override int EstimateSize()
 {
     bytes = Packer.Pack(map);
     return(bytes.Length);
 }
 public override void Pack(Packer packer)
 {
     packer.PackList(list);
 }
 public override void Pack(Packer packer)
 {
     packer.PackValueArray(array);
 }
 public override void Pack(Packer packer)
 {
     // Do not try to pack bytes field because it will be null
     // when packing objects in a collection (ie. EstimateSize() not called).
     packer.PackBlob(obj);
 }
 /// <summary>
 /// Create 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)
 {
     Packer packer = new Packer();
     packer.PackRawShort(APPEND_ITEMS);
     packer.PackArrayBegin(1);
     packer.PackList(list);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 /// <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));
 }
Beispiel #16
0
 public override void Pack(Packer packer)
 {
     packer.PackBoolean(val);
 }
Beispiel #17
0
 public override void Pack(Packer packer)
 {
     packer.PackDouble(val);
 }
 public override void Pack(Packer packer)
 {
     packer.PackString(value);
 }
Beispiel #19
0
 public override void Pack(Packer packer)
 {
     packer.PackMap(map);
 }
 public override void Pack(Packer packer)
 {
     packer.PackBytes(bytes);
 }
        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()));
        }
 public override void Pack(Packer packer)
 {
     packer.PackBytes(bytes, offset, length);
 }
 public override void Pack(Packer packer)
 {
     packer.PackFloat(value);
 }
 public override void Pack(Packer packer)
 {
     throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Can't pack GeoJSON");
 }
 /// <summary>
 /// Create list size operation.
 /// Server returns size of list.
 /// </summary>
 public static Operation Size(string binName)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SIZE);
     //packer.PackArrayBegin(0);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes));
 }
Beispiel #26
0
        protected internal void SetQuery(Policy policy, Statement statement, bool write)
        {
            byte[] functionArgBuffer = null;
            int    fieldCount        = 0;
            int    filterSize        = 0;
            int    binNameSize       = 0;

            Begin();

            if (statement.ns != null)
            {
                dataOffset += ByteUtil.EstimateSizeUtf8(statement.ns) + FIELD_HEADER_SIZE;
                fieldCount++;
            }

            if (statement.indexName != null)
            {
                dataOffset += ByteUtil.EstimateSizeUtf8(statement.indexName) + FIELD_HEADER_SIZE;
                fieldCount++;
            }

            if (statement.setName != null)
            {
                dataOffset += ByteUtil.EstimateSizeUtf8(statement.setName) + FIELD_HEADER_SIZE;
                fieldCount++;
            }

            // Allocate space for TaskId field.
            dataOffset += 8 + FIELD_HEADER_SIZE;
            fieldCount++;

            if (statement.filter != null)
            {
                IndexCollectionType type = statement.filter.CollectionType;

                if (type != IndexCollectionType.DEFAULT)
                {
                    dataOffset += FIELD_HEADER_SIZE + 1;
                    fieldCount++;
                }

                dataOffset += FIELD_HEADER_SIZE;
                filterSize++;                 // num filters
                filterSize += statement.filter.EstimateSize();
                dataOffset += filterSize;
                fieldCount++;

                // Query bin names are specified as a field (Scan bin names are specified later as operations)
                if (statement.binNames != null && statement.binNames.Length > 0)
                {
                    dataOffset += FIELD_HEADER_SIZE;
                    binNameSize++;                     // num bin names

                    foreach (string binName in statement.binNames)
                    {
                        binNameSize += ByteUtil.EstimateSizeUtf8(binName) + 1;
                    }
                    dataOffset += binNameSize;
                    fieldCount++;
                }
            }
            else
            {
                // Calling query with no filters is more efficiently handled by a primary index scan.
                // Estimate scan options size.
                dataOffset += 2 + FIELD_HEADER_SIZE;
                fieldCount++;

                // Estimate scan timeout size.
                dataOffset += 4 + FIELD_HEADER_SIZE;
                fieldCount++;
            }

            PredExp[] predExp  = statement.PredExp;
            int       predSize = 0;

            if (predExp != null)
            {
                dataOffset += FIELD_HEADER_SIZE;
                predSize    = PredExp.EstimateSize(predExp);
                dataOffset += predSize;
                fieldCount++;
            }

            if (statement.functionName != null)
            {
                dataOffset += FIELD_HEADER_SIZE + 1;                 // udf type
                dataOffset += ByteUtil.EstimateSizeUtf8(statement.packageName) + FIELD_HEADER_SIZE;
                dataOffset += ByteUtil.EstimateSizeUtf8(statement.functionName) + FIELD_HEADER_SIZE;

                if (statement.functionArgs.Length > 0)
                {
                    functionArgBuffer = Packer.Pack(statement.functionArgs);
                }
                else
                {
                    functionArgBuffer = new byte[0];
                }
                dataOffset += FIELD_HEADER_SIZE + functionArgBuffer.Length;
                fieldCount += 4;
            }

            if (statement.filter == null)
            {
                if (statement.binNames != null)
                {
                    foreach (string binName in statement.binNames)
                    {
                        EstimateOperationSize(binName);
                    }
                }
            }

            SizeBuffer();
            int operationCount = (statement.filter == null && statement.binNames != null) ? statement.binNames.Length : 0;

            if (write)
            {
                WriteHeader((WritePolicy)policy, Command.INFO1_READ, Command.INFO2_WRITE, fieldCount, operationCount);
            }
            else
            {
                QueryPolicy qp       = (QueryPolicy)policy;
                int         readAttr = qp.includeBinData ? Command.INFO1_READ : Command.INFO1_READ | Command.INFO1_NOBINDATA;
                WriteHeader(policy, readAttr, 0, fieldCount, operationCount);
            }

            if (statement.ns != null)
            {
                WriteField(statement.ns, FieldType.NAMESPACE);
            }

            if (statement.indexName != null)
            {
                WriteField(statement.indexName, FieldType.INDEX_NAME);
            }

            if (statement.setName != null)
            {
                WriteField(statement.setName, FieldType.TABLE);
            }

            // Write taskId field
            WriteFieldHeader(8, FieldType.TRAN_ID);
            ByteUtil.LongToBytes(statement.taskId, dataBuffer, dataOffset);
            dataOffset += 8;

            if (statement.filter != null)
            {
                IndexCollectionType type = statement.filter.CollectionType;

                if (type != IndexCollectionType.DEFAULT)
                {
                    WriteFieldHeader(1, FieldType.INDEX_TYPE);
                    dataBuffer[dataOffset++] = (byte)type;
                }

                WriteFieldHeader(filterSize, FieldType.INDEX_RANGE);
                dataBuffer[dataOffset++] = (byte)1;
                dataOffset = statement.filter.Write(dataBuffer, dataOffset);

                // Query bin names are specified as a field (Scan bin names are specified later as operations)
                if (statement.binNames != null && statement.binNames.Length > 0)
                {
                    WriteFieldHeader(binNameSize, FieldType.QUERY_BINLIST);
                    dataBuffer[dataOffset++] = (byte)statement.binNames.Length;

                    foreach (string binName in statement.binNames)
                    {
                        int len = ByteUtil.StringToUtf8(binName, dataBuffer, dataOffset + 1);
                        dataBuffer[dataOffset] = (byte)len;
                        dataOffset            += len + 1;
                    }
                }
            }
            else
            {
                // Calling query with no filters is more efficiently handled by a primary index scan.
                WriteFieldHeader(2, FieldType.SCAN_OPTIONS);
                byte priority = (byte)policy.priority;
                priority <<= 4;

                if (!write && ((QueryPolicy)policy).failOnClusterChange)
                {
                    priority |= 0x08;
                }

                dataBuffer[dataOffset++] = priority;
                dataBuffer[dataOffset++] = (byte)100;

                // Write scan timeout
                WriteFieldHeader(4, FieldType.SCAN_TIMEOUT);
                dataOffset += ByteUtil.IntToBytes((uint)policy.socketTimeout, dataBuffer, dataOffset);
            }

            if (predExp != null)
            {
                WriteFieldHeader(predSize, FieldType.PREDEXP);
                dataOffset = PredExp.Write(predExp, dataBuffer, dataOffset);
            }

            if (statement.functionName != null)
            {
                WriteFieldHeader(1, FieldType.UDF_OP);
                dataBuffer[dataOffset++] = (statement.returnData) ? (byte)1 : (byte)2;
                WriteField(statement.packageName, FieldType.UDF_PACKAGE_NAME);
                WriteField(statement.functionName, FieldType.UDF_FUNCTION);
                WriteField(functionArgBuffer, FieldType.UDF_ARGLIST);
            }

            // Scan bin names are specified after all fields.
            if (statement.filter == null)
            {
                if (statement.binNames != null)
                {
                    foreach (string binName in statement.binNames)
                    {
                        WriteOperation(binName, Operation.Type.READ);
                    }
                }
            }
            End();
        }
Beispiel #27
0
 public override void Pack(Packer packer)
 {
     packer.PackBytes(bytes);
 }
Beispiel #28
0
 public override void Pack(Packer packer)
 {
     packer.PackDouble(value);
 }
Beispiel #29
0
 public abstract void Pack(Packer packer);
Beispiel #30
0
 public override void Pack(Packer packer)
 {
     packer.PackFloat(value);
 }
Beispiel #31
0
 public override void Pack(Packer packer)
 {
     packer.PackArrayBegin(1);
     packer.PackNumber(cmd);
 }
Beispiel #32
0
 public override void Pack(Packer packer)
 {
     packer.PackGeoJSON(value);
 }
Beispiel #33
0
 public override void Pack(Packer packer)
 {
     packer.PackNumber(val);
 }
Beispiel #34
0
 public override void Pack(Packer packer)
 {
     packer.PackList(list);
 }
Beispiel #35
0
 public override void Pack(Packer packer)
 {
     packer.PackParticleString(val);
 }
Beispiel #36
0
 public override void Pack(Packer packer)
 {
     packer.PackMap(map);
 }
Beispiel #37
0
 public override void Pack(Packer packer)
 {
     packer.PackParticleBytes(val);
 }
Beispiel #38
0
 public override void Pack(Packer packer)
 {
     packer.PackNil();
 }
Beispiel #39
0
 public override void Pack(Packer packer)
 {
     packer.PackNil();
 }
Beispiel #40
0
 public override void Pack(Packer packer)
 {
     packer.PackString(value);
 }
        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()));
        }
Beispiel #42
0
 public override void Pack(Packer packer)
 {
     packer.PackValueArray(array);
 }
 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()));
 }
Beispiel #44
0
 /// <summary>
 /// Serialize the value using MessagePack.
 /// </summary>
 public abstract void Pack(Packer packer);
 protected internal static Operation CreateOperation(int command, Operation.Type type, string binName)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     return new Operation(type, binName, Value.Get(packer.ToByteArray()));
 }
Beispiel #46
0
 public override void Pack(Packer packer)
 {
     // Do not try to pack bytes field because it will be null
     // when packing objects in a collection (ie. EstimateSize() not called).
     packer.PackBlob(obj);
 }
 public static byte[] Pack(Value[] val)
 {
     Packer packer = new Packer();
     packer.PackValueArray(val);
     return packer.ToByteArray();
 }
Beispiel #48
0
 public override void Pack(Packer packer)
 {
     packer.PackBoolean(value);
 }
 public static byte[] Pack(IDictionary val)
 {
     Packer packer = new Packer();
     packer.PackMap(val);
     return 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));
 }