コード例 #1
0
        private double internalReadDouble(int code)
        {
            switch (code)
            {
            case Codes.DOUBLE:
                return(rawInput.readRawDouble());

            case Codes.DOUBLE_0:
                return(0.0D);

            case Codes.DOUBLE_1:
                return(1.0D);

            default:
            {
                Object o = read(code);
                if (o is Double)
                {
                    return((Double)o);
                }
                else
                {
                    throw Fns.expected("double", code, o);
                }
            }
            }
        }
コード例 #2
0
        private byte[] internalReadChunkedBytes()
        {
            IList <byte[]> chunks = new List <byte[]>();
            int            code   = Codes.BYTES_CHUNK;

            while (code == Codes.BYTES_CHUNK)
            {
                chunks.Add(internalReadBytes(readCount()));
                code = readNextCode();
            }
            if (code != Codes.BYTES)
            {
                throw Fns.expected("conclusion of chunked bytes", code);
            }
            chunks.Add(internalReadBytes(readCount()));
            int length = 0;

            for (int n = 0; n < chunks.Count; n++)
            {
                length = length + chunks[n].Length;
            }
            byte[] result = new byte[length];
            int    pos    = 0;

            for (int n = 0; n < chunks.Count; n++)
            {
                Array.Copy(chunks[n], 0, result, pos, chunks[n].Length);
                pos += chunks[n].Length;
            }
            return(result);
        }
コード例 #3
0
        public bool readBoolean()
        {
            int code = readNextCode();

            switch (code)
            {
            case Codes.TRUE:
                return(true);

            case Codes.FALSE:
                return(false);

            default:
            {
                Object result = read(code);
                if (result is Boolean)
                {
                    return((Boolean)result);
                }
                else
                {
                    throw Fns.expected("boolean", code, result);
                }
            }
            }
        }
コード例 #4
0
        public float readFloat()
        {
            int   code = readNextCode();
            float result;

            switch (code)
            {
            case Codes.FLOAT:
                result = rawInput.readRawFloat();
                break;

            default:
            {
                Object o = read(code);
                if (o is Single)
                {
                    return((Single)o);
                }
                else
                {
                    throw Fns.expected("float", code, o);
                }
            }
            }
            return(result);
        }
コード例 #5
0
        private String internalReadChunkedString(int length)
        {
            StringBuilder buf  = internalReadString(length);
            bool          done = false;

            while (!done)
            {
                int code = readNextCode();
                switch (code)
                {
                case Codes.STRING_PACKED_LENGTH_START + 0:
                case Codes.STRING_PACKED_LENGTH_START + 1:
                case Codes.STRING_PACKED_LENGTH_START + 2:
                case Codes.STRING_PACKED_LENGTH_START + 3:
                case Codes.STRING_PACKED_LENGTH_START + 4:
                case Codes.STRING_PACKED_LENGTH_START + 5:
                case Codes.STRING_PACKED_LENGTH_START + 6:
                case Codes.STRING_PACKED_LENGTH_START + 7:
                    internalReadStringBuffer(buf, code - Codes.STRING_PACKED_LENGTH_START).ToString();
                    done = true;
                    break;

                case Codes.STRING:
                    internalReadStringBuffer(buf, readCount());
                    done = true;
                    break;

                case Codes.STRING_CHUNK:
                    internalReadStringBuffer(buf, readCount());
                    break;

                default:
                    throw Fns.expected("chunked string", code);
                }
            }
            return(buf.ToString());
        }
コード例 #6
0
        private long internalReadInt()
        {
            long result;
            int  code = readNextCode();

            switch (code)
            {
            //INT_PACKED_1_FIRST
            case 0xFF:
                result = -1;
                break;

            case 0x00:
            case 0x01:
            case 0x02:
            case 0x03:
            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
            case 0x08:
            case 0x09:
            case 0x0A:
            case 0x0B:
            case 0x0C:
            case 0x0D:
            case 0x0E:
            case 0x0F:
            case 0x10:
            case 0x11:
            case 0x12:
            case 0x13:
            case 0x14:
            case 0x15:
            case 0x16:
            case 0x17:
            case 0x18:
            case 0x19:
            case 0x1A:
            case 0x1B:
            case 0x1C:
            case 0x1D:
            case 0x1E:
            case 0x1F:
            case 0x20:
            case 0x21:
            case 0x22:
            case 0x23:
            case 0x24:
            case 0x25:
            case 0x26:
            case 0x27:
            case 0x28:
            case 0x29:
            case 0x2A:
            case 0x2B:
            case 0x2C:
            case 0x2D:
            case 0x2E:
            case 0x2F:
            case 0x30:
            case 0x31:
            case 0x32:
            case 0x33:
            case 0x34:
            case 0x35:
            case 0x36:
            case 0x37:
            case 0x38:
            case 0x39:
            case 0x3A:
            case 0x3B:
            case 0x3C:
            case 0x3D:
            case 0x3E:
            case 0x3F:
                result = (long)code & 0xff;
                break;

            //  INT_PACKED_2_FIRST
            case 0x40:
            case 0x41:
            case 0x42:
            case 0x43:
            case 0x44:
            case 0x45:
            case 0x46:
            case 0x47:
            case 0x48:
            case 0x49:
            case 0x4A:
            case 0x4B:
            case 0x4C:
            case 0x4D:
            case 0x4E:
            case 0x4F:
            case 0x50:
            case 0x51:
            case 0x52:
            case 0x53:
            case 0x54:
            case 0x55:
            case 0x56:
            case 0x57:
            case 0x58:
            case 0x59:
            case 0x5A:
            case 0x5B:
            case 0x5C:
            case 0x5D:
            case 0x5E:
            case 0x5F:
                result = ((long)(code - Codes.INT_PACKED_2_ZERO) << 8) | rawInput.readRawInt8();
                break;

            //  INT_PACKED_3_FIRST
            case 0x60:
            case 0x61:
            case 0x62:
            case 0x63:
            case 0x64:
            case 0x65:
            case 0x66:
            case 0x67:
            case 0x68:
            case 0x69:
            case 0x6A:
            case 0x6B:
            case 0x6C:
            case 0x6D:
            case 0x6E:
            case 0x6F:
                result = ((long)(code - Codes.INT_PACKED_3_ZERO) << 16) | rawInput.readRawInt16();
                break;

            //  INT_PACKED_4_FIRST
            case 0x70:
            case 0x71:
            case 0x72:
            case 0x73:
                result = ((long)(code - Codes.INT_PACKED_4_ZERO << 24)) | rawInput.readRawInt24();
                break;

            //  INT_PACKED_5_FIRST
            case 0x74:
            case 0x75:
            case 0x76:
            case 0x77:
                result = ((long)(code - Codes.INT_PACKED_5_ZERO) << 32) | rawInput.readRawInt32();
                break;

            //  INT_PACKED_6_FIRST
            case 0x78:
            case 0x79:
            case 0x7A:
            case 0x7B:
                result = (((long)code - Codes.INT_PACKED_6_ZERO) << 40) | rawInput.readRawInt40();
                break;

            //  INT_PACKED_7_FIRST
            case 0x7C:
            case 0x7D:
            case 0x7E:
            case 0x7F:
                result = (((long)code - Codes.INT_PACKED_7_ZERO) << 48) | rawInput.readRawInt48();
                break;

            case Codes.INT:
                result = rawInput.readRawInt64();
                break;

            default:
            {
                Object o = read(code);
                if (o is Int64)
                {
                    return((Int64)o);
                }
                else
                {
                    throw Fns.expected("int64", code, o);
                }
            }
            }
            return(result);
        }
コード例 #7
0
        private Object read(int code)
        {
            Object result;

            switch (code)
            {
            //INT_PACKED_1_FIRST
            case 0xFF:
                result = -1L;
                break;

            case 0x00:
            case 0x01:
            case 0x02:
            case 0x03:
            case 0x04:
            case 0x05:
            case 0x06:
            case 0x07:
            case 0x08:
            case 0x09:
            case 0x0A:
            case 0x0B:
            case 0x0C:
            case 0x0D:
            case 0x0E:
            case 0x0F:
            case 0x10:
            case 0x11:
            case 0x12:
            case 0x13:
            case 0x14:
            case 0x15:
            case 0x16:
            case 0x17:
            case 0x18:
            case 0x19:
            case 0x1A:
            case 0x1B:
            case 0x1C:
            case 0x1D:
            case 0x1E:
            case 0x1F:
            case 0x20:
            case 0x21:
            case 0x22:
            case 0x23:
            case 0x24:
            case 0x25:
            case 0x26:
            case 0x27:
            case 0x28:
            case 0x29:
            case 0x2A:
            case 0x2B:
            case 0x2C:
            case 0x2D:
            case 0x2E:
            case 0x2F:
            case 0x30:
            case 0x31:
            case 0x32:
            case 0x33:
            case 0x34:
            case 0x35:
            case 0x36:
            case 0x37:
            case 0x38:
            case 0x39:
            case 0x3A:
            case 0x3B:
            case 0x3C:
            case 0x3D:
            case 0x3E:
            case 0x3F:
                result = (long)code & 0xff;
                break;

            //  INT_PACKED_2_FIRST
            case 0x40:
            case 0x41:
            case 0x42:
            case 0x43:
            case 0x44:
            case 0x45:
            case 0x46:
            case 0x47:
            case 0x48:
            case 0x49:
            case 0x4A:
            case 0x4B:
            case 0x4C:
            case 0x4D:
            case 0x4E:
            case 0x4F:
            case 0x50:
            case 0x51:
            case 0x52:
            case 0x53:
            case 0x54:
            case 0x55:
            case 0x56:
            case 0x57:
            case 0x58:
            case 0x59:
            case 0x5A:
            case 0x5B:
            case 0x5C:
            case 0x5D:
            case 0x5E:
            case 0x5F:
                result = ((long)(code - Codes.INT_PACKED_2_ZERO) << 8) | rawInput.readRawInt8();
                break;

            //  INT_PACKED_3_FIRST
            case 0x60:
            case 0x61:
            case 0x62:
            case 0x63:
            case 0x64:
            case 0x65:
            case 0x66:
            case 0x67:
            case 0x68:
            case 0x69:
            case 0x6A:
            case 0x6B:
            case 0x6C:
            case 0x6D:
            case 0x6E:
            case 0x6F:
                result = ((long)(code - Codes.INT_PACKED_3_ZERO) << 16) | rawInput.readRawInt16();
                break;

            //  INT_PACKED_4_FIRST
            case 0x70:
            case 0x71:
            case 0x72:
            case 0x73:
                result = ((long)(code - Codes.INT_PACKED_4_ZERO << 24)) | rawInput.readRawInt24();
                break;

            //  INT_PACKED_5_FIRST
            case 0x74:
            case 0x75:
            case 0x76:
            case 0x77:
                result = ((long)(code - Codes.INT_PACKED_5_ZERO) << 32) | rawInput.readRawInt32();
                break;

            //  INT_PACKED_6_FIRST
            case 0x78:
            case 0x79:
            case 0x7A:
            case 0x7B:
                result = (((long)code - Codes.INT_PACKED_6_ZERO) << 40) | rawInput.readRawInt40();
                break;

            //  INT_PACKED_7_FIRST
            case 0x7C:
            case 0x7D:
            case 0x7E:
            case 0x7F:
                result = (((long)code - Codes.INT_PACKED_7_ZERO) << 48) | rawInput.readRawInt48();
                break;

            case Codes.PUT_PRIORITY_CACHE:
                result = readAndCacheObject(getPriorityCache());
                break;

            case Codes.GET_PRIORITY_CACHE:
                result = lookupCache(getPriorityCache(), readInt32());
                break;

            case Codes.PRIORITY_CACHE_PACKED_START + 0:
            case Codes.PRIORITY_CACHE_PACKED_START + 1:
            case Codes.PRIORITY_CACHE_PACKED_START + 2:
            case Codes.PRIORITY_CACHE_PACKED_START + 3:
            case Codes.PRIORITY_CACHE_PACKED_START + 4:
            case Codes.PRIORITY_CACHE_PACKED_START + 5:
            case Codes.PRIORITY_CACHE_PACKED_START + 6:
            case Codes.PRIORITY_CACHE_PACKED_START + 7:
            case Codes.PRIORITY_CACHE_PACKED_START + 8:
            case Codes.PRIORITY_CACHE_PACKED_START + 9:
            case Codes.PRIORITY_CACHE_PACKED_START + 10:
            case Codes.PRIORITY_CACHE_PACKED_START + 11:
            case Codes.PRIORITY_CACHE_PACKED_START + 12:
            case Codes.PRIORITY_CACHE_PACKED_START + 13:
            case Codes.PRIORITY_CACHE_PACKED_START + 14:
            case Codes.PRIORITY_CACHE_PACKED_START + 15:
            case Codes.PRIORITY_CACHE_PACKED_START + 16:
            case Codes.PRIORITY_CACHE_PACKED_START + 17:
            case Codes.PRIORITY_CACHE_PACKED_START + 18:
            case Codes.PRIORITY_CACHE_PACKED_START + 19:
            case Codes.PRIORITY_CACHE_PACKED_START + 20:
            case Codes.PRIORITY_CACHE_PACKED_START + 21:
            case Codes.PRIORITY_CACHE_PACKED_START + 22:
            case Codes.PRIORITY_CACHE_PACKED_START + 23:
            case Codes.PRIORITY_CACHE_PACKED_START + 24:
            case Codes.PRIORITY_CACHE_PACKED_START + 25:
            case Codes.PRIORITY_CACHE_PACKED_START + 26:
            case Codes.PRIORITY_CACHE_PACKED_START + 27:
            case Codes.PRIORITY_CACHE_PACKED_START + 28:
            case Codes.PRIORITY_CACHE_PACKED_START + 29:
            case Codes.PRIORITY_CACHE_PACKED_START + 30:
            case Codes.PRIORITY_CACHE_PACKED_START + 31:
                result = lookupCache(getPriorityCache(), code - Codes.PRIORITY_CACHE_PACKED_START);
                break;

            case Codes.STRUCT_CACHE_PACKED_START + 0:
            case Codes.STRUCT_CACHE_PACKED_START + 1:
            case Codes.STRUCT_CACHE_PACKED_START + 2:
            case Codes.STRUCT_CACHE_PACKED_START + 3:
            case Codes.STRUCT_CACHE_PACKED_START + 4:
            case Codes.STRUCT_CACHE_PACKED_START + 5:
            case Codes.STRUCT_CACHE_PACKED_START + 6:
            case Codes.STRUCT_CACHE_PACKED_START + 7:
            case Codes.STRUCT_CACHE_PACKED_START + 8:
            case Codes.STRUCT_CACHE_PACKED_START + 9:
            case Codes.STRUCT_CACHE_PACKED_START + 10:
            case Codes.STRUCT_CACHE_PACKED_START + 11:
            case Codes.STRUCT_CACHE_PACKED_START + 12:
            case Codes.STRUCT_CACHE_PACKED_START + 13:
            case Codes.STRUCT_CACHE_PACKED_START + 14:
            case Codes.STRUCT_CACHE_PACKED_START + 15:
            {
                StructType st = (StructType)lookupCache(getStructCache(), code - Codes.STRUCT_CACHE_PACKED_START);
                result = handleStruct(st.tag, st.fields);
                break;
            }

            case Codes.MAP:
                result = handleStruct("map", 1);
                break;

            case Codes.SET:
                result = handleStruct("set", 1);
                break;

            case Codes.UUID:
                result = handleStruct("uuid", 2);
                break;

            case Codes.REGEX:
                result = handleStruct("regex", 1);
                break;

            case Codes.URI:
                result = handleStruct("uri", 1);
                break;

            case Codes.BIGINT:
                result = handleStruct("bigint", 1);
                break;

            case Codes.BIGDEC:
                result = handleStruct("bigdec", 2);
                break;

            case Codes.INST:
                result = handleStruct("inst", 1);
                break;

            case Codes.SYM:
                result = handleStruct("sym", 2);
                break;

            case Codes.KEY:
                result = handleStruct("key", 2);
                break;

            case Codes.INT_ARRAY:
                result = handleStruct("int[]", 2);
                break;

            case Codes.LONG_ARRAY:
                result = handleStruct("long[]", 2);
                break;

            case Codes.FLOAT_ARRAY:
                result = handleStruct("float[]", 2);
                break;

            case Codes.BOOLEAN_ARRAY:
                result = handleStruct("boolean[]", 2);
                break;

            case Codes.DOUBLE_ARRAY:
                result = handleStruct("double[]", 2);
                break;

            case Codes.OBJECT_ARRAY:
                result = handleStruct("Object[]", 2);
                break;

            case Codes.BYTES_PACKED_LENGTH_START + 0:
            case Codes.BYTES_PACKED_LENGTH_START + 1:
            case Codes.BYTES_PACKED_LENGTH_START + 2:
            case Codes.BYTES_PACKED_LENGTH_START + 3:
            case Codes.BYTES_PACKED_LENGTH_START + 4:
            case Codes.BYTES_PACKED_LENGTH_START + 5:
            case Codes.BYTES_PACKED_LENGTH_START + 6:
            case Codes.BYTES_PACKED_LENGTH_START + 7:
                result = internalReadBytes(code - Codes.BYTES_PACKED_LENGTH_START);
                break;

            case Codes.BYTES:
                result = internalReadBytes(readCount());
                break;

            case Codes.BYTES_CHUNK:
                result = internalReadChunkedBytes();
                break;

            case Codes.STRING_PACKED_LENGTH_START + 0:
            case Codes.STRING_PACKED_LENGTH_START + 1:
            case Codes.STRING_PACKED_LENGTH_START + 2:
            case Codes.STRING_PACKED_LENGTH_START + 3:
            case Codes.STRING_PACKED_LENGTH_START + 4:
            case Codes.STRING_PACKED_LENGTH_START + 5:
            case Codes.STRING_PACKED_LENGTH_START + 6:
            case Codes.STRING_PACKED_LENGTH_START + 7:
                result = internalReadString(code - Codes.STRING_PACKED_LENGTH_START).ToString();
                break;

            case Codes.STRING:
                result = internalReadString(readCount()).ToString();
                break;

            case Codes.STRING_CHUNK:
                result = internalReadChunkedString(readCount());
                break;

            case Codes.LIST_PACKED_LENGTH_START + 0:
            case Codes.LIST_PACKED_LENGTH_START + 1:
            case Codes.LIST_PACKED_LENGTH_START + 2:
            case Codes.LIST_PACKED_LENGTH_START + 3:
            case Codes.LIST_PACKED_LENGTH_START + 4:
            case Codes.LIST_PACKED_LENGTH_START + 5:
            case Codes.LIST_PACKED_LENGTH_START + 6:
            case Codes.LIST_PACKED_LENGTH_START + 7:
                result = internalReadList(code - Codes.LIST_PACKED_LENGTH_START);
                break;

            case Codes.LIST:
                result = internalReadList(readCount());
                break;

            case Codes.BEGIN_CLOSED_LIST:
                result = ((Func <Object[], IList>)getHandler("list"))(readClosedList());
                break;

            case Codes.BEGIN_OPEN_LIST:
                result = ((Func <Object[], IList>)getHandler("list"))(readOpenList());
                break;

            case Codes.TRUE:
                result = true;
                break;

            case Codes.FALSE:
                result = false;
                break;

            case Codes.DOUBLE:
            case Codes.DOUBLE_0:
            case Codes.DOUBLE_1:
                result = ((Func <double, Object>)getHandler("double"))(internalReadDouble(code));
                break;

            case Codes.FLOAT:
                result = ((Func <float, Object>)getHandler("float"))(rawInput.readRawFloat());
                break;

            case Codes.INT:
                result = rawInput.readRawInt64();
                break;

            case Codes.NULL:
                result = null;
                break;

            case Codes.FOOTER:
            {
                int calculatedLength = rawInput.getBytesRead() - 1;
                int magicFromStream  = (int)((code << 24) + (int)rawInput.readRawInt24());
                validateFooter(calculatedLength, magicFromStream);
                return(readObject());
            }

            case Codes.STRUCTTYPE:
            {
                Object tag    = readObject();
                int    fields = readInt32();
                getStructCache().Add(new StructType(tag, fields));
                result = handleStruct(tag, fields);
                break;
            }

            case Codes.STRUCT:
            {
                StructType st = (StructType)lookupCache(getStructCache(), readInt32());
                result = handleStruct(st.tag, st.fields);
                break;
            }

            case Codes.RESET_CACHES:
            {
                resetCaches();
                result = readObject();
                break;
            }


            default:
                throw Fns.expected("any", code);
            }
            return(result);
        }