private int ReadImpl(ref ByteSlice slice) { if (_position >= _length) { return(0); } var alreadyCopied = 0; var toCopy = Math.Min(slice.Count, _length - _position); while (toCopy > 0) { var index = Calculator.GetSegmentIndex(_position); var indexInSegment = Calculator.GetIndexInSegment(_position); var segment = FindSegment(index); var bytesToRead = Math.Min(segment->Length - indexInSegment, toCopy); if (bytesToRead > 0) { var segmentBuffer = segment->Buffer; slice.CopyFrom(alreadyCopied, segmentBuffer, indexInSegment, bytesToRead); alreadyCopied += bytesToRead; toCopy -= bytesToRead; _position += bytesToRead; } } return(alreadyCopied); }
public void Test(int segmentLength, long index, int expectedSegmentIndex, int expectedIndexInSegment) { var calculator = new IndexCalculator(segmentLength); Assert.AreEqual(expectedIndexInSegment, calculator.GetIndexInSegment(index)); Assert.AreEqual(expectedSegmentIndex, calculator.GetSegmentIndex(index)); }