-
Notifications
You must be signed in to change notification settings - Fork 228
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
proto enum type and string conversion #815
Comments
Hi @mindbergh, thanks for reaching out. The cel-go stack does not yet implement the new behavior, in part because we will need to support backwards compatibility with existing customers using cel-go in their control planes. We can enable a new type-checker option to support it, but it's been a low priority. What you're looking for seems simpler: string to enum value and back. If you know the enum name, you could expose a type conversion function that better supports string enum names to numeric enum values: Happy to talk more about this though to figure out if there's something simpler that would work. -Tristan |
@TristonianJones thanks for your quick reply. Ideally, I would like to have something like Otherwise, maybe we have to expose a function for each enum type to do the conversion, which seems pretty hard to maintain and less usable. e.g. |
@TristonianJones I've found a method of overriding the current type provider to enable enums to be compared directly with strings, would that reference implementation be valuable? If so I can open a pr to add it as an example or paste it here for posterity |
Feature request checklist
Change
I read from the language spec that "enum as int" is a legacy behavior. And there are build-in conversions from int/string to the corresponding enum type. When I test with cel-go, it looks like the enum is still represented as int.
I wonder if there is a way to convert string both to and from a proto enum.
Example
type(google.protobuf.Field{}.kind) # this is int
Alternatives considered
If the enum is of its corresponding fully-qualified enumeration E, I can probably write a function to convert it to a string.
The text was updated successfully, but these errors were encountered: