feat(rust): use UNION type id for tagged enum serialization in xlang mode#3066
Open
userzhy wants to merge 3 commits intoapache:mainfrom
Open
feat(rust): use UNION type id for tagged enum serialization in xlang mode#3066userzhy wants to merge 3 commits intoapache:mainfrom
userzhy wants to merge 3 commits intoapache:mainfrom
Conversation
…mode - Add UNION (38) and NONE (39) type IDs to TypeId enum in types.rs - Modify write_type_info to use UNION type ID in xlang mode - Modify read_type_info to expect UNION type ID in xlang mode - Add tests for UNION type ID in xlang mode Closes apache#3028
Simple enums (all unit variants) should use ENUM type ID. Tagged enums (some variants have data) should use UNION type ID. This fixes the compatibility with Java where simple enums are serialized with ENUM type ID. - Add is_simple_enum() helper to check if all variants are unit types - Pass is_tagged parameter to write_type_info/read_type_info - Update tests to verify correct type ID for both enum types
Collaborator
|
@userzhy I will take a look soon, thanks for contributing this feature |
Contributor
Author
|
@chaokunyang Thanks for your time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
This PR implements support for
UNIONtype ID in Rust tagged enum serialization as part of the xlang type system enhancement (issue #3027). Previously, Rust tagged enums usedENUMorNAMED_ENUMtype IDs in xlang mode, but according to the xlang specification, tagged union types (like Rust enums, C++std::variant, GoUnion) should use theUNIONtype ID (38).This change aligns Rust's tagged enum serialization with C++ variant serialization (#3025) and ensures cross-language compatibility.
What does this PR do?
Add UNION and NONE type IDs (
rust/fory-core/src/types.rs):UNION = 38- Tagged union type (one of several alternatives)NONE = 39- Empty/unit type (no data)Modify enum serializer (
rust/fory-core/src/serializer/enum_.rs):write_type_infoto writeUNIONtype ID when in xlang moderead_type_infoto expectUNIONtype ID when in xlang modeAdd tests (
rust/tests/tests/test_enum.rs):xlang_tagged_enum_uses_union_type_id: Verifies thatUNIONtype ID (38) is used in xlang modexlang_complex_tagged_enum_roundtrip: Verifies roundtrip serialization works correctlySerialization Format Change in xlang Mode
Related issues
Does this PR introduce any user-facing change?
Note: This change affects the binary protocol in xlang mode only. In xlang mode, tagged enums now use the
UNIONtype ID (38) instead ofENUM(13) orNAMED_ENUM(14). This is a breaking change for xlang serialization but aligns with the xlang specification and other language implementations (C++, Go).Benchmark
This change does not introduce any performance impact as it only changes the type ID value written during serialization.