AeroRust/nmea

Iterator-based parser

Opened this issue · 2 comments

This idea was mentioned in #9 and will greatly improve the usability of the crate by providing an iterator-based parser that will parse new messages from e.g. streamed/received bytes when \r\n ending is present.

  • Extend with bytes (similar to Iterator::chain)
  • Extend with a single byte (optional)
  • try_next() try to parse the currently collected bytes (by searching for an ending - \r\n)

Enhancements:

  • Track both the ending \r\n but also the start of a message ! (for AIS messages) or $ (for all other) in the iterator.

what is meant by 'try_next' impl there? implementation of trait futures::stream::{TryStreamExt} or something similar, but locally defined?

try_next() as in a method that allows you to try and parse a whole sentence:

  • If the buffer contains more than 1 it will parse and return one, like Iterator::next(). This will leave any other partial or full sentences in the buffer for the next try_next() call
  • if it fails to parse (when there are not enough bytes) it will return None
  • and if a sentence is full but invalid - an error.