-
Notifications
You must be signed in to change notification settings - Fork 1k
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_varint should not return 0 upon EOF #4565
Comments
I appreciate the detailed report. I agree that your proposal would be a cleaner API. Within rust-libp2p Overall, especially since we have |
I want to second Max here. These functions are currently exposed in the public API so changing their signature is breaking. But, the good news is, this entire module is scheduled to be deprecated. The relevant issue is here: #4011 There is only one remaining item left after which we can deprecate these functions and remove them in the next breaking release! :) Does that sound like a meaningful path forward to you? Contributions would be very welcome! |
Is the plan to move this module to a different crate or to erase it completely/make it private? |
@mxinden the |
Yeah, it is recommended that you use https://github.com/mxinden/asynchronous-codec instead. In particular https://docs.rs/unsigned-varint/latest/unsigned_varint/codec/struct.UviBytes.html. |
You are obviously also welcome to fork them. The main reason we are removing them is because they unnecessarily add to our API surface. |
Thanks! |
See https://github.com/mxinden/asynchronous-codec/blob/master/src/codec/length.rs :) |
Thanks :) |
Description
from
read_varint
's documentation:I suggest that we change
read_varint
's behaviour so that EOF will not return 0.Motivation
There should be a way to distinguish between EOF at the beginning of the socket and the case where there's an actual 0 on the socket.
Current Implementation
The cleanest way to implement this is to change
read_varint
's return type fromimpl Future<Output = Result<usize, Error>>
toimpl Future<Output = Result<Option<usize>, Error>>
and an EOF will translate intoOk(None)
. That's because EOF is a positive flow, not an error, so it should be in theOk
variant.We'll also need to change the function
read_length_prefixed
to return an Option as well. It should returnOk(None)
if the call toread_varint
returnedNone
If we don't want to break backward compatibility, we can create new functions that will return Option and let the user decide whether to distinguish between 0 and EOF or not to handle with Options. A few suggestions for the new function's name:
Are you planning to do it yourself in a pull request?
Yes
The text was updated successfully, but these errors were encountered: