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

example for a custom serialization and deserialization #270

Closed
Hugo-Trentesaux opened this issue Jun 2, 2019 · 4 comments
Closed

example for a custom serialization and deserialization #270

Hugo-Trentesaux opened this issue Jun 2, 2019 · 4 comments

Comments

@Hugo-Trentesaux
Copy link

@Hugo-Trentesaux Hugo-Trentesaux commented Jun 2, 2019

Where could I find an example on how to build a custom serializer / deserializer with bincode for my structure? Or do I have to implement my own functions to replace bincode::serialize and bincode::deserialize?

@jdm
Copy link
Member

@jdm jdm commented Jun 6, 2019

@Hugo-Trentesaux I'm not sure I understand what you are asking. Could you give a code example of what you are trying to accomplish?

@Hugo-Trentesaux
Copy link
Author

@Hugo-Trentesaux Hugo-Trentesaux commented Jun 6, 2019

For example, I have an enum that I know can only take two values (a hash or a signature). I would like to store the variant on only 1 byte instead of 8. For now, I'm using two option, but that's does not represent what I want (I never have both hash and signature).

@jdm
Copy link
Member

@jdm jdm commented Jun 6, 2019

I don't believe there is anything specific to bincode involved in that. You would write a custom Serialize/Deserialize implementation for your type, and if you ran bincode::serialize on it then it would be invoked appropriately.

@jdm
Copy link
Member

@jdm jdm commented Jun 6, 2019

https://github.com/servo/ipc-channel/blob/master/src/ipc.rs#L802-L822 is not a super clear example, but it does show a custom serialization that is used with the bincode serializer.

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.