Skip to content

[Java] Set presence on enum encodings in IR. - #1146

Open
d0ra-1h3-3xpl0ra wants to merge 1 commit into
aeron-io:masterfrom
d0ra-1h3-3xpl0ra:fix-enum-encoding-presence
Open

d0ra-1h3-3xpl0ra wants to merge 1 commit into
aeron-io:masterfrom
d0ra-1h3-3xpl0ra:fix-enum-encoding-presence

Conversation

@d0ra-1h3-3xpl0ra

Copy link
Copy Markdown

Fixes #1063.

IrGenerator never set presence on the BEGIN_ENUM/END_ENUM encoding, so it was always REQUIRED. It is now OPTIONAL when the enum type is optional: either its own presence attribute is optional, or its encodingType names an optional type (e.g. uInt8NULL in the CME iLink schemas). Everything else stays REQUIRED; constant is not propagated.

A field's own presence stays on the BEGIN_FIELD token, where generators already read it. The enum token describes the type, like composite ENCODING tokens, and it is shared through Ir.types(), so it shouldn't depend on which field referenced it. OTF users read the value from the BEGIN_ENUM token (tokens[fromIndex] in onEnum).

Generated code: I generated all 84 valid schemas in the repo before and after, for Java (+DTOs), C++ (+DTOs, +IR), C, C#, Go (struct and flyweight) and Rust, and the sources are byte-identical. Only the .sbeir of the 5 schemas that use an optional enum changes. One case no repo schema covers is an optional enum inside a composite:

  • the C++, C and Go flyweight PRESENCE meta attribute becomes "optional";
  • the Rust composite encoder gains the <name>_opt setter that RustGenerator already has a branch for. The generated crate compiles.

The Java build and tests pass. I didn't run the C++/C, Go and C# test suites locally.

The BEGIN_ENUM/END_ENUM tokens always carried REQUIRED presence because
IrGenerator never set it on the enum encoding. They are now OPTIONAL when
the enum type is optional, either through its own presence attribute or
because its encodingType names an optional type, e.g. uInt8NULL in CME
iLink schemas. A field's presence remains on the BEGIN_FIELD token only.
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.

C++ OTF API presence() returns the wrong value for enums

1 participant