fix(rust): align struct fingerprint nullable flag for enum fields with Java/C++, and fix cross-language Union serialization #3094
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?
When computing struct version hash (fingerprint) for cross-language compatibility, Java and C++ treat enum fields as
nullable=trueby default (since Java enums are reference types that can be null). However, Rust's proc-macro cannot determine at compile time whether a field type is an enum, causing fingerprint mismatch between Rust and Java/C++.For example, a struct like:
Would produce different version hashes in Rust vs Java/C++, breaking cross-language schema compatibility.
What does this PR do?
This PR aligns Rust's struct fingerprint computation with Java/C++ behavior:
Add runtime enum detection for fingerprint computation
gen_struct_version_hash_ts()that generates code to compute fingerprint at runtimefory_static_type_id()to detect enumsAdd helper function
is_enum_type_id()Fix Union-compatible enum handling
xlangparameter tofory_actual_type_id()for proper TypeId selectionfield_need_write_type_info()to handle UNION TypeIdNow Rust computes the same fingerprint as Java/C++.
Related issues
Does this PR introduce any user-facing change?
Note: This changes the struct version hash computation for structs containing enum fields. The new hash will match Java/C++, but may differ from previous Rust versions. This is intentional for cross-language compatibility.
Benchmark
Others
It's really hard to determine this bug 😭...