Beispiel #1
0
        public void MultiSegmentBytesReaderNumbers()
        {
            ReadOnlyBytes bytes = ReadOnlyBytes.Create(new byte[][] {
                new byte[] { 0 },
                new byte[] { 1, 2 },
                new byte[] { 3, 4 },
                new byte[] { 5, 6, 7, 8 },
                new byte[] { 8 }
            });

            var reader = new BytesReader(bytes);

            var value = reader.ReadBytesUntil(2).Value.ToSpan();

            Assert.Equal(0, value[0]);
            Assert.Equal(1, value[1]);
            reader.Advance(1);

            value = reader.ReadBytesUntil(5).Value.ToSpan();
            Assert.Equal(3, value[0]);
            Assert.Equal(4, value[1]);
            reader.Advance(1);

            value = reader.ReadBytesUntil(new byte[] { 8, 8 }).Value.ToSpan();
            Assert.Equal(6, value[0]);
            Assert.Equal(7, value[1]);
            reader.Advance(2);

            //Assert.True(reader.IsEmpty);
        }
Beispiel #2
0
        public void MultiSegmentBytesReader()
        {
            ReadOnlyBytes bytes  = Parse("A|B |CD|#EF&|&");
            var           reader = new BytesReader(bytes);

            var ab = reader.ReadBytesUntil((byte)' ');

            Assert.Equal("AB", ab.ToString(SymbolTable.InvariantUtf8));
            Assert.Equal(2, reader.Index);

            reader.Advance(1);
            Assert.Equal(3, reader.Index);

            var cd = reader.ReadBytesUntil((byte)'#');

            Assert.Equal("CD", cd.ToString(SymbolTable.InvariantUtf8));
            Assert.Equal(5, reader.Index);

            reader.Advance(1);
            Assert.Equal(6, reader.Index);

            var ef = reader.ReadBytesUntil(new byte[] { (byte)'&', (byte)'&' });

            Assert.Equal("EF", ef.ToString(SymbolTable.InvariantUtf8));
            Assert.Equal(8, reader.Index);

            reader.Advance(2);
            Assert.Equal(10, reader.Index);
        }
Beispiel #3
0
        static void BytesReaderBenchmarkBaseline()
        {
            int           sections = 10;
            StringBuilder sb       = new StringBuilder();

            for (int i = 0; i < sections; i++)
            {
                sb.Append("123456789012345678\r\n");
            }
            var data = Encoding.UTF8.GetBytes(sb.ToString());

            var eol   = new Span <byte>(s_eol);
            var bytes = new ReadOnlyBytes(data);

            var reader = new BytesReader(bytes, TextEncoder.Utf8);

            while (true)
            {
                var result = reader.ReadBytesUntil(eol);
                if (result == null)
                {
                    break;
                }
                reader.Advance(2);
            }
        }
Beispiel #4
0
        public void MultiSegmentBytesReader()
        {
            ReadOnlyBytes bytes  = Parse("A|B |CD|#EF&|&");
            var           reader = new BytesReader(bytes);

            var ab = reader.ReadBytesUntil((byte)' ');

            Assert.Equal("AB", ab.ToString(TextEncoder.Utf8));

            reader.Advance(1);
            var cd = reader.ReadBytesUntil((byte)'#');

            Assert.Equal("CD", cd.ToString(TextEncoder.Utf8));

            reader.Advance(1);
            var ef = reader.ReadBytesUntil(new byte[] { (byte)'&', (byte)'&' });

            Assert.Equal("EF", ef.ToString(TextEncoder.Utf8));

            reader.Advance(2);

            //Assert.True(reader.IsEmpty);
        }
Beispiel #5
0
        public void EmptyBytesReader()
        {
            ReadOnlyBytes bytes  = Create("");
            var           reader = new BytesReader(bytes);
            var           found  = reader.ReadBytesUntil((byte)' ');

            Assert.Equal("", found.ToString(TextEncoder.Utf8));

            bytes  = Parse("|");
            reader = new BytesReader(bytes);
            found  = reader.ReadBytesUntil((byte)' ');
            Assert.Equal("", found.ToString(TextEncoder.Utf8));

            //Assert.True(reader.IsEmpty);
        }
Beispiel #6
0
        public void SingleSegmentBytesReader()
        {
            ReadOnlyBytes bytes  = Create("AB CD#EF&&");
            var           reader = new BytesReader(bytes);

            var ab = reader.ReadBytesUntil((byte)' ');

            Assert.True(ab.HasValue);
            Assert.Equal("AB", ab.ToString(TextEncoder.Utf8));

            reader.Advance(1);
            var cd = reader.ReadBytesUntil((byte)'#');

            Assert.Equal("CD", cd.ToString(TextEncoder.Utf8));

            reader.Advance(1);
            var ef = reader.ReadBytesUntil(new byte[] { (byte)'&', (byte)'&' });

            Assert.Equal("EF", ef.ToString(TextEncoder.Utf8));

            reader.Advance(2);

            //Assert.True(reader.IsEmpty);
        }