This repository has been archived by the owner on Aug 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Packed encoding of enum still includes variant names for non-unit variants #187
Comments
matix2267
added a commit
to matix2267/cbor
that referenced
this issue
Jun 14, 2021
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).
matix2267
added a commit
to matix2267/cbor
that referenced
this issue
May 22, 2022
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).
# for free
to subscribe to this conversation on GitHub.
Already have an account?
#.
Test case:
Hex dump of the resulting file:
Notice that it includes
Thing3
andThing2
, but notThing4
.From what I can tell, the serialization of unit variants pays attention to
self.packed
, but the serialization of non-unit variants does not.The text was updated successfully, but these errors were encountered: