-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Custom deserialization - seq.next_element() not working as expected on last element of struct #2468
Comments
|
From your description I could assume that you expected that So I think that you get error because data is interpreted as length which gives you very big size to read and trying to read that count of bytes exhausts the whole data stream. |
@Mingun thanks for your quick response. That's a good hint. My program is actually crashing because However, I don't want to read the length from the |
As I already noted, only There was already an issue of requesting API for reading byte arrays with known length, which was closed as not needed (wrongly, I think): #2120. Actually, you need exactly that API |
I just read through the other issue and yes, that seems to be exactly what I would need. Anyways, thanks for you help! |
Hello,
I have a problem with deserializing a struct (byte-array using
bincode2
to struct). The struct looks like this:I cannot use the derive attribute for deserializing because I need to deserialize the ip address depending on the version. Actually, that part works fine in my custom implementation. I went through the deserialization and everything worked out perfectly fine until I get to the
host_key
. When I want to fill thehost_key
of variable length with the rest of the byte array, I get into trouble. I get the following error message:called `Result::unwrap()` on an `Err` value: Io(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" })
Calling
seq.next_element()
on thehost_key: Vec<u8>
only gives me oneu8
. Soseq
seems not to be "empty" in the end and this error is thrown.My implementation:
Can someone help me on this? I was thinking that
seq.next_element()
is supposed to deserialize the rest into aVec<u8>
. Because that's what happens with derive attribute and aVec<u8>
in the end. Unfortunately, that's not the case here.The text was updated successfully, but these errors were encountered: