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

Include an Unspecified Value in Enums #171

Open
gmaclennan opened this issue Feb 19, 2024 · 2 comments
Open

Include an Unspecified Value in Enums #171

gmaclennan opened this issue Feb 19, 2024 · 2 comments
Labels

Comments

@gmaclennan
Copy link
Member

I know @EvanHahn you brought this up. Our use of ts-proto kind of hides that this is needed, but the protobuf docs recommend it. It seems it is only really an issue for enums added after initial release (because decoding when the enum is missing will decode the default enum), but maybe it's best for us to start with this? We could hide it in our encode/decode functions by setting a default enum value when it is unspecified.

@gmaclennan gmaclennan added the mvp label Feb 19, 2024
@EvanHahn
Copy link
Contributor

I think it depends on the use case, but I generally feel we should have some "unknown" default value for enums.

I agree that our decoder code can treat unknown as some other default. For example, we might decide that unrecognized invite decisions are equivalent to "REJECT".

@gmaclennan
Copy link
Member Author

Just to be clear, because "unknown" is possibly unspecific, there are two different cases:

  • "unrecognized" - this is an enum value that is not recognized, e.g. a newer version of a proto def adds a new enum value, and an older client would not recognize this value. We already handle this (and decode to UNRECOGNIZED)
  • "unspecified" - this is when a newer proto def adds a new enum field, and decodes protobufs from the older def. These enum values would be missing, and protobuf defaults to decode the enum value to the first enum defined (=0).

It's the latter that's the focus of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants