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); }
/// <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); }
/// <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); }
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); } }