コード例 #1
0
        private void TestReadLine()
        {
            byte[] bytes = _encoding.GetBytes("Hej\r\npå\r\ndig\r\n\t multi.\r\n");
            _reader.Assign(bytes, 0, bytes.Length);
            Assert.Equal("Hej", _reader.ReadLine());
            Assert.Equal("på", _reader.ReadLine());
            string temp = _reader.ReadLine();

            Assert.Equal("dig multi.", temp);
        }
コード例 #2
0
 /// <summary>
 /// Continue parsing a message
 /// </summary>
 /// <param name="buffer">Byte buffer containing bytes</param>
 /// <param name="offset">Where to start the parsing</param>
 /// <param name="count">Number of bytes to parse</param>
 /// <returns>index where the parsing stopped.</returns>
 /// <exception cref="ParserException">Parsing failed.</exception>
 public int Parse(byte[] buffer, int offset, int count)
 {
     _buffer = buffer;
     _reader.Assign(buffer, offset, count);
     while (_parserMethod())
     {
         ;
     }
     return(_reader.Index);
 }
コード例 #3
0
ファイル: HttpParser.cs プロジェクト: wingcd/utnt
 /// <summary>
 /// Continue parsing a message
 /// </summary>
 /// <param name="buffer">Byte buffer containing bytes</param>
 /// <param name="offset">Where to start the parsing</param>
 /// <param name="count">Number of bytes to parse</param>
 /// <returns>index where the parsing stopped.</returns>
 /// <exception cref="ParserException">Parsing failed.</exception>
 public int Parse(byte[] buffer, int offset, int count)
 {
     _logger.Trace("Parsing " + count + " bytes from offset " + offset + " using " + _parserMethod.Method.Name);
     _buffer = buffer;
     _reader.Assign(buffer, offset, count);
     while (_parserMethod())
     {
         _logger.Trace("Switched parser method to " + _parserMethod.Method.Name + " at index " + _reader.Index);
     }
     return(_reader.Index);
 }
コード例 #4
0
        internal void Lex(byte[] bytes, Action <string> onFirstLine, Action <string, string> onHeader, Action <byte[]> onBody)
        {
            _onBody       = onBody;
            _onHeader     = onHeader;
            _onFirstLine  = onFirstLine;
            _parserMethod = ParseFirstLine;

            _buffer = bytes;

            _logger.Debug("Lexing " + _buffer.Length + " bytes.");
            _reader.Assign(_buffer, 0, _buffer.Length);

            while (_parserMethod())
            {
                _logger.Trace("Switched lexer method to " + _parserMethod.Method.Name + " at index " + _reader.Index);
            }
        }