[Rust] Use the schema's null value when generating enums - #1120
Merged
Conversation
The Rust generator emitted the primitive type's default null value for an enum instead of the one declared in the schema, so a uint8 enum encoding that declares nullValue="254" generated NullVal = 0xff_u8. Java, C++ and Go generate 254 for the same schema, so a Rust encoder wrote a null value a peer in another language does not recognise. IrGenerator records the null value on the enum's BEGIN_ENUM token, while the VALID_VALUE tokens carry only byteOrder, primitiveType and constValue. generateEnum read it from messageBody.get(0), a valid value token, so applicableNullValue() fell back to primitiveType.nullValue(). JavaGenerator reads it from tokens.get(0), which is why Java is unaffected. The same mistake appeared in the enum discriminant and in From<Enum> for <primitive>. Resolve the null value once and pass it down so the two cannot disagree. optional_enum_nullify.xml already covers an enum with a declared null value, but declares 255, which is also the uint8 default, so it passes either way. The new issue1116 schema declares 254 to separate the two. Resolves aeron-io#1116
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.
Fixes #1116.
What
The Rust generator emits the primitive type's default null value for an enum
instead of the one declared in the schema. For a
uint8enum whose encodingdeclares
nullValue="254", it generatesNullVal = 0xff_u8. Java, C++ and Goall generate 254 for the same schema, so a Rust encoder writes a null a peer in
another language does not recognise.
Why
IrGeneratorrecords the null value on the enum'sBEGIN_ENUMtoken. TheVALID_VALUEtokens carry onlybyteOrder,primitiveTypeandconstValue.generateEnumread the null value frommessageBody.get(0)— a valid valuetoken — so
applicableNullValue()fell back toprimitiveType.nullValue().JavaGeneratorreads it fromtokens.get(0), which is why Java is correct.The same mistake appeared twice, in the enum discriminant and in
From<Enum> for <primitive>. The null value is now resolved once and passeddown, so the two cannot disagree.
Checks
./gradlew runRustTests— 33 passed, 0 failed./gradlew :sbe-tool:test— pass./gradlew :sbe-tool:checkstyleMain :sbe-tool:checkstyleTest— passRegenerating every Rust codec in the repository before and after the change
leaves all 133 generated files byte-identical except the two lines above in the
new
issue1116codec.optional_enum_nullify.xmlalready covers an enum with a declared null value,but it declares 255, which is also the
uint8default, so it passes either way.The new schema declares 254 to separate the two.