readBytesUntil(...) with ethernet client class

Hello,

I am building my first app with the ethernet client class.

Now I was wondering:

Is there any downside in using the readBytesUntil() of the Stream base class?

/* Handle TCP/IP communication. */
 EthernetClient client = server.available();
 client.setTimeout(1000); // 1 second timeout
 
 /* client.available() will be only evaluated if the first is OK*/
 if ( (client) && (client.available()) > 5)
 {
 // We waited for a 5-byte command:
 // 1 byte: Which external instrument...
 // 1 byte: On/Off 
 // 2 bytes: setpoint
 byte buf[5] = { 0,0,0,0,0 };
 char term = '\n';
 for (int i = 0; i < 5; ++i) 
 {
 client.readBytesUntil('\n', buf, 5);
 }
                 // Much more code is here...

 Ethernet.maintain();
 }

The reason why I am asking: That function is not included in the ethernet client documentation, and everybody seems to use the Read() function, which is of course much more work if there is a readBytesuntil method...

Thanks!

Best,
Andreas

 for (int i = 0; i < 5; ++i)
 {
 client.readBytesUntil('\n', buf, 5);
 }

Why are you calling the function 5 times? The first time it is called, it will read up to 5 bytes.

I can't see that calling read() in the loop is "much more work".

That function is not included in the ethernet client documentation

I agree that the inter-linkage of the Reference is rather bad but in the Stream Reference the function is documented and it also informs that the EthernetClient class uses that as a base.

Hello,

indeed you discovered a bug in my code: I shouldn't be calling it 5x. I used Read() before, and then I would have needed to call it 5x. Thanks a lot.

I can't see that calling read() in the loop is "much more work".

I need to do that a lot, so using readBytesUntil(...) is quite useful, or I would have written my very own readBytesUntil method.

I wouldn't say that the reference is bad: I am just new to the Arduino world and therefore I was interested if there is a relevant reason not to use readBytesUntil. Maybe it doesn't work for ethernet or so.

Thanks a lot!

Best,
Andreas

I need to do that a lot, so using readBytesUntil(...) is quite useful, or I would have written my very own readBytesUntil method.

So, your code needs to call read() in a loop, or readBytesUntil() needs to call read() in a loop.

I don't see that passing the buck is buying you anything.

I think that's what libraries are for. Use their methods, classes etc.

In this case it buys me simplified code and therefore less chance to make mistakes.