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

readBytes instead of read #300

Open
chrisflesher opened this issue Nov 30, 2020 · 1 comment
Open

readBytes instead of read #300

chrisflesher opened this issue Nov 30, 2020 · 1 comment

Comments

@chrisflesher
Copy link

chrisflesher commented Nov 30, 2020

The WiFiClient inherits from Stream which has the readBytes function. I got confused using the read function that reads multiple bytes, this essentially does the same thing as readBytes but doesn't leverage other Stream functionality (e.g. timeouts). Is the read function with multiple parameters necessary? Could it just be removed to avoid confusion?

@JAndrassy
Copy link

JAndrassy commented Jan 9, 2022

The read(buffer, size) function must be implemented because it is pure virtual in Client which is the core base class for WiFiClient. Usually use of read(buffer, size) is much more efficient for networking than read(byte), because it can read out the internal buffers faster. But unfortunately If Client is accessed as Stream, this method is not visible.

Some years ago I prepared a git pull request to add read(buffer,size) to Stream, but then I canceled it because as you say it would cause confusion.

readBytes is implemented in Stream.h (base class for Client.h) and it is one of the blocking function which wait for the next byte.

there are some historical backward compatibility reasons for the current design of the Print<-Stream<-Client hierarchy.

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

No branches or pull requests

2 participants