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

postcard support #298

Closed
nim65s opened this issue Feb 2, 2023 · 2 comments
Closed

postcard support #298

nim65s opened this issue Feb 2, 2023 · 2 comments

Comments

@nim65s
Copy link
Contributor

nim65s commented Feb 2, 2023

Hi,

I'm having issues with the provided Serialize / Deserialize implementations, which are currently raising SerdeDeCustom errors with postcard. Here is a minimal example to reproduce this:
https://github.com/nim65s/debug-bitflags-serde-postcard/blob/main/src/postcard.rs

The same example with serde-json is fine, as it is with the tests in src/external/serde_support.rs, but postcard doesn't support the "hash-map"y interfaces of serde.

So I'm wondering: what is the rationale for serializing InternalBitFlags as a struct with bits and not directly as the numeric type ?

Obviously, I can write my own Serialize / Deserialize implementations for u8s, but it would be way cleaner if this was provided by bitflags. Maybe we could provide both and let end users choose between the 2 ?

Context: I'm working in a no-std embedded environment where I need to transfer serialized data over CAN bus, which only accept 8 bytes of data in its frames. Therefore, the 9 extra bytes in the json {"bits":3} is not something I can afford to transfer the bitflags 3, and I think bitflags would be a great way in this use case to allow transfering multiple flags with a very limited footprint on the wire.

@KodrAus
Copy link
Member

KodrAus commented Feb 2, 2023

Hi @nim65s 👋

I’ve actually got a PR open right now in #297 that changes the default serialization format in 2.x to simply use the underlying integer type in non-human-readable formats.

The hashmap-y format originally used there was to maintain compatibility with what you’d get deriving serde traits in 1.x. I’ve moved that compatibility callout, just so users know their serialization data may change between those major versions.

@nim65s
Copy link
Contributor Author

nim65s commented Feb 3, 2023

Thanks a lot @KodrAus ! I tested #297 and it fits perfectly my needs :D

@nim65s nim65s closed this as completed Feb 3, 2023
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

No branches or pull requests

2 participants