-
Notifications
You must be signed in to change notification settings - Fork 35
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
thrift: Improve handling of enums #37
Conversation
{ | ||
// Unknown enum | ||
request: map[string]interface{}{ | ||
"op": "Op(NaN)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kriskowal will be at home :)
(❤️ table test) |
@@ -123,6 +123,15 @@ func valueFromWireMap(spec *compile.MapSpec, w wire.Map) (map[string]interface{} | |||
return result, nil | |||
} | |||
|
|||
func mapEnumValueToName(enumSpec *compile.EnumSpec, result int32) interface{} { | |||
for _, item := range enumSpec.Items { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just setup a static mapping so we don't need to iterate like this every time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the same issue happens in code generation in thriftrw
as well -- @abhinav what do you think about setting up a mapping internally in compile.EnumSpec
and having a method to return the EnumItem
given a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a reverse mapping but it will have undefined behavior when multiple enum items have the same enum value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created thriftrw/thriftrw-go#134
LGTM with minor comments. |
When an enum value is received over the wire, it is formatted using the name. If a name is not found, it is formatted as EnumType(%d) Enums can be specified as: - int32 - Case-insentivie name - EnumType(%d) The last format is so that formatted unknown enums on the result path can be used as input.
👍 |
When an enum value is received over the wire, it is formatted using the
name. If a name is not found, it is formatted as EnumType(%d)
Enums can be specified as:
The last format is so that formatted unknown enums on the result path
can be used as input.