Пример #1
0
        public void EmptyMultiMemoryTest()
        {
            MultiMemory mm = MultiMemory.Empty;

            Assert.Equal(0, mm.Length);
            Assert.True(mm.IsEmpty);
            Assert.Equal(0, mm.BlockCount);
            Assert.Equal(0, mm.Slice(0).Length);
            Assert.Equal(0, mm.Slice(0, 0).Length);

            // These should not throw
            mm.CopyTo(new byte[0]);
            mm.CopyFrom(new byte[0]);
        }
Пример #2
0
    public int CopyTo(Memory <byte> buffer, out bool isCompleted, out bool isEmpty)
    {
        lock (_syncRoot)
        {
            int copied = 0;
            if (!_buffer.IsEmpty)
            {
                MultiMemory activeBuffer = _buffer.ActiveMemory;
                copied = Math.Min(buffer.Length, activeBuffer.Length);
                activeBuffer.Slice(0, copied).CopyTo(buffer.Span);
                _buffer.Discard(copied);
            }

            isCompleted = _buffer.IsEmpty && _final;
            isEmpty     = _buffer.IsEmpty;

            return(copied);
        }
    }