DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="1.2.9" />

 Chunk<T>

sealed class Chunk<T> : ReadOnlySequenceSegment<T>
using System; using System.Buffers; namespace DotNext.Buffers { internal sealed class Chunk<T> : ReadOnlySequenceSegment<T> { private Chunk(ReadOnlyMemory<T> segment) { base.RunningIndex = 0; base.Memory = segment; } private Chunk<T> Next(ReadOnlyMemory<T> segment) { long runningIndex = base.RunningIndex; return (Chunk<T>)(base.Next = new Chunk<T>(segment) { RunningIndex = runningIndex + base.Memory.Length }); } internal static void AddChunk(ReadOnlyMemory<T> segment, ref Chunk<T> first, ref Chunk<T> last) { if (first == null || last == null) first = (last = new Chunk<T>(segment)); else last = last.Next(segment); } } }