-
Notifications
You must be signed in to change notification settings - Fork 99
packed regression for enum variants with data? #173
Comments
See release notes: https://github.com/pyfisch/cbor/releases/tag/v0.10.0
|
I don't see a way to tell serde to use anything other than the default, although there's a lot about serde that I don't understand, so I could be overlooking something obvious to everyone else. If it's not possible to do that, would you be interested in a PR to making it possible to change the default so that serde can write more compact enums when using If there's already a way to do that, it would be handy (to me at least!) to have that info in the Packed Encoding portion of the documentation. If not, and you want a PR, I'll be sure to update that section of the documentation explaining how (and why) to use the new feature. If there's not a way to do it and you don't want a PR to add that capability, I'm happy to write a doc-only PR that updates that section of the documentation so that others won't be surprised by the behavior. |
I now understand what you mean.
I'll accept both a PR fixing the issue or a PR containing documentation for the current behavior. |
I hope I'm not wasting anyone's time, but it seems to me that if value.serialize(&mut Serializer::new(&mut IoWrite::new(&mut vec)).packed_format().legacy_enums())?; but I can't reconcile that fix with:
My backstory is that I'm using yew with actix-web and had been using json to pass messages through a websocket with the idea that I'd eventually move to a more compact binary representation. I assumed this would be trivial since both the client and server are using Rust. When I started pursuing the binary format, yew was using serde_cbor 0.9.0 and my cursory exploration of Since I wasn't around when a lot of this ground was already covered, I'm guessing that I'm missing something, but I don't know what. AFAICT, the internal machinations of |
Of course shortly after I wrote the above, I realized I ahd made a mistake concerning |
So, indeed any user who is paying attention can create a routine comparable to I think I understand the situation well enough to update the documentation, but I'm wondering if you'd be willing to introduce a As it is, I introduced a I'll prepare a patch which includes |
No, please do not add more methods to serde-cbor. As you see the interactions between different features already cause problems and originally I planned to remove the old encoding in a future version. |
Legacy enum format supported packed encoding pretty well but with the switch to new enum format there was a regression (pyfisch#173). This commit fixes the new enum format in packed encoding. For example consider the following structure: ```rust enum Enum { Unit, NewType(i32), Tuple(i32, i32), Struct { x: i32, y: i32 }, } ``` Legacy enum packed encodings are: ``` Empty: <variant number> NewType: [<variant number>, value] Tuple: [<variant number>, values..] Struct: [<variant number>, {<struct>}] ``` Non-legacy enum packed encodings before this commit: ``` Empty: <variant number> NewType: {"<variant>": value} Tuple: {"<variant>": [values..]} Struct: {<variant number>: {<struct>}} ``` Notice how NewType and Tuple store the name instead of variant number. Fixed after this commit: ``` Empty: <variant number> NewType: {<variant number>: value} Tuple: {<variant number>: [values..]} Struct: {<variant number>: {<struct>}} ``` After this commit the packed encoding can be briefly described as: All structs fields and enum variants are identified by their number rather than name. This applies to all types of members (unit, newtype, tuple and struct).
Fixes pyfisch#187 Legacy enum format supported packed encoding pretty well but with the switch to new enum format there was a regression (pyfisch#173). This commit fixes the new enum format in packed encoding. For example consider the following structure: ```rust enum Enum { Unit, NewType(i32), Tuple(i32, i32), Struct { x: i32, y: i32 }, } ``` Legacy enum packed encodings are: ``` Empty: <variant number> NewType: [<variant number>, value] Tuple: [<variant number>, values..] Struct: [<variant number>, {<struct>}] ``` Non-legacy enum packed encodings before this commit: ``` Empty: <variant number> NewType: {"<variant>": value} Tuple: {"<variant>": [values..]} Struct: {<variant number>: {<struct>}} ``` Notice how NewType and Tuple store the name instead of variant number. Fixed after this commit: ``` Empty: <variant number> NewType: {<variant number>: value} Tuple: {<variant number>: [values..]} Struct: {<variant number>: {<struct>}} ``` After this commit the packed encoding can be briefly described as: All struct fields and enum variants are encoded as their field number rather than name. This applies to all types of members (unit, newtype, tuple and struct).
With cbor 0.10, enum variant names are serialized if the variant carries data. Here's an example:
Under 0.9 the output is:
Under 0.10:
The text was updated successfully, but these errors were encountered: