You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Nevo Hed <nh...@bamboom.com> on 2011/08/08 02:52:48 UTC

Extending a thrift generated object in C++

Hi All

I first asked here<http://stackoverflow.com/questions/6901249/extending-a-thrift-generated-object-in-c>,
but didn't get far, so I'll ask here where I should have asked first.



Using the following .thrift file

struct myElement {
  1: required i32 num,
}

struct stuff {
  1: optional map<i32,myElement> mymap,
}

I get thrift-generated class with an STL map. The instance of this class is
long-lived (I append and remove from it as well as write it to disk using
TSimpleFileTransport).

I would like to extend myElement in C++, the extensions should not affect
the serialized version of this object (and this object is not used in any
other language). Whats a clean way to accomplish that?

I contemplated the following, but they didn't seem clean:

   1. Make a second, non thrift map that is indexed with the same key
      - keeping both in sync could prove to be a pain (even if wrapped in
      another class)
   2. Modify the generated code either by post-processing of the generated
   header (incl. preprocessor hackery).
   3. Similar to #2, but modify the generation side to include the following
   in the generated struct and then define NAME_CXX_EXT in a forced-included
   header

     #ifdef NAME_CXX_EXT
     NAME_CXX_EXT ...
     #endif</li>


All of the above seem rather nasty, any ideas?


Thanks

   -Nevo