Esempio n. 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));
        }
Esempio n. 2
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);
        }