-
Notifications
You must be signed in to change notification settings - Fork 47
Description
I am writing a transport to encapsulate SerialPort to add framing and encoding (serde). When I want to read from the port, I need to allocate some space in my Transport but I don't know how many bytes to allocate until the read is actually performed. This means I need to keep an intermediate buffer for bytes to be read into, and then I can copy the number of bytes actually read from the port into my Transport.
However, SerialPort already has internal buffering with a default size of 128 bytes for the read buffer. So, I am effectively triple buffering and copying twice for no good reason.
On the host side with the serialport crate, I can query the number of bytes available in the OS buffer with SerialPort::bytes_to_read(). It is trivial for me to allocate space in my Transport with this API and copy only once.