Пример #1
0
        // We will have problem with binary blobs greater than int.MaxValue bytes.
        public byte[] Read(IMsgPackReader reader, MsgPackContext context, Func <byte[]> creator)
        {
            var type = reader.ReadDataType();

            uint length;

            switch (type)
            {
            case DataTypes.Null:
                return(null);

            case DataTypes.Bin8:
                length = IntConverter.ReadUInt8(reader);
                break;

            case DataTypes.Bin16:
                length = IntConverter.ReadUInt16(reader);
                break;

            case DataTypes.Bin32:
                length = IntConverter.ReadUInt32(reader);
                break;

            default:
                throw ExceptionUtils.BadTypeException(type, DataTypes.Bin8, DataTypes.Bin16, DataTypes.Bin32, DataTypes.Null);
            }

            return(ReadByteArray(reader, length));
        }
Пример #2
0
        public override TArray Read(IMsgPackReader reader, MsgPackContext context, Func <TArray> creator)
        {
            var type = reader.ReadDataType();

            switch (type)
            {
            case DataTypes.Null:
                return(default(TArray));

            case DataTypes.Array16:
                return(ReadArray(reader, context, creator, IntConverter.ReadUInt16(reader)));

            case DataTypes.Array32:
                return(ReadArray(reader, context, creator, IntConverter.ReadUInt32(reader)));
            }

            uint length;

            if (TryGetLengthFromFixArray(type, out length))
            {
                return(ReadArray(reader, context, creator, length));
            }

            throw ExceptionUtils.BadTypeException(type, DataTypes.Array16, DataTypes.Array32, DataTypes.FixArray);
        }
Пример #3
0
        public string Read(IMsgPackReader reader, MsgPackContext context, Func <string> creator)
        {
            var type = reader.ReadDataType();

            switch (type)
            {
            case DataTypes.Null:
                return(null);

            case DataTypes.Str8:
                return(ReadString(reader, IntConverter.ReadUInt8(reader)));

            case DataTypes.Str16:
                return(ReadString(reader, IntConverter.ReadUInt16(reader)));

            case DataTypes.Str32:
                return(ReadString(reader, IntConverter.ReadUInt32(reader)));
            }

            uint length;

            if (TryGetFixstrLength(type, out length))
            {
                return(ReadString(reader, length));
            }

            throw ExceptionUtils.BadTypeException(type, DataTypes.FixStr, DataTypes.Str8, DataTypes.Str16, DataTypes.Str32);
        }