Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator-based parser #53

Open
elpiel opened this issue Sep 12, 2022 · 2 comments
Open

Iterator-based parser #53

elpiel opened this issue Sep 12, 2022 · 2 comments
Labels
enhancement Hacktoberfest Issues suitable for Hacktoberfest high High priority tasks

Comments

@elpiel
Copy link
Member

elpiel commented Sep 12, 2022

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.
@elpiel elpiel changed the title Iterator parser Iterator-based parser Sep 12, 2022
@elpiel elpiel added enhancement high High priority tasks labels Sep 12, 2022
@elpiel elpiel pinned this issue Jan 24, 2023
@elpiel elpiel added the Hacktoberfest Issues suitable for Hacktoberfest label Oct 12, 2023
@trkohler
Copy link
Contributor

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

@elpiel
Copy link
Member Author

elpiel commented Nov 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Hacktoberfest Issues suitable for Hacktoberfest high High priority tasks
Projects
None yet
Development

No branches or pull requests

2 participants