Skip to content

[Rust] Use the schema's null value when generating enums - #1120

Merged
vyazelenko merged 1 commit into
aeron-io:masterfrom
s1amese2003:fix/rust-enum-null-value
Aug 22, 2026
Merged

[Rust] Use the schema's null value when generating enums#1120
vyazelenko merged 1 commit into
aeron-io:masterfrom
s1amese2003:fix/rust-enum-null-value

Conversation

@s1amese2003

Copy link
Copy Markdown
Contributor

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 uint8 enum whose encoding
declares nullValue="254", it generates NullVal = 0xff_u8. Java, C++ and Go
all generate 254 for the same schema, so a Rust encoder writes a null a peer in
another language does not recognise.

Why

IrGenerator records the null value on the enum's BEGIN_ENUM token. The
VALID_VALUE tokens carry only byteOrder, primitiveType and constValue.
generateEnum read the null value 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 correct.

The same mistake appeared twice, in the enum discriminant and in
From<Enum> for <primitive>. The null value is now resolved once and passed
down, so the two cannot disagree.

Checks

  • ./gradlew runRustTests — 33 passed, 0 failed
  • ./gradlew :sbe-tool:test — pass
  • ./gradlew :sbe-tool:checkstyleMain :sbe-tool:checkstyleTest — pass

Regenerating 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 issue1116 codec.

optional_enum_nullify.xml already covers an enum with a declared null value,
but it declares 255, which is also the uint8 default, so it passes either way.
The new schema declares 254 to separate the two.

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
@vyazelenko
vyazelenko merged commit 7373f23 into aeron-io:master Aug 22, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust] Cannot set the null value of enums, but can in c++, java, go

2 participants