Exemplo n.º 1
0
        protected internal Record ParseRecord()
        {
            Dictionary <string, object> bins = null;

            for (int i = 0; i < opCount; i++)
            {
                int opSize = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 5;
                byte particleType = dataBuffer[dataOffset];
                dataOffset += 2;
                byte   nameSize = dataBuffer[dataOffset++];
                string name     = ByteUtil.Utf8ToString(dataBuffer, dataOffset, nameSize);
                dataOffset += nameSize;

                int    particleBytesSize = opSize - (4 + nameSize);
                object value             = ByteUtil.BytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);
                dataOffset += particleBytesSize;

                if (bins == null)
                {
                    bins = new Dictionary <string, object>();
                }
                bins[name] = value;
            }
            return(new Record(bins, generation, expiration));
        }
Exemplo n.º 2
0
        protected internal Record ParseRecord()
        {
            Dictionary <string, object> bins = null;

            for (int i = 0; i < opCount; i++)
            {
                ReadBytes(8);
                int  opSize       = ByteUtil.BytesToInt(dataBuffer, 0);
                byte particleType = dataBuffer[5];
                byte nameSize     = dataBuffer[7];

                ReadBytes(nameSize);
                string name = ByteUtil.Utf8ToString(dataBuffer, 0, nameSize);

                int particleBytesSize = (int)(opSize - (4 + nameSize));
                ReadBytes(particleBytesSize);
                object value = ByteUtil.BytesToParticle(particleType, dataBuffer, 0, particleBytesSize);

                if (bins == null)
                {
                    bins = new Dictionary <string, object>();
                }
                bins[name] = value;
            }
            return(new Record(bins, generation, expiration));
        }
        protected internal Record ParseRecordBatch()
        {
            Dictionary <string, object> bins = null;

            for (int i = 0; i < opCount; i++)
            {
                int    opSize       = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                byte   particleType = dataBuffer[dataOffset + 5];
                byte   nameSize     = dataBuffer[dataOffset + 7];
                string name         = ByteUtil.Utf8ToString(dataBuffer, dataOffset + 8, nameSize);
                dataOffset += 4 + 4 + nameSize;

                int    particleBytesSize = (int)(opSize - (4 + nameSize));
                object value             = ByteUtil.BytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);
                dataOffset += particleBytesSize;

                // Currently, the batch command returns all the bins even if a subset of
                // the bins are requested. We have to filter it on the client side.
                // TODO: Filter batch bins on server!
                if (binNames == null || binNames.Contains(name))
                {
                    if (bins == null)
                    {
                        bins = new Dictionary <string, object>();
                    }
                    bins[name] = value;
                }
            }
            return(new Record(bins, generation, expiration));
        }
Exemplo n.º 4
0
        protected internal override void ParseRow(Key key)
        {
#if NETFRAMEWORK
            if (opCount != 1)
            {
                throw new AerospikeException("Query aggregate expected exactly one bin.  Received " + opCount);
            }

            // Parse aggregateValue.
            int opSize = ByteUtil.BytesToInt(dataBuffer, dataOffset);
            dataOffset += 5;
            byte particleType = dataBuffer[dataOffset];
            dataOffset += 2;
            byte   nameSize = dataBuffer[dataOffset++];
            string name     = ByteUtil.Utf8ToString(dataBuffer, dataOffset, nameSize);
            dataOffset += nameSize;

            int particleBytesSize = (int)(opSize - (4 + nameSize));

            if (!name.Equals("SUCCESS"))
            {
                if (name.Equals("FAILURE"))
                {
                    object value = ByteUtil.BytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);
                    throw new AerospikeException(ResultCode.QUERY_GENERIC, value.ToString());
                }
                else
                {
                    throw new AerospikeException(ResultCode.PARSE_ERROR, "Query aggregate expected bin name SUCCESS.  Received " + name);
                }
            }

            object aggregateValue = LuaInstance.BytesToLua(particleType, dataBuffer, dataOffset, particleBytesSize);
            dataOffset += particleBytesSize;

            if (!valid)
            {
                throw new AerospikeException.QueryTerminated();
            }

            if (aggregateValue != null)
            {
                try
                {
                    inputQueue.Add(aggregateValue, cancelToken);
                }
                catch (OperationCanceledException)
                {
                }
            }
#endif
        }
        private Record ParseRecord(int opCount, int fieldCount, int generation, int expiration)
        {
            Dictionary <string, object> bins = null;

            // There can be fields in the response (setname etc).
            // But for now, ignore them. Expose them to the API if needed in the future.
            if (fieldCount != 0)
            {
                // Just skip over all the fields
                for (int i = 0; i < fieldCount; i++)
                {
                    int fieldSize = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                    dataOffset += 4 + fieldSize;
                }
            }

            for (int i = 0; i < opCount; i++)
            {
                int opSize = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 5;
                byte particleType = dataBuffer[dataOffset];
                dataOffset += 2;
                byte   nameSize = dataBuffer[dataOffset++];
                string name     = ByteUtil.Utf8ToString(dataBuffer, dataOffset, nameSize);
                dataOffset += nameSize;

                int    particleBytesSize = (int)(opSize - (4 + nameSize));
                object value             = ByteUtil.BytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);
                dataOffset += particleBytesSize;

                if (bins == null)
                {
                    bins = new Dictionary <string, object>();
                }
                AddBin(bins, name, value);
            }
            return(new Record(bins, generation, expiration));
        }
        /// <summary>
        /// Parses the given byte buffer and populate the result object.
        /// Returns the number of bytes that were parsed from the given buffer.
        /// </summary>
        private Record ParseRecord(int opCount, int generation, int expiration)
        {
            Dictionary <string, object> bins = null;

            for (int i = 0; i < opCount; i++)
            {
                if (!valid)
                {
                    throw new AerospikeException.QueryTerminated();
                }

                ReadBytes(8);
                int  opSize       = ByteUtil.BytesToInt(dataBuffer, 0);
                byte particleType = dataBuffer[5];
                byte nameSize     = dataBuffer[7];

                ReadBytes(nameSize);
                string name = ByteUtil.Utf8ToString(dataBuffer, 0, nameSize);

                int particleBytesSize = (int)(opSize - (4 + nameSize));
                ReadBytes(particleBytesSize);
                object value = ByteUtil.BytesToParticle(particleType, dataBuffer, 0, particleBytesSize);

                // Currently, the batch command returns all the bins even if a subset of
                // the bins are requested. We have to filter it on the client side.
                // TODO: Filter batch bins on server!
                if (binNames == null || binNames.Contains(name))
                {
                    if (bins == null)
                    {
                        bins = new Dictionary <string, object>();
                    }
                    bins[name] = value;
                }
            }
            return(new Record(bins, generation, expiration));
        }
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            // Read/parse remaining message bytes one record at a time.
            dataOffset = 0;

            while (dataOffset < receiveSize)
            {
                ReadBytes(MSG_REMAINING_HEADER_SIZE);
                int resultCode = dataBuffer[5];

                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                    {
                        return(false);
                    }
                    throw new AerospikeException(resultCode);
                }

                byte info3 = dataBuffer[3];

                // If this is the end marker of the response, do not proceed further
                if ((info3 & Command.INFO3_LAST) == Command.INFO3_LAST)
                {
                    return(false);
                }

                int fieldCount = ByteUtil.BytesToShort(dataBuffer, 18);
                int opCount    = ByteUtil.BytesToShort(dataBuffer, 20);

                ParseKey(fieldCount);

                if (opCount != 1)
                {
                    throw new AerospikeException("Query aggregate expected exactly one bin.  Received " + opCount);
                }

                // Parse aggregateValue.
                ReadBytes(8);
                int  opSize       = ByteUtil.BytesToInt(dataBuffer, 0);
                byte particleType = dataBuffer[5];
                byte nameSize     = dataBuffer[7];

                ReadBytes(nameSize);
                string name = ByteUtil.Utf8ToString(dataBuffer, 0, nameSize);

                int particleBytesSize = (int)(opSize - (4 + nameSize));
                ReadBytes(particleBytesSize);

                if (!name.Equals("SUCCESS"))
                {
                    if (name.Equals("FAILURE"))
                    {
                        object value = ByteUtil.BytesToParticle(particleType, dataBuffer, 0, particleBytesSize);
                        throw new AerospikeException(ResultCode.QUERY_GENERIC, value.ToString());
                    }
                    else
                    {
                        throw new AerospikeException(ResultCode.QUERY_GENERIC, "Query aggregate expected bin name SUCCESS.  Received " + name);
                    }
                }

                object aggregateValue = LuaInstance.BytesToLua(particleType, dataBuffer, 0, particleBytesSize);

                if (!valid)
                {
                    throw new AerospikeException.QueryTerminated();
                }

                if (aggregateValue != null)
                {
                    try
                    {
                        inputQueue.Add(aggregateValue, cancelToken);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                }
            }
            return(true);
        }
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            // Read/parse remaining message bytes one record at a time.
            dataOffset = 0;

            while (dataOffset < receiveSize)
            {
                ReadBytes(MSG_REMAINING_HEADER_SIZE);
                int resultCode = dataBuffer[5];

                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                    {
                        return(false);
                    }
                    throw new AerospikeException(resultCode);
                }

                byte info3 = dataBuffer[3];

                // If this is the end marker of the response, do not proceed further
                if ((info3 & Command.INFO3_LAST) == Command.INFO3_LAST)
                {
                    return(false);
                }

                int generation = ByteUtil.BytesToInt(dataBuffer, 6);
                int expiration = ByteUtil.BytesToInt(dataBuffer, 10);
                int fieldCount = ByteUtil.BytesToShort(dataBuffer, 18);
                int opCount    = ByteUtil.BytesToShort(dataBuffer, 20);

                Key key = ParseKey(fieldCount);

                // Parse bins.
                Dictionary <string, object> bins = null;

                for (int i = 0; i < opCount; i++)
                {
                    ReadBytes(8);
                    int  opSize       = ByteUtil.BytesToInt(dataBuffer, 0);
                    byte particleType = dataBuffer[5];
                    byte nameSize     = dataBuffer[7];

                    ReadBytes(nameSize);
                    string name = ByteUtil.Utf8ToString(dataBuffer, 0, nameSize);

                    int particleBytesSize = (int)(opSize - (4 + nameSize));
                    ReadBytes(particleBytesSize);
                    object value = ByteUtil.BytesToParticle(particleType, dataBuffer, 0, particleBytesSize);

                    if (bins == null)
                    {
                        bins = new Dictionary <string, object>();
                    }
                    bins[name] = value;
                }

                if (!valid)
                {
                    throw new AerospikeException.ScanTerminated();
                }

                // Call the callback function.
                callback(key, new Record(bins, generation, expiration));
            }
            return(true);
        }