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

gen/enum: Generate <Name>_Values function #308

Merged
merged 4 commits into from
May 9, 2017
Merged

Conversation

recht
Copy link
Contributor

@recht recht commented May 4, 2017

This generates a <Name>_Values function for all enums which returns
all known values for that enum.

@CLAassistant
Copy link

CLAassistant commented May 4, 2017

CLA assistant check
All committers have signed the CLA.

@abhinav
Copy link
Contributor

abhinav commented May 4, 2017

Hey, thanks for implementing this. Two things:

  • I'm not sure about introducing a new top-level function. We've generally maintained a policy of avoiding reserving names in the top-level namespace unless absolutely necessary. Are you getting much value out of this function?
  • Can you rename FromText to UnmarshalText and change it to accept a []byte so that it conforms to encoding.TextUnmarshaler? That'll give us support for YAML and some other encodings for free.

@recht
Copy link
Contributor Author

recht commented May 4, 2017

As for the first question: currently there's no way of listing valid values, which makes it quite hard to do anything data driven. I'm all for not having too many top level symbols, but not being able to list values is pretty annoying, and adding it as a func on the type also seems pretty weird to me...

As for renaming: it makes sense, I'll fix that.

@recht
Copy link
Contributor Author

recht commented May 8, 2017

Any update on this?

@abhinav abhinav changed the base branch from dev to enum-text-unmarshaler May 8, 2017 20:16
@abhinav abhinav changed the title Add support for getting all enum values and mapping strings back to enums gen/enum: Generate Get<Name>Values function May 8, 2017
@abhinav
Copy link
Contributor

abhinav commented May 8, 2017

Hey, @recht. Since the UnmarshalText change is independent of the GetValues
change, I pulled it into its own PR. Can you give #309 a look and verify
everything is in order?

For the GetValues change, I buy the need for such a function. We have a
workaround for the namespace issue: ThriftRW ensures that the code generated
for user-defined types does not use underscores even if the user-defined type
had underscores in its name in the Thrift file. This effectively reserves the
namespace of things with underscores for ThriftRW. So we can name these
functions <EnumName>_Values() and not worry about naming conflicts at all.
I've made the required changes for that to this PR. Please review this change
and we will merge it.

abhinav added a commit that referenced this pull request May 9, 2017
This changes generated code for enums to implement the
encoding.TextUnmarshaler interface. This exposes a simple API to users
for reading enums by name in addition to integrating better with
other encoding libraries.

(This was pulled from #308. Thanks @recht!)
@abhinav abhinav closed this May 9, 2017
abhinav pushed a commit that referenced this pull request May 9, 2017
This changes generated code for enums to implement the
encoding.TextUnmarshaler interface. This exposes a simple API to users
for reading enums by name in addition to integrating better with
other encoding libraries.

(This was pulled from #308. Thanks @recht!)
@abhinav abhinav changed the base branch from enum-text-unmarshaler to dev May 9, 2017 15:48
@abhinav abhinav reopened this May 9, 2017
@abhinav abhinav changed the title gen/enum: Generate Get<Name>Values function gen/enum: Generate<Name>_Values function May 9, 2017
@abhinav abhinav changed the title gen/enum: Generate<Name>_Values function gen/enum: Generate <Name>_Values function May 9, 2017
@abhinav
Copy link
Contributor

abhinav commented May 9, 2017

LGTM. @bombela @prashantv can one of you have a look when you get a chance? Thanks.

@abhinav abhinav merged commit 1204a69 into thriftrw:dev May 9, 2017
@recht recht deleted the enums branch May 9, 2017 19:10
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

Successfully merging this pull request may close these issues.

4 participants