-
Notifications
You must be signed in to change notification settings - Fork 7
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
json_string and embedded struct #53
Comments
I think that's something the |
It's not supposed to (show only bytes) though... because the |
I've just run cargo-expand on it, and see BinRead impl show up first, then simd-json-derive, then bitfield. |
Can I collect all structs and then manually serialize them into JSON? Doing this as the last step should help avoid this out-of-order macro expansion/execution. |
you could try changing the order of the macros, I think that determines what gets executed first, so if |
I tried this... it doesn't :( |
Macro expansion starts with the top-most attribute, yes. #[derive(Debug, BinRead, Serialize)]
#[br(map = Self::from_bytes)]
#[bitfield]
pub struct Flags { ... }
If you add |
Funny story, I am indeed using a custom Serialize impl like this but for the bitfield. Although the fields aren't available, the functions to get to them were ( |
json objects aren't sorted so order is probably not important As to an implementation, I feel like it would have a better home in the bitfield crate. Perhaps they're open to a PR to implement it in the bitfield crate. The reasoning is simple there are way fewer crates doing serialization then there are data structure crates. So if the serialization creates implements all the serializers then they quickly become unwieldy and large with a ton of dependencies and feature flags on the other hand if data structure crates implement the handful of serializer, it's not too much of a addition to each crate. |
Absolutely, no worries. |
bitfield is supposed to return the parsed struct. Instead it just returns input array (bytes).
(
fn from_bytes([u8; 1]) -> Self
)Ref: https://docs.rs/modular-bitfield/latest/modular_bitfield/#generated-implementations
To reproduce:
So it looks like
json_string
is acting before binrw can derive thosebytes
.When trying to manually
impl Serialize
forFlags
,self.
only showsself.bytes
.This explains why json_string just dumps the
bytes
as is.Any idea how to make this right?
Somehow, Serialize should run after binrw's map.
But placing it like this (innocently) doesn't help:
The text was updated successfully, but these errors were encountered: