Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Add support for union, binary fields, and empty structs #14

Merged
merged 5 commits into from
Jun 18, 2014

Conversation

dan-blanchard
Copy link
Contributor

This PR adds support for unions, binary fields, empty structs, and semicolons at the ends of lines within structs, with the goal of allowing someone to load the Apache Storm thrift file.

Some notes about implementation:

  • unions are just loaded up as structs for now. In the future we might want to modify _compat.init_func_generator to enforce the restriction that you are only supposed to set one of the fields of a union.
  • binary fields are just special cases of string, so when receiving string fields in the binary protocol, we try to decode as utf-8 first, but if that fails we just return the bytes.
  • There were a few places where the grammar had OneOrMore instead of ZeroOrMore, which prevented declaring empty structs. I've fixed that.
  • The Thrift IDL specifies that you can use semicolons or commas as list separators in some places, so I've added support for semicolons.

I'll finish adding the test data tomorrow; I just wanted to trigger a travis build to make sure everything was working so far.

`unions` are just loaded up as `structs` for now. In the future we might
want to modify `_compat.init_func_generator` to enforce the restriction
that you are only supposed to set one of the fields of a union.

`binary` fields are just special cases of `string`, so when receiving
`string` fields in the binary protocol, we try to decode as `utf-8`
first, but if that fails we just return the bytes.

There were a few places where the grammar had `OneOrMore` instead of
`ZeroOrMore`, which prevented declaring empty structs. I've fixed that.
@dan-blanchard
Copy link
Contributor Author

This is supposed to address #13.

@dan-blanchard
Copy link
Contributor Author

Alright, now I've added unit tests that use the Storm thrift file and make sure we can load empty structs, unions, things with semicolons, and the binary field type.

I'm only seeing one unit test failure and that's with test_rpc on pypy, and I have no idea why that's happening, since I didn't change anything related to that.

@dan-blanchard
Copy link
Contributor Author

Actually, I guess that pypy failure was just a onetime fluke. Everything passes now.

lxyu added a commit that referenced this pull request Jun 18, 2014
Add support for union, binary fields, and empty structs
@lxyu lxyu merged commit f17906f into Thriftpy:master Jun 18, 2014
@dan-blanchard dan-blanchard deleted the support_storm branch June 18, 2014 17:49
@lxyu
Copy link
Contributor

lxyu commented Jun 18, 2014

Thank you very much for your excellent PR!

@dan-blanchard
Copy link
Contributor Author

Thank you for making a nicer version of thrift for Python so that I didn't have to. 😄

lxyu added a commit that referenced this pull request Jun 18, 2014
The cybinary protocol uses local cdef TTypes, which was missed in #14
@lxyu
Copy link
Contributor

lxyu commented Jun 18, 2014

FYI, I just did a v0.1.3 release. You may use pypi for convenient installation now.

@dan-blanchard
Copy link
Contributor Author

Awesome. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants