Esempio n. 1
0
        public object UnpackMap()
        {
            if (length <= 0)
            {
                return(new Dictionary <object, object>(0));
            }

            int type = buffer[offset++];
            int count;

            if ((type & 0xf0) == 0x80)
            {
                count = type & 0x0f;
            }
            else if (type == 0xde)
            {
                count   = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
            }
            else if (type == 0xdf)
            {
                count   = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
            }
            else
            {
                return(new Dictionary <object, object>(0));
            }
            return(UnpackMap(count));
        }
Esempio n. 2
0
        public object UnpackList()
        {
            if (length <= 0)
            {
                return(new List <object>(0));
            }

            int type = buffer[offset++];
            int count;

            if ((type & 0xf0) == 0x90)
            {
                count = type & 0x0f;
            }
            else if (type == 0xdc)
            {
                count   = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
            }
            else if (type == 0xdd)
            {
                count   = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
            }
            else
            {
                return(new List <object>(0));
            }
            return(UnpackList(count));
        }
        protected internal sealed override void ParseResult()
        {
            int resultCode = dataBuffer[5];
            int generation = ByteUtil.BytesToInt(dataBuffer, 6);
            int expiration = ByteUtil.BytesToInt(dataBuffer, 10);
            int fieldCount = ByteUtil.BytesToShort(dataBuffer, 18);
            int opCount    = ByteUtil.BytesToShort(dataBuffer, 20);

            dataOffset = Command.MSG_REMAINING_HEADER_SIZE;

            if (resultCode == 0)
            {
                if (opCount == 0)
                {
                    // Bin data was not returned.
                    record = new Record(null, generation, expiration);
                }
                else
                {
                    record = ParseRecord(opCount, fieldCount, generation, expiration);
                }
            }
            else
            {
                if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    record = null;
                }
                else
                {
                    throw new AerospikeException(resultCode);
                }
            }
        }
 public int GetShortBig(int offset)
 {
     if (offset < 0 || offset > this.length)
     {
         return(0);
     }
     return(ByteUtil.BytesToShort(bytes, offset));
 }
Esempio n. 5
0
        protected internal override void ParseResult(Connection conn)
        {
            // Read header.
            conn.ReadFully(dataBuffer, MSG_TOTAL_HEADER_SIZE);

            long sz           = ByteUtil.BytesToLong(dataBuffer, 0);
            byte headerLength = dataBuffer[8];
            int  resultCode   = dataBuffer[13];
            int  generation   = ByteUtil.BytesToInt(dataBuffer, 14);
            int  expiration   = ByteUtil.BytesToInt(dataBuffer, 18);
            int  fieldCount   = ByteUtil.BytesToShort(dataBuffer, 26);          // almost certainly 0
            int  opCount      = ByteUtil.BytesToShort(dataBuffer, 28);
            int  receiveSize  = ((int)(sz & 0xFFFFFFFFFFFFL)) - headerLength;

            // Read remaining message bytes.
            if (receiveSize > 0)
            {
                SizeBuffer(receiveSize);
                conn.ReadFully(dataBuffer, receiveSize);
            }

            if (resultCode == 0)
            {
                if (opCount == 0)
                {
                    // Bin data was not returned.
                    record = new Record(null, generation, expiration);
                    return;
                }
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                return;
            }

            if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
            {
                HandleNotFound(resultCode);
                return;
            }

            if (resultCode == ResultCode.FILTERED_OUT)
            {
                if (policy.failOnFilteredOut)
                {
                    throw new AerospikeException(resultCode);
                }
                return;
            }

            if (resultCode == ResultCode.UDF_BAD_RESPONSE)
            {
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                HandleUdfError(resultCode);
                return;
            }

            throw new AerospikeException(resultCode);
        }
Esempio n. 6
0
        /// <summary>
        /// Parse all results in the batch.  Add records to shared list.
        /// If the record was not found, the bins will be null.
        /// </summary>
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            //Parse each message response and add it to the result array
            dataOffset = 0;

            while (dataOffset < receiveSize)
            {
                if (!valid)
                {
                    throw new AerospikeException.QueryTerminated();
                }

                ReadBytes(MSG_REMAINING_HEADER_SIZE);
                int resultCode = dataBuffer[5];

                // The only valid server return codes are "ok" and "not found".
                // If other return codes are received, then abort the batch.
                if (resultCode != 0 && resultCode != ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    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);

                if (opCount > 0)
                {
                    throw new AerospikeException.Parse("Received bins that were not requested!");
                }

                Key key    = ParseKey(fieldCount);
                int offset = batch.offsets[index++];

                if (Util.ByteArrayEquals(key.digest, keys[offset].digest))
                {
                    existsArray[offset] = resultCode == 0;
                }
                else
                {
                    throw new AerospikeException.Parse("Unexpected batch key returned: " + key.ns + ',' + ByteUtil.BytesToHexString(key.digest) + ',' + index + ',' + offset);
                }
            }
            return(true);
        }
Esempio n. 7
0
        private bool ParseGroup()
        {
            // Parse each message response and add it to the result array
            while (dataOffset < dataLength)
            {
                dataOffset += 3;
                info3       = dataBuffer[dataOffset];
                dataOffset += 2;
                resultCode  = dataBuffer[dataOffset];

                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR || resultCode == ResultCode.FILTERED_OUT)
                    {
                        if (stopOnNotFound)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        throw new AerospikeException(resultCode);
                    }
                }

                // If this is the end marker of the response, do not proceed further
                if ((info3 & Command.INFO3_LAST) != 0)
                {
                    return(true);
                }
                dataOffset++;
                generation  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                expiration  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                batchIndex  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                fieldCount  = ByteUtil.BytesToShort(dataBuffer, dataOffset);
                dataOffset += 2;
                opCount     = ByteUtil.BytesToShort(dataBuffer, dataOffset);
                dataOffset += 2;

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

                Key key = ParseKey(fieldCount);
                ParseRow(key);
            }
            return(false);
        }
        public static object BytesToLua(int type, byte[] buf, int offset, int len)
        {
            if (len <= 0)
            {
                return(null);
            }

            switch (type)
            {
            case ParticleType.STRING:
                return(ByteUtil.Utf8ToString(buf, offset, len));

            case ParticleType.INTEGER:
                return(ByteUtil.BytesToNumber(buf, offset, len));

            case ParticleType.DOUBLE:
                return(ByteUtil.BytesToDouble(buf, offset));

            case ParticleType.BLOB:
                byte[] dest = new byte[len];
                Array.Copy(buf, offset, dest, 0, len);
                return(new LuaBytes(dest));

            case ParticleType.CSHARP_BLOB:
                return(ByteUtil.BytesToObject(buf, offset, len));

            case ParticleType.LIST:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackList());
            }

            case ParticleType.MAP:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackMap());
            }

            case ParticleType.GEOJSON:
            {
                // skip the flags
                int ncells = ByteUtil.BytesToShort(buf, offset + 1);
                int hdrsz  = 1 + 2 + (ncells * 8);
                return(new LuaGeoJSON(ByteUtil.Utf8ToString(buf, offset + hdrsz, len - hdrsz)));
            }

            default:
                return(null);
            }
        }
Esempio n. 9
0
        private bool ParseGroup(int receiveSize)
        {
            while (dataOffset < receiveSize)
            {
                dataOffset += 3;
                info3       = dataBuffer[dataOffset];
                dataOffset += 2;
                resultCode  = dataBuffer[dataOffset];

                // The only valid server return codes are "ok" and "not found".
                // If other return codes are received, then abort the batch.
                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR || resultCode == ResultCode.FILTERED_OUT)
                    {
                        if (stopOnNotFound)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        throw new AerospikeException(resultCode);
                    }
                }

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

                dataOffset++;
                generation  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                expiration  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                batchIndex  = ByteUtil.BytesToInt(dataBuffer, dataOffset);
                dataOffset += 4;
                fieldCount  = ByteUtil.BytesToShort(dataBuffer, dataOffset);
                dataOffset += 2;
                opCount     = ByteUtil.BytesToShort(dataBuffer, dataOffset);
                dataOffset += 2;

                Key key = ParseKey(fieldCount);
                ParseRow(key);
            }
            return(true);
        }
        private bool ParseGroup()
        {
            // Parse each message response and add it to the result array
            dataOffset = 0;

            while (dataOffset < dataLength)
            {
                resultCode = dataBuffer[dataOffset + 5];

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

                // If this is the end marker of the response, do not proceed further
                if ((dataBuffer[dataOffset + 3] & Command.INFO3_LAST) != 0)
                {
                    return(true);
                }
                generation = ByteUtil.BytesToInt(dataBuffer, dataOffset + 6);
                expiration = ByteUtil.BytesToInt(dataBuffer, dataOffset + 10);
                batchIndex = ByteUtil.BytesToInt(dataBuffer, dataOffset + 14);
                fieldCount = ByteUtil.BytesToShort(dataBuffer, dataOffset + 18);
                opCount    = ByteUtil.BytesToShort(dataBuffer, dataOffset + 20);

                dataOffset += Command.MSG_REMAINING_HEADER_SIZE;

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

                Key key = ParseKey();
                ParseRow(key);
            }
            return(false);
        }
Esempio n. 11
0
        protected internal sealed override void ParseResult()
        {
            int resultCode = dataBuffer[dataOffset + 5];
            int generation = ByteUtil.BytesToInt(dataBuffer, dataOffset + 6);
            int expiration = ByteUtil.BytesToInt(dataBuffer, dataOffset + 10);
            int fieldCount = ByteUtil.BytesToShort(dataBuffer, dataOffset + 18);
            int opCount    = ByteUtil.BytesToShort(dataBuffer, dataOffset + 20);

            dataOffset += Command.MSG_REMAINING_HEADER_SIZE;

            if (resultCode == 0)
            {
                if (opCount == 0)
                {
                    // Bin data was not returned.
                    record = new Record(null, generation, expiration);
                    return;
                }
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                return;
            }

            if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
            {
                HandleNotFound(resultCode);
                return;
            }

            if (resultCode == ResultCode.FILTERED_OUT)
            {
                if (policy.failOnFilteredOut)
                {
                    throw new AerospikeException(resultCode);
                }
                return;
            }

            if (resultCode == ResultCode.UDF_BAD_RESPONSE)
            {
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                HandleUdfError(resultCode);
                return;
            }

            throw new AerospikeException(resultCode);
        }
Esempio n. 12
0
        private bool ParseGroup(int receiveSize)
        {
            //Parse each message response and add it to the result array
            dataOffset = 0;

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

                // The only valid server return codes are "ok" and "not found".
                // If other return codes are received, then abort the batch.
                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                    {
                        if (stopOnNotFound)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        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);
                }

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

                Key key = ParseKey(fieldCount);
                ParseRow(key);
            }
            return(true);
        }
        /// <summary>
        /// Parse all results in the batch.  Add records to shared list.
        /// If the record was not found, the bins will be null.
        /// </summary>
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            //Parse each message response and add it to the result array
            dataOffset = 0;

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

                // The only valid server return codes are "ok" and "not found".
                // If other return codes are received, then abort the batch.
                if (resultCode != 0 && resultCode != ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    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);

                if (!Util.ByteArrayEquals(key.digest, keys[index].digest))
                {
                    Log.Warn("Returned batch keys not in same order.");
                }

                if (resultCode == 0)
                {
                    records[index] = ParseRecord(opCount, generation, expiration);
                }
                index++;
            }
            return(true);
        }
        protected internal override void ParseResult(Connection conn)
        {
            // Read header.
            conn.ReadFully(dataBuffer, 8);

            long sz          = ByteUtil.BytesToLong(dataBuffer, 0);
            int  receiveSize = (int)(sz & 0xFFFFFFFFFFFFL);

            if (receiveSize <= 0)
            {
                throw new AerospikeException("Invalid receive size: " + receiveSize);
            }

            SizeBuffer(receiveSize);
            conn.ReadFully(dataBuffer, receiveSize);
            conn.UpdateLastUsed();

            ulong type = (ulong)((sz >> 48) & 0xff);

            if (type == Command.AS_MSG_TYPE)
            {
                dataOffset = 5;
            }
            else if (type == Command.MSG_TYPE_COMPRESSED)
            {
                int    usize = (int)ByteUtil.BytesToLong(dataBuffer, 0);
                byte[] ubuf  = new byte[usize];

                ByteUtil.Decompress(dataBuffer, 8, receiveSize, ubuf, usize);
                dataBuffer = ubuf;
                dataOffset = 13;
            }
            else
            {
                throw new AerospikeException("Invalid proto type: " + type + " Expected: " + Command.AS_MSG_TYPE);
            }

            int resultCode = dataBuffer[dataOffset];

            dataOffset++;
            int generation = ByteUtil.BytesToInt(dataBuffer, dataOffset);

            dataOffset += 4;
            int expiration = ByteUtil.BytesToInt(dataBuffer, dataOffset);

            dataOffset += 8;
            int fieldCount = ByteUtil.BytesToShort(dataBuffer, dataOffset);

            dataOffset += 2;
            int opCount = ByteUtil.BytesToShort(dataBuffer, dataOffset);

            dataOffset += 2;

            if (resultCode == 0)
            {
                if (opCount == 0)
                {
                    // Bin data was not returned.
                    record = new Record(null, generation, expiration);
                    return;
                }
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                return;
            }

            if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
            {
                HandleNotFound(resultCode);
                return;
            }

            if (resultCode == ResultCode.FILTERED_OUT)
            {
                if (policy.failOnFilteredOut)
                {
                    throw new AerospikeException(resultCode);
                }
                return;
            }

            if (resultCode == ResultCode.UDF_BAD_RESPONSE)
            {
                record = ParseRecord(opCount, fieldCount, generation, expiration);
                HandleUdfError(resultCode);
                return;
            }

            throw new AerospikeException(resultCode);
        }
        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);
        }
Esempio n. 17
0
        private object UnpackObject()
        {
            int type = buffer[offset++];

            switch (type)
            {
            case 0xc0:                     // nil
            {
                return(null);
            }

            case 0xc3:                     // boolean true
            {
                return(true);
            }

            case 0xc2:                     // boolean false
            {
                return(false);
            }

            case 0xca:                     // float
            {
                float val = ByteUtil.BytesToFloat(buffer, offset);
                offset += 4;
                return(val);
            }

            case 0xcb:                     // double
            {
                double val = ByteUtil.BytesToDouble(buffer, offset);
                offset += 8;
                return(val);
            }

            case 0xd0:                     // signed 8 bit integer
            {
                return((long)(sbyte)(buffer[offset++]));
            }

            case 0xcc:                     // unsigned 8 bit integer
            {
                return((long)(buffer[offset++]));
            }

            case 0xd1:                     // signed 16 bit integer
            {
                int val = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
                return((long)(short)val);
            }

            case 0xcd:                     // unsigned 16 bit integer
            {
                int val = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
                return((long)val);
            }

            case 0xd2:                     // signed 32 bit integer
            {
                int val = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
                return((long)val);
            }

            case 0xce:                     // unsigned 32 bit integer
            {
                uint val = ByteUtil.BytesToUInt(buffer, offset);
                offset += 4;
                return((long)val);
            }

            case 0xd3:                     // signed 64 bit integer
            {
                long val = ByteUtil.BytesToLong(buffer, offset);
                offset += 8;
                return(val);
            }

            case 0xcf:                     // unsigned 64 bit integer
            {
                // The contract is to always return long.
                // The caller can always cast back to ulong.
                long val = ByteUtil.BytesToLong(buffer, offset);
                offset += 8;
                return(val);
            }

            case 0xda:                     // raw bytes with 16 bit header
            {
                int count = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
                return(UnpackBlob(count));
            }

            case 0xdb:                     // raw bytes with 32 bit header
            {
                // Array length is restricted to positive int values (0 - int.MAX_VALUE).
                int count = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
                return(UnpackBlob(count));
            }

            case 0xdc:                     // list with 16 bit header
            {
                int count = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
                return(UnpackList(count));
            }

            case 0xdd:                     // list with 32 bit header
            {
                // List size is restricted to positive int values (0 - int.MAX_VALUE).
                int count = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
                return(UnpackList(count));
            }

            case 0xde:                     // map with 16 bit header
            {
                int count = ByteUtil.BytesToShort(buffer, offset);
                offset += 2;
                return(UnpackMap(count));
            }

            case 0xdf:                     // map with 32 bit header
            {
                // Map size is restricted to positive int values (0 - int.MAX_VALUE).
                int count = ByteUtil.BytesToInt(buffer, offset);
                offset += 4;
                return(UnpackMap(count));
            }

            default:
            {
                if ((type & 0xe0) == 0xa0)                         // raw bytes with 8 bit combined header
                {
                    return(UnpackBlob(type & 0x1f));
                }

                if ((type & 0xf0) == 0x80)                         // map with 8 bit combined header
                {
                    return(UnpackMap(type & 0x0f));
                }

                if ((type & 0xf0) == 0x90)                         // list with 8 bit combined header
                {
                    return(UnpackList(type & 0x0f));
                }

                if (type < 0x80)                         // 8 bit combined unsigned integer
                {
                    return((long)type);
                }

                if (type >= 0xe0)                         // 8 bit combined signed integer
                {
                    return((long)(type - 0xe0 - 32));
                }
                throw new IOException("Unknown unpack type: " + type);
            }
            }
        }