userzhy opened a new pull request, #3066:
URL: https://github.com/apache/fory/pull/3066
## Why?
This PR implements support for `UNION` type ID in Rust tagged enum
serialization as part of the xlang type system enhancement (issue #3027).
Previously, Rust tagged enums used `ENUM` or `NAMED_ENUM` type IDs in xlang
mode, but according to the xlang specification, tagged union types (like Rust
enums, C++ `std::variant`, Go `Union`) should use the `UNION` type 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?
1. **Add UNION and NONE type IDs** (`rust/fory-core/src/types.rs`):
- Added `UNION = 38` - Tagged union type (one of several alternatives)
- Added `NONE = 39` - Empty/unit type (no data)
- Added corresponding constants
2. **Modify enum serializer** (`rust/fory-core/src/serializer/enum_.rs`):
- Modified `write_type_info` to write `UNION` type ID when in xlang mode
- Modified `read_type_info` to expect `UNION` type ID when in xlang mode
3. **Add tests** (`rust/tests/tests/test_enum.rs`):
- `xlang_tagged_enum_uses_union_type_id`: Verifies that `UNION` type ID
(38) is used in xlang mode
- `xlang_complex_tagged_enum_roundtrip`: Verifies roundtrip serialization
works correctly
### Serialization Format Change in xlang Mode
```text
Before:
| ref flag | ENUM/NAMED_ENUM type id | variant index |
After:
| ref flag | UNION type id (38) | variant index |
```
## Related issues
- Closes #3028
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [x] Does this PR introduce any binary protocol compatibility change?
**Note**: This change affects the binary protocol in **xlang mode only**. In
xlang mode, tagged enums now use the `UNION` type ID (38) instead of `ENUM`
(13) or `NAMED_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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]