internal static SqlInfo ReadSqlInfo(IMsgPackReader reader, IMsgPackConverter <Key> keyConverter, IMsgPackConverter <int> intConverter)
        {
            var length = reader.ReadMapLength();

            if (length == null)
            {
                return(null);
            }

            var result = default(SqlInfo);

            for (var i = 0; i < length; i++)
            {
                switch (keyConverter.Read(reader))
                {
                case Key.SqlRowCount:
                    result = new SqlInfo(intConverter.Read(reader));
                    break;

                case Key.SqlRowCount_2_0_4:
                    result = new SqlInfo(intConverter.Read(reader));
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }

            return(result);
        }
        public Space Read(IMsgPackReader reader)
        {
            var        actual   = reader.ReadArrayLength();
            const uint expected = 7u;

            if (actual != expected)
            {
                throw ExceptionHelper.InvalidArrayLength(expected, actual);
            }

            var id = _uintConverter.Read(reader);

            //TODO Find what skipped number means
            reader.SkipToken();

            var name       = _stringConverter.Read(reader);
            var engine     = _engineConverter.Read(reader);
            var fieldCount = _uintConverter.Read(reader);

            //TODO Find what skipped dictionary used for
            reader.SkipToken();

            var fields = _fieldConverter.Read(reader);

            return(new Space(id, fieldCount, name, engine, fields.AsReadOnly()));
        }
Esempio n. 3
0
        public SpaceField Read(IMsgPackReader reader)
        {
            var dictLength = reader.ReadMapLength();

            string name = null;
            var    type = (FieldType)(-1);

            for (int i = 0; i < dictLength.Value; i++)
            {
                var key = _stringConverter.Read(reader);
                switch (key)
                {
                case "name":
                    name = _stringConverter.Read(reader);
                    break;

                case "type":
                    type = _typeConverter.Read(reader);
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }

            return(new SpaceField(name, type));
        }
Esempio n. 4
0
        private IndexPart ReadFromArray(IMsgPackReader reader, uint length)
        {
            if (length != 2u)
            {
                throw ExceptionHelper.InvalidArrayLength(2u, length);
            }

            var fieldNo       = _uintConverter.Read(reader);
            var indexPartType = _indexPartTypeConverter.Read(reader);

            return(new IndexPart(fieldNo, indexPartType));
        }
Esempio n. 5
0
            public BoxInfo Read(IMsgPackReader reader)
            {
                if (!_initialized)
                {
                    InitializeIfNeeded();
                }

                var mapLength = reader.ReadMapLength();

                if (!mapLength.HasValue)
                {
                    return(null);
                }

                var result = new BoxInfo();

                for (var i = 0; i < mapLength; i++)
                {
                    switch (_stringConverter.Read(reader))
                    {
                    case "id":
                        result.Id = _longConverter.Read(reader);
                        break;

                    case "lsn":
                        result.Lsn = _longConverter.Read(reader);
                        break;

                    case "pid":
                        result.Pid = _longConverter.Read(reader);
                        break;

                    case "ro":
                        result.ReadOnly = _boolConverter.Read(reader);
                        break;

                    case "uuid":
                        result.Uuid = Guid.Parse(_stringConverter.Read(reader));
                        break;

                    case "version":
                        result.Version = TarantoolVersion.Parse(_stringConverter.Read(reader));
                        break;

                    default:
                        reader.SkipToken();
                        break;
                    }
                }

                return(result);
            }
Esempio n. 6
0
        public ErrorResponse Read(IMsgPackReader reader)
        {
            string errorMessage = null;
            var    length       = reader.ReadMapLength();

            for (var i = 0; i < length; i++)
            {
                var errorKey = _keyConverter.Read(reader);

                switch (errorKey)
                {
                case Key.Error24:
                    errorMessage = _stringConverter.Read(reader);
                    break;

                case Key.Error:
                    // TODO: add parsing of new error metadata
                    reader.SkipToken();
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }

            return(new ErrorResponse(errorMessage));
        }
Esempio n. 7
0
        public DataResponse Read(IMsgPackReader reader)
        {
            var length = reader.ReadMapLength();

            if (!(1u <= length && length <= 3))
            {
                throw ExceptionHelper.InvalidMapLength(length, 1u, 2u);
            }

            var sqlInfo = default(SqlInfo);

            for (var i = 0; i < length; i++)
            {
                var dataKey = _keyConverter.Read(reader);
                switch (dataKey)
                {
                case Key.SqlInfo:
                    sqlInfo = ReadSqlInfo(reader, _keyConverter, _intConverter);
                    break;

                default:
                    throw ExceptionHelper.UnexpectedKey(dataKey, Key.Data, Key.Metadata);
                }
            }

            return(new DataResponse(sqlInfo));
        }
Esempio n. 8
0
        public EmptyResponse Read(IMsgPackReader reader)
        {
            var length = reader.ReadMapLength();

            if (length > 1)
            {
                throw ExceptionHelper.InvalidMapLength(length, 0, 1);
            }

            if (length == 1)
            {
                var dataKey = _keyConverter.Read(reader);
                if (dataKey != Key.Data)
                {
                    throw ExceptionHelper.UnexpectedKey(dataKey, Key.Data);
                }

                var arrayLength = reader.ReadArrayLength();
                if (arrayLength != 0)
                {
                    throw ExceptionHelper.InvalidArrayLength(0, length);
                }
            }

            return(new EmptyResponse());
        }
Esempio n. 9
0
        private IndexPart ReadFromMap(IMsgPackReader reader, uint length)
        {
            uint?         fieldNo       = null;
            IndexPartType?indexPartType = null;

            for (var i = 0; i < length; i++)
            {
                switch (_stringConverter.Read(reader))
                {
                case "field":
                    fieldNo = _uintConverter.Read(reader);
                    break;

                case "type":
                    indexPartType = _indexPartTypeConverter.Read(reader);
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }

            if (fieldNo.HasValue && indexPartType.HasValue)
            {
                return(new IndexPart(fieldNo.Value, indexPartType.Value));
            }

            throw new SerializationException("Can't read fieldNo or indexPart from map of index metadata");
        }
        public Index Read(IMsgPackReader reader)
        {
            var length = reader.ReadArrayLength();

            if (length != 6u)
            {
                throw ExceptionHelper.InvalidArrayLength(6u, length);
            }

            var spaceId    = _uintConverter.Read(reader);
            var id         = _uintConverter.Read(reader);
            var name       = _stringConverter.Read(reader);
            var type       = _indexTypeConverter.Read(reader);
            var options    = _optionsConverter.Read(reader);
            var indexParts = _indexPartsConverter.Read(reader);

            return(new Index(id, spaceId, name, options.Unique, type, indexParts.AsReadOnly()));
        }
Esempio n. 11
0
        public Beer Read(IMsgPackReader reader)
        {
            var length = reader.ReadMapLength();

            if (length == null)
            {
                return(null);
            }

            if (length != 4)
            {
                throw new SerializationException("Bad format");
            }

            var result = new Beer();

            for (var i = 0; i < length.Value; i++)
            {
                var propertyName = _stringConverter.Read(reader);
                switch (propertyName)
                {
                case nameof(result.Brand):
                    result.Brand = _stringConverter.Read(reader);
                    break;

                case nameof(result.Sort):
                    result.Sort = _listStringConverter.Read(reader);
                    break;

                case nameof(result.Alcohol):
                    result.Alcohol = _floatConverter.Read(reader);
                    break;

                case nameof(result.Brewery):
                    result.Brewery = _stringConverter.Read(reader);
                    break;

                default:
                    throw new SerializationException("Bad format");
                }
            }

            return(result);
        }
Esempio n. 12
0
 private void InitializeReadMethodsCache()
 {
     _readMethodsCache.Add(typeof(sbyte), reader => (T)Enum.ToObject(typeof(T), _sbyteConverter.Read(reader)));
     _readMethodsCache.Add(typeof(byte), reader => (T)Enum.ToObject(typeof(T), _byteConverter.Read(reader)));
     _readMethodsCache.Add(typeof(short), reader => (T)Enum.ToObject(typeof(T), _shortConverter.Read(reader)));
     _readMethodsCache.Add(typeof(ushort), reader => (T)Enum.ToObject(typeof(T), _ushortConverter.Read(reader)));
     _readMethodsCache.Add(typeof(int), reader => (T)Enum.ToObject(typeof(T), _intConverter.Read(reader)));
     _readMethodsCache.Add(typeof(uint), reader => (T)Enum.ToObject(typeof(T), _uintConverter.Read(reader)));
     _readMethodsCache.Add(typeof(long), reader => (T)Enum.ToObject(typeof(T), _longConverter.Read(reader)));
     _readMethodsCache.Add(typeof(ulong), reader => (T)Enum.ToObject(typeof(T), _ulongConverter.Read(reader)));
 }
        private TArray ReadArray(IMsgPackReader reader, MsgPackContext context, uint length, IMsgPackConverter <TElement> converter)
        {
            // ReSharper disable once RedundantCast
            var result = (TArray)(object)new TElement[length];

            for (var i = 0; i < length; i++)
            {
                result[i] = converter.Read(reader, context, null);
            }

            return(result);
        }
Esempio n. 14
0
        public T?Read(IMsgPackReader reader)
        {
            var type = reader.ReadDataType();

            if (type == DataTypes.Null)
            {
                return(null);
            }

            reader.Seek(-1, SeekOrigin.Current);

            return(_converter.Read(reader));
        }
Esempio n. 15
0
        public ResponseHeader Read(IMsgPackReader reader)
        {
            var length = reader.ReadMapLength();

            if (!length.HasValue)
            {
                throw ExceptionHelper.InvalidMapLength(length, 2u, 3u);
            }

            CommandCode?code     = null;
            RequestId?  sync     = null;
            ulong?      schemaId = null;

            for (int i = 0; i < length.Value; i++)
            {
                var key = _keyConverter.Read(reader);

                switch (key)
                {
                case Key.Code:
                    code = _codeConverter.Read(reader);
                    break;

                case Key.Sync:
                    sync = _requestIdConverter.Read(reader);
                    break;

                case Key.SchemaId:
                    schemaId = _ulongConverter.Read(reader);
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }

            if (!code.HasValue)
            {
                throw ExceptionHelper.PropertyUnspecified("Code");
            }

            if (!sync.HasValue)
            {
                throw ExceptionHelper.PropertyUnspecified("Sync");
            }

            return(new ResponseHeader(code.Value, sync.Value, schemaId));
        }
Esempio n. 16
0
        public ErrorResponse Read(IMsgPackReader reader)
        {
            string errorMessage = null;
            var    length       = reader.ReadMapLength();

            var errorKey = _keyConverter.Read(reader);

            if (errorKey != Key.Error)
            {
                throw ExceptionHelper.UnexpectedKey(errorKey, Key.Error);
            }
            errorMessage = _stringConverter.Read(reader);

            return(new ErrorResponse(errorMessage));
        }
        private static TArray ReadList(
            IMsgPackReader reader,
            MsgPackContext context,
            Func <TArray> creator,
            uint length,
            IMsgPackConverter <TElement> converter)
        {
            var array = creator == null ? (TArray)context.GetObjectActivator(typeof(TArray))() : creator();

            for (var i = 0u; i < length; i++)
            {
                array.Add(converter.Read(reader, context, null));
            }

            return(array);
        }
Esempio n. 18
0
        public ValueTuple <T1> Read(IMsgPackReader reader)
        {
            var actual = reader.ReadArrayLength();

            if (actual == null)
            {
                return(default(ValueTuple <T1>));
            }

            const uint expected = 1;

            if (actual != expected)
            {
                throw ExceptionHelper.InvalidArrayLength(expected, actual);
            }

            var item1 = _t1Converter.Read(reader);

            return(ValueTuple.Create(
                       item1
                       ));
        }
Esempio n. 19
0
        public ErrorResponse Read(IMsgPackReader reader)
        {
            string errorMessage = null;
            var    length       = reader.ReadMapLength();

            for (int i = 0; i < length.Value; i++)
            {
                var key = _keyConverter.Read(reader);

                switch (key)
                {
                case Key.Error:
                    errorMessage = _stringConverter.Read(reader);
                    break;

                default:
                    reader.SkipToken();
                    break;
                }
            }
            return(new ErrorResponse(errorMessage));
        }
        public T Read(IMsgPackReader reader)
        {
            var stringValue = _stringConverter.Read(reader);

            return(StringEnum.Parse <T>(typeof(T), stringValue, true));
        }