Пример #1
0
        public T[] Deserialize(ref JsonReader <TSymbol> reader)
        {
            T[] temp = null;
            T[] result;
            try
            {
                temp = ArrayPool <T> .Shared.Rent(4);

                reader.ReadBeginArrayOrThrow();
                var count = 0;
                while (!reader.TryReadIsEndArrayOrValueSeparator(ref count)) // count is already preincremented, as it counts the separators
                {
                    if (count == temp.Length)
                    {
                        FormatterUtils.GrowArray(ref temp);
                    }

                    temp[count - 1] = ElementFormatter.Deserialize(ref reader);
                }

                result = count == 0 ? Array.Empty <T>() : FormatterUtils.CopyArray(temp, count);
            }
            finally
            {
                if (temp != null)
                {
                    ArrayPool <T> .Shared.Return(temp);
                }
            }

            return(result);
        }
Пример #2
0
        public QueryContainer Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            switch (reader.GetCurrentJsonToken())
            {
            case JsonToken.BeginObject:
                return(QueryFormatter.Deserialize(ref reader, formatterResolver));

            case JsonToken.String:
                var jsonString       = reader.ReadStringSegmentUnsafe();
                var jsonStringReader = new JsonReader(jsonString.Array, jsonString.Offset);
                return(QueryFormatter.Deserialize(ref jsonStringReader, formatterResolver));

            default:
                reader.ReadNextBlock();
                return(null);
            }
        }
Пример #3
0
        public FSharpValueOption <T> Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(FSharpValueOption <T> .ValueNone);
            }

            return(FSharpValueOption <T> .NewValueSome(valueFormatter.Deserialize(ref reader)));
        }
Пример #4
0
        public FSharpOption <T> Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            return(FSharpOption <T> .Some(elementFormatter.Deserialize(ref reader)));
        }
Пример #5
0
        public T?Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            return(ElementFormatter.Deserialize(ref reader));
        }
Пример #6
0
        public IProperty Read(ref JsonReader reader)
        {
            T value = jsonFormatter.Deserialize(ref reader, jsonFormatterResolver);

            return(new Property <T>(this)
            {
                Value = value
            });
        }
Пример #7
0
        private Option <object> ReadRecord(ref JsonReader reader)
        {
            reader.SkipWhiteSpace();
            if (reader.GetCurrentOffsetUnsafe() >= reader.GetBufferUnsafe().Length)
            {
                return(new None());
            }

            return(Formatter.Deserialize(ref reader, StandardResolver.Default));
        }
 public T?Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
 {
     if (reader.ReadIsNull())
     {
         return(null);
     }
     else
     {
         return(underlyingFormatter.Deserialize(ref reader, formatterResolver));
     }
 }
        public override T Deserialize <T>(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var reader = new JsonReader(data);
            IJsonFormatter <T> formatter = Resolver.GetFormatter <T>();

            return(formatter.Deserialize(ref reader, Resolver));
        }
Пример #10
0
                    static TKey ReadIntegerKey(ref JsonReader <TSymbol> reader)
                    {
                        var separator   = JsonUtf16Constant.NameSeparator;
                        var doubleQuote = JsonUtf16Constant.DoubleQuote;

                        reader.ReadSymbolOrThrow(Unsafe.As <char, TSymbol>(ref doubleQuote));
                        var key = KeyFormatter.Deserialize(ref reader);

                        reader.ReadSymbolOrThrow(Unsafe.As <char, TSymbol>(ref doubleQuote));
                        reader.ReadSymbolOrThrow(Unsafe.As <char, TSymbol>(ref separator));
                        return(key);
                    }
Пример #11
0
        public override T Deserialize <T>(string data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            byte[]             bytes     = Encoding.UTF8.GetBytes(data);
            var                reader    = new JsonReader(bytes);
            IJsonFormatter <T> formatter = Resolver.GetFormatter <T>();

            return(formatter.Deserialize(ref reader, Resolver));
        }
Пример #12
0
        public TList Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            reader.ReadBeginArrayOrThrow();
            var list  = CreateFunctor();
            var count = 0;

            while (!reader.TryReadIsEndArrayOrValueSeparator(ref count))
            {
                list.Add(ElementFormatter.Deserialize(ref reader));
            }

            return(list);
        }
        public TDictionary Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            reader.ReadBeginObjectOrThrow();
            var result = new Dictionary <string, T>();
            var count  = 0;

            while (!reader.TryReadIsEndObjectOrValueSeparator(ref count))
            {
                var key   = reader.ReadEscapedName();
                var value = ElementFormatter.Deserialize(ref reader);
                result[key] = value;
            }

            return(Converter(result));
        }
Пример #14
0
        public TDictionary Deserialize(ref JsonReader <TSymbol> reader)
        {
            if (reader.ReadIsNull())
            {
                return(null);
            }

            reader.ReadBeginObjectOrThrow();
            var result = CreateFunctor(); // using new T() is 5-10 times slower
            var count  = 0;

            while (!reader.TryReadIsEndObjectOrValueSeparator(ref count))
            {
                var key   = reader.ReadEscapedName();
                var value = ElementFormatter.Deserialize(ref reader);
                result[key] = value;
            }

            return(result);
        }
Пример #15
0
 public FSharpMap <string, T> Deserialize(ref JsonReader <TSymbol> reader)
 {
     return(new FSharpMap <string, T>(innerFormatter.Deserialize(ref reader)));
 }
Пример #16
0
 public FSharpList <T> Deserialize(ref JsonReader <TSymbol> reader)
 {
     return(ListModule.OfArray(innerFormatter.Deserialize(ref reader)));
 }
Пример #17
0
        public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var obj = formatter.Deserialize(ref reader, formatterResolver);

            return((T)obj);
        }