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);
}