Beispiel #1
0
        public static ReadOnlySpan <byte> ToSpan(this ReadOnlySequence <byte> sequence)
        {
            SequencePosition      position = sequence.Start;
            ResizableArray <byte> array    = new ResizableArray <byte>(1024);

            while (sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer))
            {
                array.AddAll(buffer.Span);
            }
            return(array.Span);
        }
Beispiel #2
0
        public void OldToSpan()
        {
            SequencePosition      position = Sequence.Start;
            ResizableArray <byte> array    = new ResizableArray <byte>(1024);

            while (Sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer))
            {
                array.AddAll(buffer.Span);
            }
            var Result = array.Span;
        }
Beispiel #3
0
        public static ReadOnlySpan <byte> ToSingleSpan <T>(this T memorySequence) where T : ISequence <ReadOnlyMemory <byte> >
        {
            Position position = Position.First;
            ReadOnlyMemory <byte> memory;
            ResizableArray <byte> array = new ResizableArray <byte>(1024); // TODO: could this be rented from a pool?

            while (memorySequence.TryGet(ref position, out memory))
            {
                array.AddAll(memory.Span);
            }
            return(array.Items.Slice(0, array.Count));
        }
        public static ReadOnlySpan <byte> ToSpan <T>(this T sequence) where T : ISequence <ReadOnlyMemory <byte> >
        {
            SequencePosition      position = sequence.Start;
            ResizableArray <byte> array    = new ResizableArray <byte>(1024);

            while (sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer))
            {
                array.AddAll(buffer.Span);
            }
            array.Resize(array.Count);
            return(array.Span.Slice(0, array.Count));
        }
Beispiel #5
0
        public static ReadOnlySpan <byte> ToSpan <T>(this T memorySequence) where T : ISequence <ReadOnlyMemory <byte> >
        {
            Position position = Position.First;
            ReadOnlyMemory <byte> memory;
            ResizableArray <byte> array = new ResizableArray <byte>(memorySequence.Length.GetValueOrDefault(1024));

            while (memorySequence.TryGet(ref position, out memory))
            {
                array.AddAll(memory.Span);
            }
            array.Resize(array.Count);
            return(array.Items.Slice(0, array.Count));
        }
Beispiel #6
0
        public static ReadOnlySpan <byte> ToSpan <T>(this T bufferSequence) where T : ISequence <ReadOnlyBuffer <byte> >
        {
            Position position = Position.First;
            ReadOnlyBuffer <byte> buffer;
            ResizableArray <byte> array = new ResizableArray <byte>(1024);

            while (bufferSequence.TryGet(ref position, out buffer))
            {
                array.AddAll(buffer.Span);
            }
            array.Resize(array.Count);
            return(array.Items.Slice(0, array.Count));
        }