Exemplo n.º 1
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
        }
        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);
        }