Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDeserialize error #130
Deserialize error #130
Comments
|
Bincode does not support untagged enums. Staring at some bytes, there is no way to tell whether those bytes came from a string or number or boolean. If you need to use bincode then use tagged enums. |
|
Thank you. |
Would it not be possible to devote one byte to select the right variant for an enum and then read it? I know it wouldn't work for very long untagged enums, but for common cases like 2 variants, that should be enough, no? |
|
That's not an untagged enum anymore... If you mean a byte for type information, not for the variant tag: that's not Bincode anymore... |
|
No, I meant for the variant thing. I have a use case where the same struct is deserialized from JSON (out of my control) and I want to be able to serialize/deserialize it using bincode for performance. In result, since in JSON we have to deserialize based on "shape", I need to use untagged, but then I can serialize/deserialize bincode however I want, so adding a byte that says basically "variant 0" or "variant 1" and the proceeding bytes store the value, feel like it should be doable, but I'm not very familiar with intrinsics of bincode. |
|
I am running in the same issue here, deserialization from JSON, and serialization into bincode. |
|
@zbraniecki if you use a byte to store the variant though, then its not an untagged enum anymore. Serde just tells us to serialize a struct, we get no information that this is an enum at all, so we couldn't put a variant on it anyways. |
|
I see. Maybe there's some information we could get out of serde? If you knew you're looking at an untagged enum, you could take the first byte as a variant selection? |
|
I looked at serde and there doesn't seem to be a way to get extra info out of it. You should probably open an issue on serde. |
Error message:
It will pass if I remove
#[serde(untagged)].