[ 
https://issues.apache.org/jira/browse/THRIFT-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12689626#action_12689626
 ] 

David Reiss commented on THRIFT-409:
------------------------------------

bq. May contain exactly one of the fields in its definition. (Should we go so 
far as to say that the wire protocol only allows for one field in unions?)

I say "yes and no" to this.  Union-aware readers should probably throw an 
exception if more than one field is set, but I think that we should not create 
a special wire-format for unions.  Just use the struct format.

bq. When reading, if it encounters a field it doesn't recognize, it should skip 
the entire field, essentially reporting the field as unset.

That doesn't really work in containers, and I think it actually makes the code 
quite a bit trickier in structs.  Maybe we could have a special setting for 
each union indicating that none of the fields are set.

bq. It should be impossible to have a union with no set field. For nullable 
types, nulls should not be allowed.

I think I disagree with this.  I think we have to have this type of 
representation in order to be able to read a union with no set field.  
Therefore, we might as well give apps the ability to use it.

bq. When you are dealing with a union in-memory, it should be able to tell you 
programmatically which of its fields are set.

Do you mean "which of its fields is set"?  If so, I agree.  Probably just an 
int equal to the id of the field that was read, which will make it faster than 
checking isset for each individual field.

bq. I can't really view the semantics and uses of this.

Your description of the semantics is exactly correct.  In addition, we can make 
it more efficient to determine which field is set.  I'll let Bryan comment on 
the uses.


Also, there is no need to add any new syntax for this while we are 
experimenting with it.  We can just make it an annotation.


> Add "union" to Thrift
> ---------------------
>
>                 Key: THRIFT-409
>                 URL: https://issues.apache.org/jira/browse/THRIFT-409
>             Project: Thrift
>          Issue Type: New Feature
>            Reporter: Bryan Duxbury
>             Fix For: 0.2
>
>
> It would be very helpful to have a "union" construct in Thrift. Let's decide 
> on the design and then break up into sub-issues to add this feature.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to