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

Feature request: fromName function in enum generated classes #192

Open
lizjackson-toast opened this issue Aug 31, 2023 · 1 comment
Open

Comments

@lizjackson-toast
Copy link

When working with classes generated from enums, sometimes I have a string and I'd like to grab the corresponding object whose name matches that string. A fromName function within generated enum classes would be helpful so we don't have to write many-line when statements to match strings to their corresponding enum objects.

@andrewparmet
Copy link
Collaborator

The complication here is which enum name to support when an enum's variations all start with the enum name prefix. In this case protokt will cut off the prefix in generated code since the name of a protobuf enum is not important. Which name should be supported in fromName - the original declared name with the prefix, which is used e.g. in the proto3 JSON spec (which also supports the number instead https://protobuf.dev/programming-guides/proto3/#json), or the name in the generated code without it?

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

No branches or pull requests

2 participants