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

bincode error while deserializing file with option #52

Closed
ghotiphud opened this issue Jan 14, 2016 · 11 comments
Closed

bincode error while deserializing file with option #52

ghotiphud opened this issue Jan 14, 2016 · 11 comments

Comments

@ghotiphud
Copy link

@ghotiphud ghotiphud commented Jan 14, 2016

bincode::serde::deserialize_from(&mut file, SizeLimit::Infinite).expect("bincode deserialize error");

thread '<main>' panicked at 'bincode deserialize error: InvalidEncoding(InvalidEncoding { desc: "invalid tag when decoding Option", detail: Some("Expected 0 or 1, got 11") })', ../src/libcore/result.rs:709

I'm going to attempt to build a repro case, but it might take me a while. Thought maybe this would mean more to you than me.

@ghotiphud ghotiphud changed the title bincode panic while deserializing file bincode error while deserializing file with option<string> Jan 14, 2016
@ghotiphud ghotiphud changed the title bincode error while deserializing file with option<string> bincode error while deserializing file with option Jan 14, 2016
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 14, 2016

Are you implementing the serde serializer and deserializer by hand, or are you using serde's compiler plugin to do it for you?

@ghotiphud
Copy link
Author

@ghotiphud ghotiphud commented Jan 14, 2016

I used serde_macros on nightly.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 14, 2016

Hmm. That shouldn't happen.

Are you sure that the struct didn't change between when you serialized the file and when you deserialized it?

@ghotiphud
Copy link
Author

@ghotiphud ghotiphud commented Jan 14, 2016

I've just run it again with the same results.

serialize_into(&mut file, &makes, SizeLimit::Infinite).unwrap();

deserialize_from(file, SizeLimit::Infinite)
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 14, 2016

Ok, I'll need to see your code, is it public somewhere?

@ghotiphud
Copy link
Author

@ghotiphud ghotiphud commented Jan 15, 2016

Gist for repro - https://gist.github.com/ghotiphud/c97ac187a088a45e7d0a

Library to gather data - https://github.com/ghotiphud/edmunds-rs

You'll need an API key to access the Edmunds Api, but I'll loan you my test one. Should I send it to ty@pre-alpha.com?

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 15, 2016

I'm pretty sure that #[serde(skip_serializing)] will just flat-out break bincode.

Bincode relies on the serializer and deserializer following the exact same steps, so if serialization doesn't serialize something, and deserialization expects it to be there, then everything breaks.

I'll do some more experimenting and add this as a warning to the readme.

@ghotiphud
Copy link
Author

@ghotiphud ghotiphud commented Jan 15, 2016

That worked! Is there any way to just ignore fields completely for serialization and deserialization?

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 15, 2016

It should be possible to define a newtype struct like this:

struct Ignore<T: Default>(T);

and then

  • have a custom serialize implementation that doesn't do anything.
  • have a custom deserialize implementation that constructs a Default T.

This might be handy enough that I could just include it in Bincode.

@ghotiphud
Copy link
Author

@ghotiphud ghotiphud commented Jan 15, 2016

I think it would be most handy in serde, at least for my use case... basically saving a Json response off to a file while ignoring some fields.

But for my current experiment, avoiding #[serde(skip_serializing)] should be good enough. Thank you!

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 17, 2016

Apparently serde has #[serde(default)] but it won't work with bincode (bincode has no idea if something is missing or not)

@TyOverby TyOverby closed this Jan 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.