public void CopyMemoryChunksWithBufferAsReadOnlySequence() { // Trying to be vaguely similar to pipe behaviour for happy path var sourceMemory = new ReadOnlyMemory <byte>(_data); for (int i = 0, sorucePosition = 0; sorucePosition < _data.Length; sorucePosition += _chunkSize, i++) { var source = sourceMemory.Slice(sorucePosition, _chunkSize); var destination = _buffers[i].AsMemory(); source.CopyTo(destination); } var segments = ArraySegment.Create(_buffers); var destinationMemory = _destination.AsMemory(); var destinationPosition = 0; foreach (var segment in segments) { var destination = destinationMemory.Slice(destinationPosition, _chunkSize); segment.CopyTo(destination); destinationPosition += _chunkSize; } }
public override int Read(byte[] buffer, int offset, int count) => Read(This, ArraySegment.Create(buffer, offset, count));