feat(rust): use UNION type id for tagged enum serialization in xlang mode #3066
+185
−9
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.