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

thrift: Improve handling of enums #37

Merged
merged 1 commit into from
May 25, 2016
Merged

thrift: Improve handling of enums #37

merged 1 commit into from
May 25, 2016

Conversation

prashantv
Copy link
Contributor

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.

{
// Unknown enum
request: map[string]interface{}{
"op": "Op(NaN)",

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 :)

@HelloGrayson
Copy link

:shipit:

(❤️ 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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@abhinav
Copy link
Contributor

abhinav commented May 25, 2016

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.
@abhinav
Copy link
Contributor

abhinav commented May 25, 2016

👍

@prashantv prashantv merged commit 05eb763 into dev May 25, 2016
@prashantv prashantv deleted the enum_name branch May 25, 2016 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants