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

Change UnexpectedEnd to include the expected size #521

Closed
aviramha opened this issue Mar 13, 2022 · 2 comments · Fixed by #522
Closed

Change UnexpectedEnd to include the expected size #521

aviramha opened this issue Mar 13, 2022 · 2 comments · Fixed by #522

Comments

@aviramha
Copy link

Right now the enum variant of ErrorKind UnexpectedEnd is void. I suggest changing it to UnexpectedEnd(usize) so the caller will be able to know how much data it is missing for success.

This will allow development of stream protocols to be more efficient by reserving buffers & calling the decode only when data is complete.

More specifically, I'm now developing a actix-codec Encoder/Decoder and I'd wish to reserve the additional missing data before returning.

Thoughts?

@VictorKoenders
Copy link
Contributor

#[derive(Decode)]
struct Foo {
    a: u64, 
    b: u64
}

Because bincode does not have a look ahead system, if you feed this struct only 1 byte, it would report a UnexpectedEnd(7) as u64 needs 8 bytes. Not the 15 bytes it actually needs. Would this be good enough for your case?

@aviramha
Copy link
Author

Yes.

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

Successfully merging a pull request may close this issue.

2 participants