public void Read(BionReader reader) { _index.Clear(); reader.Read(BionToken.StartArray); // Read the Container Index long lastEndPosition = 0; while (reader.Read()) { if (reader.TokenType != BionToken.Integer) { break; } long endPosition = lastEndPosition + reader.CurrentInteger(); reader.Read(BionToken.Integer); long byteLength = reader.CurrentInteger(); _index.Add(new ContainerEntry(endPosition - byteLength, endPosition, _index.Count)); lastEndPosition = endPosition; } // Reconstruct the hierarchy for (int i = _index.Count - 2; i >= 0; --i) { ContainerEntry current = _index[i]; // Find the parent - the first container which starts before this one int parentIndex = i + 1; while (parentIndex != -1) { if (_index[parentIndex].StartByteOffset < current.StartByteOffset) { current.ParentIndex = parentIndex; _index[i] = current; break; } parentIndex = _index[parentIndex].ParentIndex; } } // Size exact _index.Capacity = _index.Count; }
public BionSyntaxException(BionReader reader, string expected) : this($"@{reader.BytesRead:n0}, expected {expected} but found {reader.TokenType}.") { }