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

Read*Until should do an hybrid of seek/read? #492

Open
Suisse00 opened this issue Jul 24, 2022 · 0 comments
Open

Read*Until should do an hybrid of seek/read? #492

Suisse00 opened this issue Jul 24, 2022 · 0 comments

Comments

@Suisse00
Copy link

Hi,

This is kinda an open question as some code review feedback.

Disclaimer: I'm not a heavy Arduino user, I could miss some code, some forum posts, ...

My feedback goes around the discrepancy between giving tools to users to get data easily using a separator and the real implementation.

I'm assuming most of your community are beginners with embedded and programming, hence the readBytesUntil, readStringUntil, find, ... functions.

Such functions job should be described as "return data if the terminator has been found otherwise keep adding data in the buffer".
Meaning, if we didn't receive the terminator yet, we will wait until we get it before returning everything. No data should be read as per the Stream until we know the terminator is there. So calling the function more than once will return the complete data.
(Eg. of the complete expected string: "ABCDEF\n" where \n is the terminal character; if we receive "AB", then "CDEF\n", where we call read*Until each time, we should get "ABCDEF", NOT "CDEF")

In the case of the Arduino, my assumption is that the last part ("keep adding data in the buffer") is impossible because of the low RAM constraint.

Which let me introduce some potential solutions:

  • readUntil do a hybrid between reading and seeking. Seek until we found the terminator character, making multiple calls to readUntil possible if we can't find yet the terminator. When it is found, move the current read position (referenced as head in the code) to the terminator character to do as if everything has been read. User (or read*Until?) would have the job to discard data if the buffer is full.
  • keep read*Until as it is now, but add a seek find/findUntil (As a dev I would prefer if it returns the index of the match but since it is oriented to be beginner friendly and find/findUtil return a bool I guess you should return a bool)

Labels suggestion:

enhancement
question
waiting for feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants