Hi Patrick

What language are you using?
In C++ anyway you have to set the value, as well as set the flag indicating
that it is indeed
set see __isset in the generated code.

Dont know if thats the cleanest thing, but in my local headers I have the
following macros

   #define *THRIFT_HAVE_OPT_FIELD*(O,M)     \

     ((O).__isset.M)

#define *THRIFT_MARK_OPT_FIELD*(O,M)     \

     (O).__isset.M = true

#define *THRIFT_SET_OPT_FIELD*(O,M,V)  { \

     (O).M = (V);                      \

     *THRIFT_MARK_OPT_FIELD*(O,M);       \

}

And would use it as follows

  *THRIFT_SET_OPT_FIELD*(theSession,btest , true);





--
+---------------------------------------------+-------------------------+
| Nevo Hed                                    |         +1-617-302-6175 |
| Senior Principal Embedded Software Engineer | nhed at bamboom dot com |
| Bamboom Labs                                |  http://www.bamboom.com |
+---------------------------------------------+-------------------------+



On Mon, Aug 8, 2011 at 4:51 AM, Patrick Nick <[email protected]> wrote:

> Hi all,
>
> I have started experimenting with Thrift. After running the provided
> tutorial in Java I decided to extend it with my own datatype.
>
> struct Session {
>  1: bool isSessionAlive,
>  2: string sessionID,
>  3: optional string creatingIP,
>  4: optional bool btest,
> }
>
> However, I am observing strange behaviour of the booleans. The server
> creates a session object and fills all 4 fields, setting both the mandatory
> and the optional bool to true.
> When it is sent to the client I read out the values, and at that point the
> mandatory bool "isSessionAlive" is true, but the optional bool "btest"
> evaluates to FALSE.
> If I change the definition file and take away the optional flag, making
> "btest" mandatory, it evaluates to true as expected. The rest of the code
> remains unchanged.
>
> It seems as if I can not get optional booleans to evaluate to true after
> sending an object. Is this a functionality which I don't understand or a
> bug?
> I have not tried in other languages so far, only in Java.
>
> Kind regards,
> Patrick
>

Reply via email to