protected internal override ReadOnlySequence <byte> _GetSequence(int index, int count)
        {
            if (0u >= (uint)count)
            {
                return(ReadOnlySequence <byte> .Empty);
            }

            var buffers = ThreadLocalList <ReadOnlyMemory <byte> > .NewInstance(_componentCount);

            try
            {
                int i = ToComponentIndex0(index);
                while (count > 0)
                {
                    ComponentEntry c           = _components[i];
                    IByteBuffer    s           = c.Buffer;
                    int            localLength = Math.Min(count, c.EndOffset - index);
                    switch (s.IoBufferCount)
                    {
                    case 0:
                        ThrowHelper.ThrowNotSupportedException();
                        break;

                    case 1:
                        if (s.IsSingleIoBuffer)
                        {
                            buffers.Add(s.GetReadableMemory(c.Idx(index), localLength));
                        }
                        else
                        {
                            var sequence0 = s.GetSequence(c.Idx(index), localLength);
                            foreach (var memory in sequence0)
                            {
                                buffers.Add(memory);
                            }
                        }
                        break;

                    default:
                        var sequence = s.GetSequence(c.Idx(index), localLength);
                        foreach (var memory in sequence)
                        {
                            buffers.Add(memory);
                        }
                        break;
                    }

                    index += localLength;
                    count -= localLength;
                    i++;
                }

                return(ReadOnlyBufferSegment.Create(buffers));
            }
            finally
            {
                buffers.Return();
            }
        }
예제 #2
0
 public ReadOnlySequence <byte> GetSequence(int index, int count)
 {
     return(_buffer.GetSequence(index, count));
 }