Ejemplo n.º 1
0
        private static CorpusZipMetadata ReadCorpusMetadata(ref Utf8JsonStreamReader reader)
        {
            IReadOnlyList <DocumentId> firstDocumentIdInBlock = Array.Empty <DocumentId>();

            H.ReadToken(ref reader, JsonTokenType.StartObject);
            while (reader.Read() && reader.TokenType == JsonTokenType.PropertyName)
            {
                var propertyName = reader.GetString();
                switch (propertyName)
                {
                case FirstDocumentIdInBlockPropertyName:
                    firstDocumentIdInBlock = ReadFirstDocumentIdInBlock(ref reader);
                    break;

                default:
                    throw new InvalidDataException($"Unexpected property at position {reader.Position}: {propertyName}");
                }
            }

            if (firstDocumentIdInBlock.Count == 0)
            {
                throw new InvalidDataException("Mandatory field ReadFirstDocumentIdInBlock was not found");
            }

            return(new CorpusZipMetadata(firstDocumentIdInBlock));
        }
Ejemplo n.º 2
0
        private static IReadOnlyList <DocumentId> ReadFirstDocumentIdInBlock(ref Utf8JsonStreamReader reader)
        {
            var firstDocumentIdInBlock = new List <DocumentId>();

            H.ReadToken(ref reader, JsonTokenType.StartArray);
            while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
            {
                firstDocumentIdInBlock.Add(new DocumentId(reader.GetUInt32()));
            }

            return(firstDocumentIdInBlock);
        }