Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove UNSPECIFIED aliases for enums with natural zero values #493

Merged
merged 6 commits into from
Feb 1, 2022

Conversation

astarche
Copy link
Collaborator

@astarche astarche commented Jan 28, 2022

What does this Pull Request accomplish?

Remove UNSPECIFIED aliases for enums with natural zero values

Fixes #444.

Why should this Pull Request be merged?

Enum aliases make it impossible to map protobuf data back to one-or-the-other specific alias. This specifically causes problems and/or confusion in replay/capture and other grpc-json use cases.

Normally the UNSPECIFIED zero-value enum is used as a convention to ensure that the default value of an enum is defined to be invalid/meaningless. This isn't effective when it is aliased to a meaningful zero value from the C API. Also, we use enums along with oneofs which are a different way of ensuring that a value is set. Ultimately, avoiding aliases is more useful than injecting a conventional UNSPECIFIED value that doesn't serve it's intended purpose.

Alternatives Considered

Use mapped enum values to avoid valid zero values. The reason we have zero valued enums is because we're using the enum values from the C API, some of which have zero values. Mapped enums provide a way to avoid this. Reason Rejected: This would be massively API breaking for existing drivers and also deviate from the C API. We can consider offering a "mapped" alternative if there is some case where it is especially useful (consider attribute values, which have a lot of overlap), but we should stay-the-course of supporting an API that uses C enum values directly and that solution is sufficient for now.

Breaking change

This change Does not break binary compatibility.

It will break "source compatibility" for existing clients that intentionally use the UNSPECIFIED enum value for enums that have a value default value. Those clients will need to make some sort of edit after re-running protoc (Very rare. Either a bug or a test.).

What testing has been done?

Ran all RF, Scope, Switch, DCPower, and DAQmx tests. One pre-existing failure.

@astarche astarche added the binary-breaking Change to proto file that requires client updates label Jan 28, 2022
Copy link
Collaborator

@reckenro reckenro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few non-attribute enums that still had the allow_alias and UNSPECIFIED value due to the other 0 value not being directly after it:

  • BT
    • AcpResultsMeasurementStatus
    • PacketType
  • Instr
    • Boolean
    • LinearInterpolationFormat
    • Personality
    • SelfCalStep
  • WLAN
    • OfdmLtfSize
    • OfdmModAccLSigParityCheckStatus
    • OfdmModAccSigBCrcStatus
    • OfdmModAccSigCrcStatus
  • RFSG
    • RoutedSignal

@astarche astarche requested a review from reckenro February 1, 2022 16:28
@astarche astarche merged commit 80e46f4 into ni:main Feb 1, 2022
@astarche astarche deleted the users/astarche/no-zero-aliases branch February 1, 2022 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary-breaking Change to proto file that requires client updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum aliases cause problems in json replay style use cases
3 participants