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

Bryan Duxbury commented on THRIFT-409:
--------------------------------------

bq. Just use the struct format.

I thought of this as an option, but I think that will lead to suboptimal wire 
performance. For instance, we definitely do not need a whole extra stop byte at 
the end of the union just to say there's nothing more coming. There should only 
ever be one field, so I say let's tailor it accordingly.

bq. 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.

I'll admit I'm not sure on how the container thing might work, but I don't 
think it will make the struct code that much more complicated. I was thinking 
that our generated union classes would have a static read() method that could 
return null if an invalid union was read from the wire. If a null union is 
unacceptable in any circumstance, I think we should just use some constant 
"invalid" union or something to indicate there was a problem. However, I don't 
think an empty union should be serializable.

bq. Do you mean "which of its fields is set"

Yep. 

bq. 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.

Maybe. I think we'd kind of have to do a lot of working around the built in 
generator behavior to do this, and if we ultimately decide to have this 
feature, it'd be silly to use annotations for it.

> 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