Exemple #1
0
        public void TestConsumeHe()
        {
            var buffer = Encoding.ASCII.GetBytes("Hello world.!");
            var slice  = new BufferSlice(buffer, 0, buffer.Length, buffer.Length);
            var reader = new BufferSliceReader(slice);

            reader.Consume('H', 'e');
            Assert.Equal('l', reader.Current);
            Assert.Equal('l', reader.Peek);
        }
Exemple #2
0
        public void TestConsumeEnd()
        {
            var buffer = Encoding.ASCII.GetBytes("Hello  \tworld.!");
            var slice  = new BufferSlice(buffer, 0, buffer.Length, buffer.Length);
            var reader = new BufferSliceReader(slice);

            reader.ReadUntil('!');
            Assert.Equal('!', reader.Current);
            reader.Consume();
            Assert.True(reader.EndOfFile);
            Assert.Equal(0, reader.RemainingLength);
        }
Exemple #3
0
        public void TestConsume()
        {
            var buffer = Encoding.ASCII.GetBytes("Hello world.!");
            var slice  = new BufferSlice(buffer, 0, buffer.Length, buffer.Length);

            var reader = new BufferSliceReader(slice);

            reader.Consume();
            Assert.Equal(slice.Count, reader.Length);
            Assert.Equal(slice.RemainingLength, reader.RemainingLength);
            Assert.Equal('e', reader.Current);
            Assert.Equal('l', reader.Peek);
            Assert.True(reader.HasMore);
        }
        /// <summary>
        /// Try to find a header name.
        /// </summary>
        /// <returns></returns>
        private bool GetHeaderName()
        {
            // empty line. body is begining.
            if (_reader.Current == '\r' && _reader.Peek == '\n')
            {
                // Eat the line break
                _reader.Consume('\r', '\n');

                _isComplete   = true;
                _parserMethod = ParseFirstLine;
                return(false);
            }

            _headerName = _reader.ReadUntil(':');
            if (_headerName == null)
            {
                return(false);
            }

            _reader.Consume(); // eat colon
            _parserMethod = GetHeaderValue;
            return(true);
        }