예제 #1
0
        public void Test_MemoryBufferWriterOfT_Clear()
        {
            Memory <byte> memory = new byte[256];

            var writer = new MemoryBufferWriter <byte>(memory);

            Span <byte> span = writer.GetSpan(4).Slice(0, 4);

            byte[] data = { 1, 2, 3, 4 };

            data.CopyTo(span);

            writer.Advance(4);

            Assert.AreEqual(writer.WrittenCount, 4);
            Assert.IsTrue(span.SequenceEqual(data));

            writer.Clear();

            Assert.AreEqual(writer.WrittenCount, 0);
            Assert.IsTrue(span.ToArray().All(b => b == 0));
        }