Exemple #1
0
        public void SkipTests(bool singleSegment)
        {
            byte[] buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var    bytes  = singleSegment
                ? new ReadOnlySequence <byte>(buffer)
                : BufferUtilities.CreateSplitBuffer(buffer, 2, 4);

            var skipReader = new BufferReader <byte>(bytes);

            Assert.False(skipReader.TryAdvanceTo(10));
            Assert.True(skipReader.TryAdvanceTo(4, advancePastDelimiter: false));
            Assert.True(skipReader.TryRead(out byte value));
            Assert.Equal(4, value);

            Assert.True(skipReader.TryAdvanceToAny(new byte[] { 3, 12, 7 }, advancePastDelimiter: false));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(7, value);
            Assert.Equal(1, skipReader.AdvancePast(8));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(9, value);

            skipReader = new BufferReader <byte>(bytes);
            Assert.Equal(0, skipReader.AdvancePast(2));
            Assert.Equal(3, skipReader.AdvancePastAny(new byte[] { 2, 3, 1 }));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(4, value);
        }