private void BuildPositions() { using (Stream stream = _streamProvider()) using (JsonPositionedTextReader reader = new JsonPositionedTextReader(() => stream)) { stream.Seek(_start, SeekOrigin.Begin); reader.Read(); BuildPositions(reader, _start); } }
private void CountOnly(JsonPositionedTextReader reader) { int count = 0; // StartArray reader.Read(); while (true) { reader.Read(); if (reader.TokenType == JsonToken.EndArray) { break; } count++; reader.Skip(); } _count = count; }
private void BuildPositions(JsonPositionedTextReader reader, long currentOffset) { var result = new Dictionary <int, long>(); while (true) { // Find the position just before the PropertyName (we need to read it back later to confirm the string matches) long keyPosition = currentOffset + reader.TokenPosition + 1; reader.Read(); if (reader.TokenType == JsonToken.EndObject) { break; } if (reader.TokenType != JsonToken.PropertyName) { throw new InvalidDataException($"@({reader.LineNumber}, {reader.LinePosition}): Expected property name, found {reader.TokenType} \"{reader.Value}\"."); } // Read JSON object name (Dictionary key) string key = (string)reader.Value; int keyHash = key.GetHashCode(); // Skip the value reader.Read(); reader.Skip(); // Add the hash to the position to our Dictionary; resolve collisions by incrementing while (result.ContainsKey(keyHash)) { keyHash++; } result[keyHash] = keyPosition; } _itemPositions = result; }
private void BuildPositions(JsonPositionedTextReader reader, long currentOffset) { List <long> positions = new List <long>(); while (true) { reader.Read(); if (reader.TokenType == JsonToken.EndArray) { break; } positions.Add(currentOffset + reader.TokenPosition); reader.Skip(); } _itemPositions = positions.ToArray(); _count = positions.Count; }