public CatFielddataRecord Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var record = new CatFielddataRecord();
            var count  = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var property = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(property, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        record.Id = reader.ReadString();
                        break;

                    case 1:
                        record.Node = reader.ReadString();
                        break;

                    case 2:
                        record.Host = reader.ReadString();
                        break;

                    case 3:
                        record.Ip = reader.ReadString();
                        break;

                    case 4:
                        record.Field = reader.ReadString();
                        break;

                    case 5:
                        record.Size = reader.ReadString();
                        break;
                    }
                }
            }

            return(record);
        }
        public ISuggestContext Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() == JsonToken.Null)
            {
                reader.ReadNext();
                return(null);
            }

            var segment       = reader.ReadNextBlockSegment();
            var segmentReader = new JsonReader(segment.Array, segment.Offset);

            var count = 0;
            ArraySegment <byte> contextType = default;

            while (segmentReader.ReadIsInObject(ref count))
            {
                if (segmentReader.ReadPropertyName() == "type")
                {
                    contextType = segmentReader.ReadStringSegmentRaw();
                    break;
                }

                segmentReader.ReadNextBlock();
            }

            segmentReader = new JsonReader(segment.Array, segment.Offset);

            if (ContextTypes.TryGetValue(contextType, out var value))
            {
                switch (value)
                {
                case 0:
                    return(Deserialize <GeoSuggestContext>(ref segmentReader, formatterResolver));

                case 1:
                    return(Deserialize <CategorySuggestContext>(ref segmentReader, formatterResolver));
                }
            }

            return(Deserialize <CategorySuggestContext>(ref segmentReader, formatterResolver));
        }
        public IDistanceFeatureQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var query = new DistanceFeatureQuery();
            var count = 0;

            while (reader.ReadIsInObject(ref count))
            {
                if (Fields.TryGetValue(reader.ReadPropertyNameSegmentRaw(), out var value))
                {
                    switch (value)
                    {
                    case 0:
                        query.Field = formatterResolver.GetFormatter <Field>().Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        query.Origin = OriginUnionFormatter.Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        query.Pivot = PivotUnionFormatter.Deserialize(ref reader, formatterResolver);
                        break;

                    case 3:
                        query.Boost = reader.ReadDouble();
                        break;
                    }
                }
                else
                {
                    reader.ReadNextBlock();
                }
            }

            return(query);
        }
        public ISingleGroupSource Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            reader.ReadIsBeginObjectWithVerify();
            var sourcePropertyName = reader.ReadPropertyNameSegmentRaw();

            ISingleGroupSource groupSource = null;

            if (GroupSource.TryGetValue(sourcePropertyName, out var value))
            {
                switch (value)
                {
                case 0:
                    groupSource = formatterResolver.GetFormatter <TermsGroupSource>()
                                  .Deserialize(ref reader, formatterResolver);
                    break;

                case 1:
                    groupSource = formatterResolver.GetFormatter <DateHistogramGroupSource>()
                                  .Deserialize(ref reader, formatterResolver);
                    break;

                case 2:
                    groupSource = formatterResolver.GetFormatter <HistogramGroupSource>()
                                  .Deserialize(ref reader, formatterResolver);
                    break;
                }
            }
            else
            {
                throw new JsonParsingException($"Unknown {nameof(ISingleGroupSource)}: {sourcePropertyName.Utf8String()}");
            }

            reader.ReadIsEndObjectWithVerify();
            return(groupSource);
        }
        public ShardStore Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            ShardStore           shardStore   = null;
            var                  count        = 0;
            ShardStoreAllocation allocation   = default;
            string               allocationId = null;

            while (reader.ReadIsInObject(ref count))
            {
                var property = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(property, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        allocation = formatterResolver.GetFormatter <ShardStoreAllocation>()
                                     .Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        allocationId = reader.ReadString();
                        break;
                    }
                }
                else
                {
                    var formatter = DynamicObjectResolver.AllowPrivateExcludeNullCamelCase.GetFormatter <ShardStore>();
                    shardStore    = formatter.Deserialize(ref reader, formatterResolver);
                    shardStore.Id = property.Utf8String();
                }
            }

            if (shardStore != null)
            {
                shardStore.Allocation   = allocation;
                shardStore.AllocationId = allocationId;
            }

            return(shardStore);
        }
Exemple #6
0
        public IEmailAttachments Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                return(null);
            }

            var attachments = new Dictionary <string, IEmailAttachment>();

            var count = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var name       = reader.ReadPropertyName();
                var innerCount = 0;
                while (reader.ReadIsInObject(ref innerCount))
                {
                    if (AttachmentType.TryGetValue(reader.ReadPropertyNameSegmentRaw(), out var value))
                    {
                        IEmailAttachment attachment;
                        switch (value)
                        {
                        case 0:
                            attachment = formatterResolver.GetFormatter <HttpAttachment>()
                                         .Deserialize(ref reader, formatterResolver);
                            attachments.Add(name, attachment);
                            break;

                        case 1:
                            attachment = formatterResolver.GetFormatter <DataAttachment>()
                                         .Deserialize(ref reader, formatterResolver);
                            attachments.Add(name, attachment);
                            break;
                        }
                    }
                }
            }

            return(new EmailAttachments(attachments));
        }
Exemple #7
0
        public IAliasAction Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var token = reader.GetCurrentJsonToken();

            if (token == JsonToken.Null)
            {
                reader.ReadNext();
                return(null);
            }

            var segment       = reader.ReadNextBlockSegment();
            var segmentReader = new JsonReader(segment.Array, segment.Offset);

            segmentReader.ReadIsBeginObjectWithVerify();
            var          action      = segmentReader.ReadPropertyNameSegmentRaw();
            IAliasAction aliasAction = null;

            segmentReader = new JsonReader(segment.Array, segment.Offset);

            if (Actions.TryGetValue(action, out var value))
            {
                switch (value)
                {
                case 0:
                    aliasAction = Deserialize <AliasAddAction>(ref segmentReader, formatterResolver);
                    break;

                case 1:
                    aliasAction = Deserialize <AliasRemoveAction>(ref segmentReader, formatterResolver);
                    break;

                case 2:
                    aliasAction = Deserialize <AliasRemoveIndexAction>(ref segmentReader, formatterResolver);
                    break;
                }
            }

            return(aliasAction);
        }
Exemple #8
0
        protected override bool Deserialize(ref JsonReader reader, ref ArraySegment <byte> property, Error value, IJsonFormatterResolver formatterResolver)
        {
            if (Fields.TryGetValue(property, out var fieldValue))
            {
                switch (fieldValue)
                {
                case 0:
                    value.Headers = formatterResolver.GetFormatter <Dictionary <string, string> >()
                                    .Deserialize(ref reader, formatterResolver);
                    break;

                case 1:
                    value.RootCause = formatterResolver.GetFormatter <List <ErrorCause> >()
                                      .Deserialize(ref reader, formatterResolver);
                    break;
                }

                return(true);
            }

            return(false);
        }
Exemple #9
0
        public Union <bool, DynamicMapping> Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var token = reader.GetCurrentJsonToken();

            switch (token)
            {
            case JsonToken.True:
            case JsonToken.False:
                return(new Union <bool, DynamicMapping>(reader.ReadBoolean()));

            case JsonToken.String:
                var segment = reader.ReadStringSegmentUnsafe();
                if (Values.TryGetValue(segment, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        return(new Union <bool, DynamicMapping>(true));

                    case 1:
                        return(new Union <bool, DynamicMapping>(false));

                    case 2:
                        return(new Union <bool, DynamicMapping>(DynamicMapping.Strict));
                    }
                }

                return(null);

            default:
                throw new JsonParsingException($"Cannot parse Union<bool, DynamicMapping> from token '{token}'");
            }
        }
        public Tuple <T1> Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }


            T1 item1 = default(T1);


            var count = 0;

            reader.ReadIsBeginObjectWithVerify();
            while (!reader.ReadIsEndObjectWithSkipValueSeparator(ref count))
            {
                var keyString = reader.ReadPropertyNameSegmentRaw();
                int key;
#if NETSTANDARD
                dictionary.TryGetValue(keyString, out key);
#else
                dictionary.TryGetValueSafe(keyString, out key);
#endif

                switch (key)
                {
                case 0:
                    item1 = formatterResolver.GetFormatterWithVerify <T1>().Deserialize(ref reader, formatterResolver);
                    break;

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

            return(new Tuple <T1>(item1));
        }
Exemple #11
0
        public GeoLocation Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() == JsonToken.Null)
            {
                reader.ReadNext();
                return(null);
            }

            var    count = 0;
            double lat   = 0;
            double lon   = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        lat = reader.ReadDouble();
                        break;

                    case 1:
                        lon = reader.ReadDouble();
                        break;
                    }
                }
                else
                {
                    reader.ReadNextBlock();
                }
            }

            return(new GeoCoordinate(lat, lon));
        }
        public ITermsQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            ITermsQuery query = new TermsQuery();
            var         count = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var property = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(property, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        query.Boost = reader.ReadDouble();
                        break;

                    case 1:
                        query.Name = reader.ReadString();
                        break;
                    }
                }
                else
                {
                    query.Field = property.Utf8String();
                    ReadTerms(ref reader, query, formatterResolver);
                }
            }

            return(query);
        }
Exemple #13
0
        public Attachment Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var token = reader.GetCurrentJsonToken();

            if (token == JsonToken.String)
            {
                return new Attachment {
                           Content = reader.ReadString()
                }
            }
            ;

            if (token == JsonToken.BeginObject)
            {
                var attachment = new Attachment();

                var count = 0;
                while (reader.ReadIsInObject(ref count))
                {
                    var propertyName = reader.ReadPropertyNameSegmentRaw();
                    if (AutomataDictionary.TryGetValue(propertyName, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                            attachment.Content = reader.ReadString();
                            break;

                        case 1:
                            attachment.Name = reader.ReadString();
                            break;

                        case 2:
                            attachment.Author = reader.ReadString();
                            break;

                        case 3:
                            attachment.Keywords = reader.ReadString();
                            break;

                        case 4:
                            attachment.Date = formatterResolver.GetFormatter <DateTime?>()
                                              .Deserialize(ref reader, formatterResolver);
                            break;

                        case 5:
                            attachment.ContentType = reader.ReadString();
                            break;

                        case 6:
                            attachment.ContentLength = reader.ReadNullableLong();
                            break;

                        case 7:
                            attachment.Language = reader.ReadString();
                            break;

                        case 8:
                            attachment.DetectLanguage = reader.ReadNullableBoolean();
                            break;

                        case 9:
                            attachment.IndexedCharacters = reader.ReadNullableLong();
                            break;

                        case 10:
                            attachment.Title = reader.ReadString();
                            break;
                        }
                    }
                }

                return(attachment);
            }

            return(null);
        }
Exemple #14
0
        public IGeoShapeQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var              count          = 0;
            string           field          = null;
            double?          boost          = null;
            string           name           = null;
            bool?            ignoreUnmapped = null;
            IGeoShapeQuery   query          = null;
            GeoShapeRelation?relation       = null;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        boost = reader.ReadDouble();
                        break;

                    case 1:
                        name = reader.ReadString();
                        break;

                    case 2:
                        ignoreUnmapped = reader.ReadBoolean();
                        break;
                    }
                }
                else
                {
                    field = propertyName.Utf8String();
                    var shapeCount = 0;
                    while (reader.ReadIsInObject(ref shapeCount))
                    {
                        var shapeProperty = reader.ReadPropertyNameSegmentRaw();
                        if (ShapeFields.TryGetValue(shapeProperty, out var shapeValue))
                        {
                            switch (shapeValue)
                            {
                            case 0:
                                var shapeFormatter = formatterResolver.GetFormatter <IGeoShape>();
                                query = new GeoShapeQuery
                                {
                                    Shape = shapeFormatter.Deserialize(ref reader, formatterResolver)
                                };
                                break;

                            case 1:
                                var fieldLookupFormatter = formatterResolver.GetFormatter <FieldLookup>();
                                query = new GeoShapeQuery
                                {
                                    IndexedShape = fieldLookupFormatter.Deserialize(ref reader, formatterResolver)
                                };
                                break;

                            case 2:
                                relation = formatterResolver.GetFormatter <GeoShapeRelation>()
                                           .Deserialize(ref reader, formatterResolver);
                                break;
                            }
                        }
                    }
                }
            }

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

            query.Boost          = boost;
            query.Name           = name;
            query.Field          = field;
            query.Relation       = relation;
            query.IgnoreUnmapped = ignoreUnmapped;
            return(query);
        }
        public CartesianPoint Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var token = reader.GetCurrentJsonToken();

            switch (token)
            {
            case JsonToken.BeginObject:
            {
                var count = 0;
                var point = new CartesianPoint {
                    Format = ShapeFormat.Object
                };
                while (reader.ReadIsInObject(ref count))
                {
                    var property = reader.ReadPropertyNameSegmentRaw();
                    if (Fields.TryGetValue(property, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                            point.X = reader.ReadSingle();
                            break;

                        case 1:
                            point.Y = reader.ReadSingle();
                            break;

                        case 2:
                            reader.ReadSingle();
                            break;
                        }
                    }
                    else
                    {
                        throw new JsonParsingException($"Unknown property {property.Utf8String()} when parsing {nameof(CartesianPoint)}");
                    }
                }

                return(point);
            }

            case JsonToken.BeginArray:
            {
                var count = 0;
                var point = new CartesianPoint {
                    Format = ShapeFormat.Array
                };
                while (reader.ReadIsInArray(ref count))
                {
                    switch (count)
                    {
                    case 1:
                        point.X = reader.ReadSingle();
                        break;

                    case 2:
                        point.Y = reader.ReadSingle();
                        break;

                    case 3:
                        reader.ReadSingle();
                        break;

                    default:
                        throw new JsonParsingException($"Expected 2 or 3 coordinates but found {count}");
                    }
                }

                return(point);
            }

            case JsonToken.String:
            {
                var value = reader.ReadString();
                return(value.IndexOf(",", StringComparison.InvariantCultureIgnoreCase) > -1
                                                ? CartesianPoint.FromCoordinates(value)
                                                : CartesianPoint.FromWellKnownText(value));
            }

            default:
                throw new JsonParsingException($"Unexpected token type {token} when parsing {nameof(CartesianPoint)}");
            }
        }
        public IReadOnlyDictionary <Field, IFieldMapping> Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var fieldMappings = new Dictionary <Field, IFieldMapping>();

            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNext();
                return(fieldMappings);
            }

            var           count   = 0;
            IFieldMapping mapping = null;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
#pragma warning disable 618
                        mapping = formatterResolver.GetFormatter <AllField>()
                                  .Deserialize(ref reader, formatterResolver);
#pragma warning restore 618
                        break;

                    case 1:
                        mapping = formatterResolver.GetFormatter <SourceField>()
                                  .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        mapping = formatterResolver.GetFormatter <RoutingField>()
                                  .Deserialize(ref reader, formatterResolver);
                        break;

                    case 3:
#pragma warning disable 618
                        mapping = formatterResolver.GetFormatter <IndexField>()
                                  .Deserialize(ref reader, formatterResolver);
#pragma warning restore 618
                        break;

                    case 4:
                        mapping = formatterResolver.GetFormatter <SizeField>()
                                  .Deserialize(ref reader, formatterResolver);
                        break;
                    }
                }
                else
                {
                    var property = formatterResolver.GetFormatter <IProperty>()
                                   .Deserialize(ref reader, formatterResolver);

                    if (property != null)
                    {
                        property.Name =
                            propertyName.Utf8String();
                    }

                    mapping = property;
                }

                if (mapping != null)
                {
                    var name = propertyName.Utf8String();
                    fieldMappings.Add(name, mapping);
                }
            }

            var settings             = formatterResolver.GetConnectionSettings();
            var resolvableDictionary = new ResolvableDictionaryProxy <Field, IFieldMapping>(settings, fieldMappings);
            return(resolvableDictionary);
        }
        public override IFuzzyQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() == JsonToken.Null)
            {
                reader.ReadNext();
                return(null);
            }

            var                   count = 0;
            IFuzzyQuery           query = null;
            string                name  = null;
            double?               boost = null;
            MultiTermQueryRewrite multiTermQueryRewrite = null;
            int?                  prefixLength          = null;
            int?                  maxExpansions         = null;
            bool?                 transpositions        = null;

            while (reader.ReadIsInObject(ref count))
            {
                var field = reader.ReadPropertyName();
                // ReSharper disable once TooWideLocalVariableScope
                ArraySegment <byte> fuzzinessSegment = default;
                var valueCount = 0;
                while (reader.ReadIsInObject(ref valueCount))
                {
                    var property = reader.ReadPropertyNameSegmentRaw();
                    if (Fields.TryGetValue(property, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                        {
                            var token = reader.GetCurrentJsonToken();
                            switch (token)
                            {
                            case JsonToken.String:
                                var valueSegment = reader.ReadStringSegmentUnsafe();
                                if (valueSegment.IsDateTime(formatterResolver, out var dateTime))
                                {
                                    query = new FuzzyDateQuery
                                    {
                                        Field = field,
                                        Value = dateTime
                                    }
                                }
                                ;
                                else
                                {
                                    query = new FuzzyQuery
                                    {
                                        Field = field,
                                        Value = valueSegment.Utf8String()
                                    }
                                };
                                break;

                            case JsonToken.Number:
                                query = new FuzzyNumericQuery
                                {
                                    Field = field,
                                    Value = reader.ReadDouble()
                                };
                                break;
                            }

                            if (fuzzinessSegment != default)
                            {
                                var fuzzinessReader = new JsonReader(fuzzinessSegment.Array, fuzzinessSegment.Offset);
                                SetFuzziness(ref fuzzinessReader, query, formatterResolver);
                            }
                            break;
                        }

                        case 1:
                        {
                            if (query != null)
                            {
                                SetFuzziness(ref reader, query, formatterResolver);
                            }
                            else
                            {
                                fuzzinessSegment = reader.ReadNextBlockSegment();
                            }
                            break;
                        }

                        case 2:
                            prefixLength = reader.ReadInt32();
                            break;

                        case 3:
                            maxExpansions = reader.ReadInt32();
                            break;

                        case 4:
                            transpositions = reader.ReadBoolean();
                            break;

                        case 5:
                            var rewriteFormatter = formatterResolver.GetFormatter <MultiTermQueryRewrite>();
                            multiTermQueryRewrite = rewriteFormatter.Deserialize(ref reader, formatterResolver);
                            break;

                        case 6:
                            name = reader.ReadString();
                            break;

                        case 7:
                            boost = reader.ReadDouble();
                            break;
                        }
                    }
                }
            }

            query.PrefixLength   = prefixLength;
            query.MaxExpansions  = maxExpansions;
            query.Transpositions = transpositions;
            query.Rewrite        = multiTermQueryRewrite;
            query.Name           = name;
            query.Boost          = boost;
            return(query);
        }
Exemple #18
0
        public IPercentilesAggregation Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var count       = 0;
            var percentiles = new PercentilesAggregation();

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        percentiles.Method = formatterResolver.GetFormatter <HDRHistogramMethod>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        percentiles.Method = formatterResolver.GetFormatter <TDigestMethod>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        percentiles.Field = reader.ReadString();
                        break;

                    case 3:
                        percentiles.Script = formatterResolver.GetFormatter <IScript>()
                                             .Deserialize(ref reader, formatterResolver);
                        break;

                    case 4:
                        percentiles.Missing = reader.ReadDouble();
                        break;

                    case 5:
                        percentiles.Percents = formatterResolver.GetFormatter <IEnumerable <double> >()
                                               .Deserialize(ref reader, formatterResolver);
                        break;

                    case 6:
                        percentiles.Meta = formatterResolver.GetFormatter <IDictionary <string, object> >()
                                           .Deserialize(ref reader, formatterResolver);
                        break;

                    case 7:
                        percentiles.Keyed = reader.ReadBoolean();
                        break;

                    case 8:
                        percentiles.Format = reader.ReadString();
                        break;
                    }
                }
            }

            return(percentiles);
        }
Exemple #19
0
        public IArrayCompareCondition Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var        count           = 0;
            string     arrayPath       = null;
            string     path            = null;
            var        comparisonValue = -1;
            Quantifier?quantifier      = null;
            object     value           = null;

            while (reader.ReadIsInObject(ref count))
            {
                arrayPath = reader.ReadPropertyName();

                var innerCount = 0;
                while (reader.ReadIsInObject(ref innerCount))
                {
                    var property = reader.ReadPropertyNameSegmentRaw();
                    if (Comparisons.TryGetValue(property, out comparisonValue))
                    {
                        var comparisonPropCount = 0;
                        while (reader.ReadIsInObject(ref comparisonPropCount))
                        {
                            var comparisonProperty = reader.ReadPropertyNameSegmentRaw();
                            if (ComparisonProperties.TryGetValue(comparisonProperty, out var propValue))
                            {
                                switch (propValue)
                                {
                                case 0:
                                    quantifier = formatterResolver.GetFormatter <Quantifier>()
                                                 .Deserialize(ref reader, formatterResolver);
                                    break;

                                case 1:
                                    value = formatterResolver.GetFormatter <object>()
                                            .Deserialize(ref reader, formatterResolver);
                                    break;
                                }
                            }
                            else
                            {
                                reader.ReadNextBlock();
                            }
                        }
                    }
                    else
                    {
                        path = reader.ReadString();
                    }
                }
            }

            switch (comparisonValue)
            {
            case 0: return(new EqualArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            case 1: return(new NotEqualArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            case 2: return(new GreaterThanArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            case 3: return(new GreaterThanOrEqualArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            case 4: return(new LowerThanArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            case 5: return(new LowerThanOrEqualArrayCondition(arrayPath, path, value)
                {
                    Quantifier = quantifier
                });

            default: return(null);
            }
        }
        public IScoreFunction Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            QueryContainer filter   = null;
            double?        weight   = null;
            IScoreFunction function = null;

            var count = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        var formatter = formatterResolver.GetFormatter <QueryContainer>();
                        filter = formatter.Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        weight = reader.ReadDouble();
                        break;

                    case 2:
                        var            innerCount     = 0;
                        MultiValueMode?multiValueMode = null;
                        IDecayFunction decayFunction  = null;
                        while (reader.ReadIsInObject(ref innerCount))
                        {
                            var functionPropertyName = reader.ReadPropertyName();
                            if (functionPropertyName == "multi_value_mode")
                            {
                                multiValueMode = formatterResolver.GetFormatter <MultiValueMode>()
                                                 .Deserialize(ref reader, formatterResolver);
                            }
                            else
                            {
                                var name = propertyName.Utf8String();
                                decayFunction       = ReadDecayFunction(ref reader, name, formatterResolver);
                                decayFunction.Field = functionPropertyName;
                            }
                        }

                        if (decayFunction != null)
                        {
                            decayFunction.MultiValueMode = multiValueMode;
                            function = decayFunction;
                        }
                        break;

                    case 3:
                        var randomScoreFormatter = formatterResolver.GetFormatter <RandomScoreFunction>();
                        function = randomScoreFormatter.Deserialize(ref reader, formatterResolver);
                        break;

                    case 4:
                        var fieldValueFormatter = formatterResolver.GetFormatter <FieldValueFactorFunction>();
                        function = fieldValueFormatter.Deserialize(ref reader, formatterResolver);
                        break;

                    case 5:
                        var scriptFormatter = formatterResolver.GetFormatter <ScriptScoreFunction>();
                        function = scriptFormatter.Deserialize(ref reader, formatterResolver);
                        break;
                    }
                }
            }

            if (function == null)
            {
                if (weight.HasValue)
                {
                    function = new WeightFunction();
                }
                else
                {
                    return(null);
                }
            }

            function.Weight = weight;
            function.Filter = filter;
            return(function);
        }
Exemple #21
0
        public Actions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var dictionary = new Dictionary <string, IAction>();
            var count      = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var name        = reader.ReadPropertyName();
                var actionCount = 0;

                Time               throttlePeriod = null;
                IAction            action         = null;
                string             @foreach       = null;
                int?               maxIterations  = null;
                TransformContainer transform      = null;
                ConditionContainer condition      = null;

                while (reader.ReadIsInObject(ref actionCount))
                {
                    var propertyName = reader.ReadPropertyNameSegmentRaw();

                    if (Fields.TryGetValue(propertyName, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                            throttlePeriod = formatterResolver.GetFormatter <Time>()
                                             .Deserialize(ref reader, formatterResolver);
                            break;

                        case 1:
                            action = formatterResolver.GetFormatter <EmailAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 2:
                            action = formatterResolver.GetFormatter <WebhookAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 3:
                            action = formatterResolver.GetFormatter <IndexAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 4:
                            action = formatterResolver.GetFormatter <LoggingAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 5:
                            action = formatterResolver.GetFormatter <SlackAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 6:
                            action = formatterResolver.GetFormatter <PagerDutyAction>()
                                     .Deserialize(ref reader, formatterResolver);
                            break;

                        case 7:
                            @foreach = reader.ReadString();
                            break;

                        case 8:
                            transform = formatterResolver.GetFormatter <TransformContainer>()
                                        .Deserialize(ref reader, formatterResolver);
                            break;

                        case 9:
                            condition = formatterResolver.GetFormatter <ConditionContainer>()
                                        .Deserialize(ref reader, formatterResolver);
                            break;

                        case 10:
                            maxIterations = reader.ReadInt32();
                            break;
                        }
                    }
                    else
                    {
                        reader.ReadNextBlock();
                    }
                }

                if (action != null)
                {
                    action.Name           = name;
                    action.ThrottlePeriod = throttlePeriod;
                    action.Foreach        = @foreach;
                    action.MaxIterations  = maxIterations;
                    action.Transform      = transform;
                    action.Condition      = condition;
                    dictionary.Add(name, action);
                }
            }

            return(new Actions(dictionary));
        }
        public IProcessor Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            // read opening {
            reader.ReadNext();

            IProcessor processor = null;

            var processorName = reader.ReadPropertyNameSegmentRaw();

            if (Processors.TryGetValue(processorName, out var value))
            {
                switch (value)
                {
                case 0:
                    processor = Deserialize <AttachmentProcessor>(ref reader, formatterResolver);
                    break;

                case 1:
                    processor = Deserialize <AppendProcessor>(ref reader, formatterResolver);
                    break;

                case 2:
                    processor = Deserialize <ConvertProcessor>(ref reader, formatterResolver);
                    break;

                case 3:
                    processor = Deserialize <DateProcessor>(ref reader, formatterResolver);
                    break;

                case 4:
                    processor = Deserialize <DateIndexNameProcessor>(ref reader, formatterResolver);
                    break;

                case 5:
                    processor = Deserialize <DotExpanderProcessor>(ref reader, formatterResolver);
                    break;

                case 6:
                    processor = Deserialize <FailProcessor>(ref reader, formatterResolver);
                    break;

                case 7:
                    processor = Deserialize <ForeachProcessor>(ref reader, formatterResolver);
                    break;

                case 8:
                    processor = Deserialize <JsonProcessor>(ref reader, formatterResolver);
                    break;

                case 9:
                    processor = Deserialize <UserAgentProcessor>(ref reader, formatterResolver);
                    break;

                case 10:
                    processor = Deserialize <KeyValueProcessor>(ref reader, formatterResolver);
                    break;

                case 11:
                    processor = Deserialize <GeoIpProcessor>(ref reader, formatterResolver);
                    break;

                case 12:
                    processor = Deserialize <GrokProcessor>(ref reader, formatterResolver);
                    break;

                case 13:
                    processor = Deserialize <GsubProcessor>(ref reader, formatterResolver);
                    break;

                case 14:
                    processor = Deserialize <JoinProcessor>(ref reader, formatterResolver);
                    break;

                case 15:
                    processor = Deserialize <LowercaseProcessor>(ref reader, formatterResolver);
                    break;

                case 16:
                    processor = Deserialize <RemoveProcessor>(ref reader, formatterResolver);
                    break;

                case 17:
                    processor = Deserialize <RenameProcessor>(ref reader, formatterResolver);
                    break;

                case 18:
                    processor = Deserialize <ScriptProcessor>(ref reader, formatterResolver);
                    break;

                case 19:
                    processor = Deserialize <SetProcessor>(ref reader, formatterResolver);
                    break;

                case 20:
                    processor = Deserialize <SortProcessor>(ref reader, formatterResolver);
                    break;

                case 21:
                    processor = Deserialize <SplitProcessor>(ref reader, formatterResolver);
                    break;

                case 22:
                    processor = Deserialize <TrimProcessor>(ref reader, formatterResolver);
                    break;

                case 23:
                    processor = Deserialize <UppercaseProcessor>(ref reader, formatterResolver);
                    break;

                case 24:
                    processor = Deserialize <UrlDecodeProcessor>(ref reader, formatterResolver);
                    break;

                case 25:
                    processor = Deserialize <BytesProcessor>(ref reader, formatterResolver);
                    break;

                case 26:
                    processor = Deserialize <DissectProcessor>(ref reader, formatterResolver);
                    break;

                case 27:
                    processor = Deserialize <SetSecurityUserProcessor>(ref reader, formatterResolver);
                    break;

                case 28:
                    processor = Deserialize <PipelineProcessor>(ref reader, formatterResolver);
                    break;

                case 29:
                    processor = Deserialize <DropProcessor>(ref reader, formatterResolver);
                    break;

                case 30:
                    processor = Deserialize <CircleProcessor>(ref reader, formatterResolver);
                    break;

                case 31:
                    processor = Deserialize <EnrichProcessor>(ref reader, formatterResolver);
                    break;

                case 32:
                    processor = Deserialize <CsvProcessor>(ref reader, formatterResolver);
                    break;

                case 33:
                    processor = Deserialize <UriPartsProcessor>(ref reader, formatterResolver);
                    break;

                case 34:
                    processor = Deserialize <FingerprintProcessor>(ref reader, formatterResolver);
                    break;

                case 35:
                    processor = Deserialize <NetworkCommunityIdProcessor>(ref reader, formatterResolver);
                    break;
                }
            }
            else
            {
                reader.ReadNextBlock();
            }

            reader.ReadIsEndObjectWithVerify();
            return(processor);
        }
Exemple #23
0
        public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var lifecycles = new Dictionary <string, ILifecycleAction>();
            var count      = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var type = reader.ReadPropertyNameSegmentRaw();
                ILifecycleAction lifecycleAction = null;

                if (LifeCycleActions.TryGetValue(type, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        lifecycleAction = formatterResolver.GetFormatter <AllocateLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        lifecycleAction = formatterResolver.GetFormatter <DeleteLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        lifecycleAction = formatterResolver.GetFormatter <ForceMergeLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 3:
                        lifecycleAction = formatterResolver.GetFormatter <FreezeLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 4:
                        lifecycleAction = formatterResolver.GetFormatter <ReadOnlyLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 5:
                        lifecycleAction = formatterResolver.GetFormatter <RolloverLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 6:
                        lifecycleAction = formatterResolver.GetFormatter <SetPriorityLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 7:
                        lifecycleAction = formatterResolver.GetFormatter <ShrinkLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 8:
                        lifecycleAction = formatterResolver.GetFormatter <UnfollowLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 9:
                        lifecycleAction = formatterResolver.GetFormatter <WaitForSnapshotLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;
                    }

                    lifecycles.Add(type.Utf8String(), lifecycleAction);
                }
                else
                {
                    reader.ReadNextBlock();
                }
            }

            return(new LifecycleActions(lifecycles));
        }
Exemple #24
0
        public ISourceOnlyRepository Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var count = 0;
            ArraySegment <byte> settings = default;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        reader.ReadNext();
                        break;

                    case 1:
                        settings = reader.ReadNextBlockSegment();
                        break;
                    }
                }
                else
                {
                    reader.ReadNextBlock();
                }
            }

            if (settings == default)
            {
                return(null);
            }

            var    segmentReader    = new JsonReader(settings.Array, settings.Offset);
            string delegateType     = null;
            object delegateSettings = null;

            // reset count to zero to so that ReadIsInObject skips opening brace
            count = 0;
            while (segmentReader.ReadIsInObject(ref count))
            {
                var propertyName = segmentReader.ReadPropertyNameSegmentRaw();
                if (propertyName.EqualsBytes(DelegateType))
                {
                    delegateType = segmentReader.ReadString();
                    break;
                }

                segmentReader.ReadNextBlock();
            }

            // reset the offset
            segmentReader.ResetOffset();

            switch (delegateType)
            {
            case "s3":
                delegateSettings = Deserialize <S3RepositorySettings>(ref segmentReader, formatterResolver);
                break;

            case "azure":
                delegateSettings = Deserialize <AzureRepositorySettings>(ref segmentReader, formatterResolver);
                break;

            case "url":
                delegateSettings = Deserialize <ReadOnlyUrlRepositorySettings>(ref segmentReader, formatterResolver);
                break;

            case "hdfs":
                delegateSettings = Deserialize <HdfsRepositorySettings>(ref segmentReader, formatterResolver);
                break;

            case "fs":
                delegateSettings = Deserialize <FileSystemRepositorySettings>(ref segmentReader, formatterResolver);
                break;
            }

            return(new SourceOnlyRepository(delegateType, delegateSettings));
        }
Exemple #25
0
        public IRangeQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            var segment       = reader.ReadNextBlockSegment();
            var segmentReader = new JsonReader(segment.Array, segment.Offset);
            var isLong        = false;
            var isDate        = false;
            var isDouble      = false;
            var count         = 0;

            while (segmentReader.ReadIsInObject(ref count))
            {
                segmentReader.ReadPropertyNameSegmentRaw();

                var innerCount = 0;
                while (segmentReader.ReadIsInObject(ref innerCount))
                {
                    var innerPropertyName = segmentReader.ReadPropertyNameSegmentRaw();
                    if (RangeFields.TryGetValue(innerPropertyName, out var innerValue))
                    {
                        switch (innerValue)
                        {
                        case 0:
                        case 1:
                            isDate = true;
                            break;

                        case 2:
                        case 3:
                        case 4:
                        case 5:
                            var token = segmentReader.GetCurrentJsonToken();
                            switch (token)
                            {
                            case JsonToken.String:
                            case JsonToken.Null:
                                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                                // Inspection is not correct
                                if (!isDate)
                                {
                                    var valueSegment = segmentReader.ReadStringSegmentUnsafe();
                                    isDate = valueSegment.IsDateTime(formatterResolver, out _) ||
                                             valueSegment.ContainsDateMathSeparator() && DateMath.IsValidDateMathString(valueSegment.Utf8String());
                                }
                                break;

                            case JsonToken.Number:
                                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                                // Inspection is not correct
                                if (!isDouble)
                                {
                                    var numberSegment = segmentReader.ReadNumberSegment();
                                    if (numberSegment.IsDouble())
                                    {
                                        isDouble = true;
                                    }
                                    else
                                    {
                                        isLong = true;
                                    }
                                }
                                break;
                            }
                            break;
                        }
                    }
                    else
                    {
                        segmentReader.ReadNextBlock();
                    }

                    if (isDate || isDouble)
                    {
                        break;
                    }
                }

                if (isDate || isDouble)
                {
                    break;
                }
            }

            segmentReader = new JsonReader(segment.Array, segment.Offset);

            if (isDate)
            {
                return(Deserialize <IDateRangeQuery>(ref segmentReader, formatterResolver));
            }
            if (isDouble)
            {
                return(Deserialize <INumericRangeQuery>(ref segmentReader, formatterResolver));
            }
            if (isLong)
            {
                return(Deserialize <ILongRangeQuery>(ref segmentReader, formatterResolver));
            }

            return(Deserialize <ITermRangeQuery>(ref segmentReader, formatterResolver));
        }
Exemple #26
0
        public ISort Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            ISort sort = null;

            switch (reader.GetCurrentJsonToken())
            {
            case JsonToken.String:
            {
                var sortProperty = reader.ReadString();
                sort = new FieldSort {
                    Field = sortProperty
                };
                break;
            }

            case JsonToken.BeginObject:
            {
                var count = 0;
                while (reader.ReadIsInObject(ref count))
                {
                    var sortProperty = reader.ReadPropertyNameSegmentRaw();
                    if (SortFields.TryGetValue(sortProperty, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                            var    propCount                 = 0;
                            string field                     = null;
                            var    geoDistanceSegment        = reader.ReadNextBlockSegment();
                            var    geoDistanceReader         = new JsonReader(geoDistanceSegment.Array, geoDistanceSegment.Offset);
                            IEnumerable <GeoLocation> points = null;
                            while (geoDistanceReader.ReadIsInObject(ref propCount))
                            {
                                var nameSegment = geoDistanceReader.ReadPropertyNameSegmentRaw();
                                if (geoDistanceReader.GetCurrentJsonToken() == JsonToken.BeginArray)
                                {
                                    field  = nameSegment.Utf8String();
                                    points = formatterResolver.GetFormatter <IEnumerable <GeoLocation> >()
                                             .Deserialize(ref geoDistanceReader, formatterResolver);
                                    break;
                                }

                                // skip value if not array
                                geoDistanceReader.ReadNextBlock();
                            }
                            geoDistanceReader = new JsonReader(geoDistanceSegment.Array, geoDistanceSegment.Offset);
                            var geoDistanceSort = formatterResolver.GetFormatter <GeoDistanceSort>()
                                                  .Deserialize(ref geoDistanceReader, formatterResolver);
                            geoDistanceSort.Field  = field;
                            geoDistanceSort.Points = points;
                            sort = geoDistanceSort;
                            break;

                        case 1:
                            sort = formatterResolver.GetFormatter <ScriptSort>()
                                   .Deserialize(ref reader, formatterResolver);
                            break;
                        }
                    }
                    else
                    {
                        var       field = sortProperty.Utf8String();
                        FieldSort sortField;
                        if (reader.GetCurrentJsonToken() == JsonToken.String)
                        {
                            var sortOrder = formatterResolver.GetFormatter <SortOrder>()
                                            .Deserialize(ref reader, formatterResolver);
                            sortField = new FieldSort {
                                Field = field, Order = sortOrder
                            };
                        }
                        else
                        {
                            sortField = formatterResolver.GetFormatter <FieldSort>()
                                        .Deserialize(ref reader, formatterResolver);
                            sortField.Field = field;
                        }

                        sort = sortField;
                    }
                }

                break;
            }

            default:
                throw new JsonParsingException($"Cannot deserialize {nameof(ISort)} from {reader.GetCurrentJsonToken()}");
            }

            return(sort);
        }
        public ITokenFilter Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var arraySegment  = reader.ReadNextBlockSegment();
            var segmentReader = new JsonReader(arraySegment.Array, arraySegment.Offset);
            var count         = 0;
            ArraySegment <byte> tokenFilterType = default;

            while (segmentReader.ReadIsInObject(ref count))
            {
                var propertyName = segmentReader.ReadPropertyNameSegmentRaw();
                if (propertyName.EqualsBytes(TypeField))
                {
                    tokenFilterType = segmentReader.ReadStringSegmentUnsafe();
                    break;
                }

                segmentReader.ReadNextBlock();
            }

            if (tokenFilterType == default)
            {
                return(null);
            }

            segmentReader = new JsonReader(arraySegment.Array, arraySegment.Offset);
            if (TokenFilterTypes.TryGetValue(tokenFilterType, out var value))
            {
                switch (value)
                {
                case 0: return(Deserialize <AsciiFoldingTokenFilter>(ref segmentReader, formatterResolver));

                case 1: return(Deserialize <CommonGramsTokenFilter>(ref segmentReader, formatterResolver));

                case 2: return(Deserialize <DelimitedPayloadTokenFilter>(ref segmentReader, formatterResolver));

                case 3: return(Deserialize <DictionaryDecompounderTokenFilter>(ref segmentReader, formatterResolver));

                case 4: return(Deserialize <EdgeNGramTokenFilter>(ref segmentReader, formatterResolver));

                case 5: return(Deserialize <ElisionTokenFilter>(ref segmentReader, formatterResolver));

                case 6: return(Deserialize <HunspellTokenFilter>(ref segmentReader, formatterResolver));

                case 7: return(Deserialize <HyphenationDecompounderTokenFilter>(ref segmentReader, formatterResolver));

                case 8: return(Deserialize <KeepTypesTokenFilter>(ref segmentReader, formatterResolver));

                case 9: return(Deserialize <KeepWordsTokenFilter>(ref segmentReader, formatterResolver));

                case 10: return(Deserialize <KeywordMarkerTokenFilter>(ref segmentReader, formatterResolver));

                case 11: return(Deserialize <KStemTokenFilter>(ref segmentReader, formatterResolver));

                case 12: return(Deserialize <LengthTokenFilter>(ref segmentReader, formatterResolver));

                case 13: return(Deserialize <LimitTokenCountTokenFilter>(ref segmentReader, formatterResolver));

                case 14: return(Deserialize <LowercaseTokenFilter>(ref segmentReader, formatterResolver));

                case 15: return(Deserialize <NGramTokenFilter>(ref segmentReader, formatterResolver));

                case 16: return(Deserialize <PatternCaptureTokenFilter>(ref segmentReader, formatterResolver));

                case 17: return(Deserialize <PatternReplaceTokenFilter>(ref segmentReader, formatterResolver));

                case 18: return(Deserialize <PorterStemTokenFilter>(ref segmentReader, formatterResolver));

                case 19: return(Deserialize <PhoneticTokenFilter>(ref segmentReader, formatterResolver));

                case 20: return(Deserialize <ReverseTokenFilter>(ref segmentReader, formatterResolver));

                case 21: return(Deserialize <ShingleTokenFilter>(ref segmentReader, formatterResolver));

                case 22: return(Deserialize <SnowballTokenFilter>(ref segmentReader, formatterResolver));

                case 23: return(Deserialize <StemmerTokenFilter>(ref segmentReader, formatterResolver));

                case 24: return(Deserialize <StemmerOverrideTokenFilter>(ref segmentReader, formatterResolver));

                case 25: return(Deserialize <StopTokenFilter>(ref segmentReader, formatterResolver));

                case 26: return(Deserialize <SynonymTokenFilter>(ref segmentReader, formatterResolver));

                case 27: return(Deserialize <SynonymGraphTokenFilter>(ref segmentReader, formatterResolver));

                case 28: return(Deserialize <TrimTokenFilter>(ref segmentReader, formatterResolver));

                case 29: return(Deserialize <TruncateTokenFilter>(ref segmentReader, formatterResolver));

                case 30: return(Deserialize <UniqueTokenFilter>(ref segmentReader, formatterResolver));

                case 31: return(Deserialize <UppercaseTokenFilter>(ref segmentReader, formatterResolver));

                case 32: return(Deserialize <WordDelimiterTokenFilter>(ref segmentReader, formatterResolver));

                case 33: return(Deserialize <WordDelimiterGraphTokenFilter>(ref segmentReader, formatterResolver));

                case 34: return(Deserialize <FingerprintTokenFilter>(ref segmentReader, formatterResolver));

                case 35: return(Deserialize <NoriPartOfSpeechTokenFilter>(ref segmentReader, formatterResolver));

                case 36: return(Deserialize <KuromojiReadingFormTokenFilter>(ref segmentReader, formatterResolver));

                case 37: return(Deserialize <KuromojiPartOfSpeechTokenFilter>(ref segmentReader, formatterResolver));

                case 38: return(Deserialize <KuromojiStemmerTokenFilter>(ref segmentReader, formatterResolver));

                case 39: return(Deserialize <IcuCollationTokenFilter>(ref segmentReader, formatterResolver));

                case 40: return(Deserialize <IcuFoldingTokenFilter>(ref segmentReader, formatterResolver));

                case 41: return(Deserialize <IcuNormalizationTokenFilter>(ref segmentReader, formatterResolver));

                case 42: return(Deserialize <IcuTransformTokenFilter>(ref segmentReader, formatterResolver));

                case 43: return(Deserialize <ConditionTokenFilter>(ref segmentReader, formatterResolver));

                case 44: return(Deserialize <MultiplexerTokenFilter>(ref segmentReader, formatterResolver));

                case 45: return(Deserialize <PredicateTokenFilter>(ref segmentReader, formatterResolver));

                default: return(null);
                }
            }

            return(null);
        }
        public IProperty Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var arraySegment = reader.ReadNextBlockSegment();

            var    segmentReader = new JsonReader(arraySegment.Array, arraySegment.Offset);
            var    count         = 0;
            string typeString    = null;
            var    type          = FieldType.None;

            while (segmentReader.ReadIsInObject(ref count))
            {
                var propertyName = segmentReader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        typeString = segmentReader.ReadString();
                        type       = typeString.ToEnum <FieldType>().GetValueOrDefault(type);
                        break;

                    case 1:
                        if (type == FieldType.None)
                        {
                            type = FieldType.Object;
                        }

                        segmentReader.ReadNextBlock();
                        break;
                    }

                    // explicit type has been set
                    if (value == 0)
                    {
                        break;
                    }
                }
                else
                {
                    segmentReader.ReadNextBlock();
                }
            }

            segmentReader = new JsonReader(arraySegment.Array, arraySegment.Offset);

            switch (type)
            {
            case FieldType.Text: return(Deserialize <TextProperty>(ref segmentReader, formatterResolver));

            case FieldType.Keyword: return(Deserialize <KeywordProperty>(ref segmentReader, formatterResolver));

            case FieldType.SearchAsYouType: return(Deserialize <SearchAsYouTypeProperty>(ref segmentReader, formatterResolver));

            case FieldType.Float:
            case FieldType.Double:
            case FieldType.Byte:
            case FieldType.Short:
            case FieldType.Integer:
            case FieldType.Long:
            case FieldType.ScaledFloat:
            case FieldType.HalfFloat:
                var numberProperty = Deserialize <NumberProperty>(ref segmentReader, formatterResolver);
                ((IProperty)numberProperty).Type = typeString;
                return(numberProperty);

            case FieldType.Date: return(Deserialize <DateProperty>(ref segmentReader, formatterResolver));

            case FieldType.DateNanos: return(Deserialize <DateNanosProperty>(ref segmentReader, formatterResolver));

            case FieldType.Boolean: return(Deserialize <BooleanProperty>(ref segmentReader, formatterResolver));

            case FieldType.Binary: return(Deserialize <BinaryProperty>(ref segmentReader, formatterResolver));

            case FieldType.Object: return(Deserialize <ObjectProperty>(ref segmentReader, formatterResolver));

            case FieldType.Nested: return(Deserialize <NestedProperty>(ref segmentReader, formatterResolver));

            case FieldType.Ip: return(Deserialize <IpProperty>(ref segmentReader, formatterResolver));

            case FieldType.GeoPoint: return(Deserialize <GeoPointProperty>(ref segmentReader, formatterResolver));

            case FieldType.GeoShape: return(Deserialize <GeoShapeProperty>(ref segmentReader, formatterResolver));

            case FieldType.Shape: return(Deserialize <ShapeProperty>(ref segmentReader, formatterResolver));

            case FieldType.Point: return(Deserialize <PointProperty>(ref segmentReader, formatterResolver));

            case FieldType.Completion: return(Deserialize <CompletionProperty>(ref segmentReader, formatterResolver));

            case FieldType.TokenCount: return(Deserialize <TokenCountProperty>(ref segmentReader, formatterResolver));

            case FieldType.Murmur3Hash: return(Deserialize <Murmur3HashProperty>(ref segmentReader, formatterResolver));

            case FieldType.Percolator: return(Deserialize <PercolatorProperty>(ref segmentReader, formatterResolver));

            case FieldType.DateRange: return(Deserialize <DateRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.DoubleRange: return(Deserialize <DoubleRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.FloatRange: return(Deserialize <FloatRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.IntegerRange: return(Deserialize <IntegerRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.LongRange: return(Deserialize <LongRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.IpRange: return(Deserialize <IpRangeProperty>(ref segmentReader, formatterResolver));

            case FieldType.Join: return(Deserialize <JoinProperty>(ref segmentReader, formatterResolver));

            case FieldType.Alias: return(Deserialize <FieldAliasProperty>(ref segmentReader, formatterResolver));

            case FieldType.RankFeature: return(Deserialize <RankFeatureProperty>(ref segmentReader, formatterResolver));

            case FieldType.RankFeatures: return(Deserialize <RankFeaturesProperty>(ref segmentReader, formatterResolver));

            case FieldType.Flattened: return(Deserialize <FlattenedProperty>(ref segmentReader, formatterResolver));

            case FieldType.Histogram: return(Deserialize <HistogramProperty>(ref segmentReader, formatterResolver));

            case FieldType.ConstantKeyword: return(Deserialize <ConstantKeywordProperty>(ref segmentReader, formatterResolver));

            case FieldType.Wildcard: return(Deserialize <WildcardProperty>(ref segmentReader, formatterResolver));

            case FieldType.None:
                // no "type" field in the property mapping, or FieldType enum could not be parsed from typeString
                return(Deserialize <ObjectProperty>(ref segmentReader, formatterResolver));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, "mapping property converter does not know this value");
            }
        }
        public FieldRuleBase Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                return(null);
            }

            var           count     = 0;
            FieldRuleBase fieldRule = null;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (Fields.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        var username = reader.ReadString();
                        fieldRule = new UsernameRule(username);
                        break;

                    case 1:
                        if (reader.GetCurrentJsonToken() == JsonToken.BeginArray)
                        {
                            var fm  = formatterResolver.GetFormatter <IEnumerable <string> >();
                            var dns = fm.Deserialize(ref reader, formatterResolver);
                            fieldRule = new DistinguishedNameRule(dns);
                            break;
                        }
                        var dn = reader.ReadString();
                        fieldRule = new DistinguishedNameRule(dn);
                        break;

                    case 2:
                        var realm = reader.ReadString();
                        fieldRule = new RealmRule(realm);
                        break;

                    case 3:
                        var formatter = formatterResolver.GetFormatter <IEnumerable <string> >();
                        var groups    = formatter.Deserialize(ref reader, formatterResolver);
                        fieldRule = new GroupsRule(groups);
                        break;
                    }
                }
                else
                {
                    var name = propertyName.Utf8String();
                    if (name.StartsWith("metadata."))
                    {
                        name = name.Replace("metadata.", string.Empty);
                        var metadata = formatterResolver.GetFormatter <object>()
                                       .Deserialize(ref reader, formatterResolver);
                        fieldRule = new MetadataRule(name, metadata);
                    }
                }
            }

            return(fieldRule);
        }
Exemple #30
0
        public IMovingAverageAggregation Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                return(null);
            }

            var count                        = 0;
            var aggregation                  = new MovingAverageAggregation();
            ArraySegment <byte> model        = default;
            ArraySegment <byte> modelSegment = default;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        aggregation.Format = reader.ReadString();
                        break;

                    case 1:
                        aggregation.GapPolicy = formatterResolver.GetFormatter <GapPolicy?>()
                                                .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        aggregation.Minimize = reader.ReadBoolean();
                        break;

                    case 3:
                        aggregation.Predict = reader.ReadInt32();
                        break;

                    case 4:
                        aggregation.Window = reader.ReadInt32();
                        break;

                    case 5:
                        modelSegment = reader.ReadNextBlockSegment();
                        break;

                    case 6:
                        model = reader.ReadStringSegmentUnsafe();
                        break;

                    case 7:
                        var path = reader.ReadString();
                        if (!string.IsNullOrEmpty(path))
                        {
                            aggregation.BucketsPath = new SingleBucketsPath(path);
                        }
                        break;
                    }
                }
            }

            if (model != default && ModelDictionary.TryGetValue(model, out var modelValue))
            {
                var modelReader = new JsonReader(modelSegment.Array, modelSegment.Offset);
                switch (modelValue)
                {
                case 0:
                    aggregation.Model = formatterResolver.GetFormatter <LinearModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 1:
                    aggregation.Model = formatterResolver.GetFormatter <SimpleModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 2:
                    aggregation.Model = formatterResolver.GetFormatter <EwmaModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 3:
                    aggregation.Model = formatterResolver.GetFormatter <HoltLinearModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 4:
                    aggregation.Model = formatterResolver.GetFormatter <HoltWintersModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;
                }
            }

            return(aggregation);
        }