public bool TryReadRoot(ref DdbReader reader, out IReadOnlyList <Document> value)
        {
            var success = false;

            reader.State.PushDocument();

            try
            {
                ref var current = ref reader.State.GetCurrent();

                if (DocumentJsonReader.TryReadBuffer(ref reader, ref current))
                {
                    value = CreateDocumentsArray(current.AttributesBuffer);
                    return(success = true);
                }

                Unsafe.SkipInit(out value);
                return(success = false);
            }
        public static bool TryReadMap(ref DdbReader reader, out Document value)
        {
            var success = false;

            reader.State.PushDocument();
            try
            {
                ref var current = ref reader.State.GetCurrent();

                if (reader.State.UseFastPath)
                {
                    while (true)
                    {
                        // Property name
                        reader.JsonReaderValue.ReadWithVerify();

                        if (reader.JsonReaderValue.TokenType == JsonTokenType.EndObject)
                        {
                            break;
                        }

                        current.StringBuffer.Add(GetCachedString(ref reader.JsonReaderValue, ref reader.State));

                        // Attribute value
                        reader.JsonReaderValue.ReadWithVerify();

                        TryReadValue(ref reader, ref current);
                    }

                    value = DocumentJsonReader.CreateDocumentFromBuffer(ref current) !;

                    return(success = true);
                }
                else
                {
                    Unsafe.SkipInit(out value);

                    if (current.PropertyState != DdbStackFramePropertyState.None)
                    {
                        if (current.PropertyState < DdbStackFramePropertyState.Name)
                        {
                            current.StringBuffer.Add(GetCachedString(ref reader.JsonReaderValue, ref reader.State));
                            current.PropertyState = DdbStackFramePropertyState.Name;
                        }

                        if (current.PropertyState < DdbStackFramePropertyState.ReadValue)
                        {
                            if (!reader.JsonReaderValue.Read())
                            {
                                return(success = false);
                            }

                            current.PropertyState = DdbStackFramePropertyState.ReadValue;
                        }

                        if (current.PropertyState < DdbStackFramePropertyState.TryRead)
                        {
                            if (!TryReadValue(ref reader, ref current))
                            {
                                return(success = false);
                            }
                        }

                        current.PropertyState = DdbStackFramePropertyState.None;
                    }

                    while (true)
                    {
                        // Property name
                        if (!reader.JsonReaderValue.Read())
                        {
                            return(success = false);
                        }

                        if (reader.JsonReaderValue.TokenType == JsonTokenType.EndObject)
                        {
                            break;
                        }

                        current.StringBuffer.Add(GetCachedString(ref reader.JsonReaderValue, ref reader.State));
                        current.PropertyState = DdbStackFramePropertyState.Name;

                        if (!reader.JsonReaderValue.Read())
                        {
                            return(success = false);
                        }

                        current.PropertyState = DdbStackFramePropertyState.ReadValue;

                        if (!TryReadValue(ref reader, ref current))
                        {
                            return(success = false);
                        }

                        current.PropertyState = DdbStackFramePropertyState.None;
                    }

                    value = DocumentJsonReader.CreateDocumentFromBuffer(ref current);
                    return(success = true);
                }
            }
Пример #3
0
 public bool TryReadRoot(ref DdbReader reader, out Document value) => DocumentJsonReader.TryReadMap(ref reader, out value);