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); }
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); }
static void BytesReaderBasic() { var eol = new ReadOnlySpan <byte>(s_eol); foreach (var iteration in Benchmark.Iterations) { var reader = new BytesReader(s_bytes, SymbolTable.InvariantUtf8); using (iteration.StartMeasurement()) { while (true) { var result = reader.ReadRangeUntil(eol); if (result == null) { break; } reader.Advance(eol.Length); } } } }