Beispiel #1
0
        public void PeekReturnsByteWithoutMoving()
        {
            var reader = new ReadableBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 }));

            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Peek());
        }
Beispiel #2
0
        public void PeekReturnsByteWithoutMoving()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2));

            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Peek());
        }
        public void EmptySegmentsAreSkippedOnMoveNext()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { 1 }, new byte[] { }, new byte[] { }, new byte[] { 2 } });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
            reader.Skip(1);
            Assert.Equal(2, reader.Peek());
        }
Beispiel #4
0
        public void SkipSingleBufferSkipsBytes()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2, 3, 4, 5 }, 0, 5));

            reader.Skip(2);
            Assert.Equal(3, reader.Peek());
            reader.Skip(2);
            Assert.Equal(5, reader.Peek());
        }
Beispiel #5
0
        public void EmptySegmentsAreSkippedOnMoveNext()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1, 2 });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
            reader.Skip(1);
            Assert.Equal(2, reader.Peek());
        }
Beispiel #6
0
        public void PeekWorkesWithEmptySegments()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] {  }, new byte[] { 1 } });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
Beispiel #7
0
        public void PeekTraversesSegments()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { 1 }, new byte[] { 2 } });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Take());
            Assert.Equal(2, reader.Peek());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
Beispiel #8
0
        public void PeekWorkesWithEmptySegments()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1 });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(0, reader.Index);
            Assert.Equal(1, reader.Span.Length);
            Assert.Equal(1, reader.Peek());
            Assert.Equal(1, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
Beispiel #9
0
            public void SkipSingleBufferSkipsBytes()
            {
                var reader = new ReadableBufferReader(BufferUtilities.CreateBuffer(new byte[] { 1, 2, 3, 4, 5 }));

                reader.Skip(2);
                Assert.Equal(2, reader.Index);
                Assert.Equal(3, reader.Span[reader.Index]);
                Assert.Equal(3, reader.Peek());
                reader.Skip(2);
                Assert.Equal(5, reader.Peek());
                Assert.Equal(4, reader.Index);
                Assert.Equal(5, reader.Span[reader.Index]);
            }
Beispiel #10
0
        public void PeekTraversesSegments()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1, 2 });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Span[reader.Index]);
            Assert.Equal(1, reader.Take());

            Assert.Equal(2, reader.Span[reader.Index]);
            Assert.Equal(2, reader.Peek());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
Beispiel #11
0
        public void WorkesWithEmptyBuffer()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 0 }, 0, 0));

            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
 public void PeekReturnsMinuOneByteInTheEnd()
 {
     var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2));
     Assert.Equal(1, reader.Take());
     Assert.Equal(2, reader.Take());
     Assert.Equal(-1, reader.Peek());
 }
        public void CtorFindsFirstNonEmptySegment()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { 1 } });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
        }
Beispiel #14
0
        public void CtorFindsFirstNonEmptySegment()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 1 });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(1, reader.Peek());
        }
Beispiel #15
0
        public void PeekReturnsMinuOneByteInTheEnd()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2));

            Assert.Equal(1, reader.Take());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
        }
Beispiel #16
0
        public void SkipToEndThenPeekReturnsMinusOne()
        {
            var reader = new ReadableBufferReader(Factory.CreateWithContent(new byte[] { 1, 2, 3, 4, 5 }));

            reader.Skip(5);
            Assert.True(reader.End);
            Assert.Equal(-1, reader.Peek());
        }
Beispiel #17
0
        public void PeekReturnsMinuOneByteInTheEnd()
        {
            var reader = new ReadableBufferReader(Factory.CreateWithContent(new byte[] { 1, 2 }));

            Assert.Equal(1, reader.Take());
            Assert.Equal(2, reader.Take());
            Assert.Equal(-1, reader.Peek());
        }
Beispiel #18
0
        public void PeekGoesToEndIfAllEmptySegments()
        {
            var buffer = BufferUtilities.CreateBuffer(new[] { new byte[] { }, new byte[] { }, new byte[] { }, new byte[] { } });
            var reader = new ReadableBufferReader(buffer);

            Assert.Equal(-1, reader.Peek());
            Assert.True(reader.End);
        }
        public void SkipToEndThenPeekReturnsMinusOne()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2, 3, 4, 5 }, 0, 5));

            reader.Skip(5);
            Assert.True(reader.End);
            Assert.Equal(-1, reader.Peek());
            Assert.True(reader.Cursor.IsEnd);
        }
Beispiel #20
0
        public void WorkesWithEmptyBuffer()
        {
            var reader = new ReadableBufferReader(Factory.CreateWithContent(new byte[] { }));

            Assert.Equal(0, reader.Index);
            Assert.Equal(0, reader.Span.Length);
            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }
Beispiel #21
0
        public void SlicingBufferReturnsCorrectCursor()
        {
            var buffer = ReadableBuffer.Create(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 10);
            var sliced = buffer.Slice(2);

            var reader = new ReadableBufferReader(sliced);

            Assert.Equal(sliced.Start, reader.Cursor);
            Assert.Equal(2, reader.Peek());
        }
Beispiel #22
0
        public void SlicingBufferReturnsCorrectCursor()
        {
            var buffer = Factory.CreateWithContent(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            var sliced = buffer.Slice(2);

            var reader = new ReadableBufferReader(sliced);

            Assert.Equal(sliced.ToArray(), buffer.Slice(reader.Cursor).ToArray());
            Assert.Equal(2, reader.Peek());
            Assert.Equal(0, reader.Index);
        }
        public async Task PeekTraversesSegments()
        {
            using (var factory = new PipelineFactory())
            {
                var readerWriter = factory.Create();
                var w = readerWriter.Alloc();
                w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1));
                w.Append(ReadableBuffer.Create(new byte[] { 2 }, 0, 1));
                await w.FlushAsync();

                var result = await readerWriter.ReadAsync();
                var buffer = result.Buffer;
                var reader = new ReadableBufferReader(buffer);

                Assert.Equal(1, reader.Take());
                Assert.Equal(2, reader.Peek());
                Assert.Equal(2, reader.Take());
                Assert.Equal(-1, reader.Peek());
                Assert.Equal(-1, reader.Take());
            }
        }
Beispiel #24
0
        public async Task PeekWorkesWithEmptySegments()
        {
            using (var channelFactory = new ChannelFactory())
            {
                var channel = channelFactory.CreateChannel();
                var w       = channel.Alloc();
                w.Append(ReadableBuffer.Create(new byte[] { 0 }, 0, 0));
                w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1));
                await w.FlushAsync();

                var result = await channel.ReadAsync();

                var buffer = result.Buffer;
                var reader = new ReadableBufferReader(buffer);

                Assert.Equal(1, reader.Peek());
                Assert.Equal(1, reader.Take());
                Assert.Equal(-1, reader.Peek());
                Assert.Equal(-1, reader.Take());
            }
        }
Beispiel #25
0
        public async Task PeekTraversesSegments()
        {
            using (var factory = new PipeFactory())
            {
                var readerWriter = factory.Create();
                var w            = readerWriter.Writer.Alloc();
                w.Append(ReadableBuffer.Create(new byte[] { 1 }, 0, 1));
                w.Append(ReadableBuffer.Create(new byte[] { 2 }, 0, 1));
                await w.FlushAsync();

                var result = await readerWriter.Reader.ReadAsync();

                var buffer = result.Buffer;
                var reader = new ReadableBufferReader(buffer);

                Assert.Equal(1, reader.Take());
                Assert.Equal(2, reader.Peek());
                Assert.Equal(2, reader.Take());
                Assert.Equal(-1, reader.Peek());
                Assert.Equal(-1, reader.Take());
            }
        }
 public void PeekReturnsByteWithoutMoving()
 {
     var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 1, 2 }, 0, 2));
     Assert.Equal(1, reader.Peek());
     Assert.Equal(1, reader.Peek());
 }
        public void WorkesWithEmptyBuffer()
        {
            var reader = new ReadableBufferReader(ReadableBuffer.Create(new byte[] { 0 }, 0, 0));

            Assert.Equal(-1, reader.Peek());
            Assert.Equal(-1, reader.Take());
        }