thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mayan Moudgill <ma...@bestweb.net>
Subject Re: heterogeneous collections
Date Mon, 03 May 2010 16:22:27 GMT

Yes, you can use unions. This _DOES_ not correspond to list<any>, but to
union A {
   ...
}
list<A>.

So, how are unions implemented?


Consider:
   union Any {
     1: i32 v_i32
     2: double v_double
  };


In C++ this will become a class with fields
   class Any {
     int32_t v_i32;
   double v_double;

     struct __isset {
       bool v_i32;
       bool v_double;
     } __isset;
   }
In other words, memory-wise, this is really a structure

Python:
   class Any:
    def __init__....:
       self.v_i32 = ...
       self.v_double = ...
Also a struct

It may be different in some of the other languages, of course, or in 
v0.3.0, but I'm not sure that the "union" suggestion is that efficient.


Alex Boisvert wrote:
> On Mon, May 3, 2010 at 7:09 AM, Bryan Duxbury <bryan@rapleaf.com> wrote:
> 
> 
>>There is already a totally viable workaround, though - make a Union of the
>>types you want in your collection, and then make the field list<YourUnion>.
>>You get basically all the capabilities with very few drawbacks, plus the
>>ability to include multiple logical "types" in the collection, not just
>>physical types. Of course, if you literally need "any" possible object to
>>go
>>into the collection, then this won't do it for you.
>>
> 
> 
> Thanks for the suggestion, Bryan.
> 
> I'm experimenting with marshalling my values to strings (I only deal with
> basic types such as int32, int64, strings) right now.   If that doesn't
> work, I'll go with your suggestion.
> 
> alex
> 


Mime
View raw message