You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by thrift thrift <th...@gmail.com> on 2010/05/10 15:41:46 UTC
about optinal field
Hi,
I met a weard problem like below.
I have two struct
struct ReverseRequest {
1: string text,
2: optional i32 int_value,
}
struct ReverseResponse {
1: string reversed_text,
2: optional i32 reversed_int_value,
}
In client side, it set like
ReverseRequest reverseRequest;
reverseRequest.text = "test";
reverseRequest.int_value = 50;
and
When I tried to get response from client
I used
ReverseResponse reverseResponse;
reverseResponse.reversed_int_value;
The thing is that if I use optional keyword, then response will be 0, if
not, the response is 50. But even when I use optional, I also set the
int_value and reversed_int_value. Why 0 is returned?
Re: about optinal field
Posted by thrift thrift <th...@gmail.com>.
Thanks everyone.
I used C++ and I followed Mark's way. It works well then
reverseRequest.__isset.int_value = true;
But there is no explaination about this in the tutorial. I think
documentation needs to be imporved in the future.
Thanks very much.
2010/5/11 Bryan Duxbury <br...@rapleaf.com>
> Or, in Java, use the "private-members" option to force yourself to use the
> accessors.
>
> On Mon, May 10, 2010 at 2:36 PM, Mark Slee <ms...@facebook.com> wrote:
>
> > Is this Java or C++?
> >
> > > > ReverseRequest reverseRequest;
> > > > reverseRequest.text = "test";
> > > > reverseRequest.int_value = 50;
> >
> > Try adding (C++):
> > reverseRequest.__isset.text = true;
> > reverseRequest.__isset.int_value = true;
> >
> > Or (Java):
> > reverseRequest.setText("test");
> > reverseRequest.setIntValue(50);
> >
> >
> > If fields are explicitly marked optional, you need to flag the isset bits
> > to indicate that they are considered present.
> >
> > Cheers,
> > mcslee
> >
> > -----Original Message-----
> > From: Noam Wolf [mailto:noam.wolf@gmail.com]
> > Sent: Monday, May 10, 2010 7:28 AM
> > To: thrift-user@incubator.apache.org
> > Subject: Re: about optinal field
> >
> > Can you provide more code of how you're actually passing the response
> back
> > to the client?
> >
> > On Mon, May 10, 2010 at 10:24 AM, Bryan Duxbury <br...@rapleaf.com>
> wrote:
> >
> > > What language are your clients and servers?
> > >
> > > On Mon, May 10, 2010 at 6:41 AM, thrift thrift <th...@gmail.com>
> > > wrote:
> > >
> > > > Hi,
> > > > I met a weard problem like below.
> > > >
> > > > I have two struct
> > > >
> > > > struct ReverseRequest {
> > > > 1: string text,
> > > > 2: optional i32 int_value,
> > > > }
> > > > struct ReverseResponse {
> > > > 1: string reversed_text,
> > > > 2: optional i32 reversed_int_value,
> > > > }
> > > >
> > > > In client side, it set like
> > > >
> > > > ReverseRequest reverseRequest;
> > > > reverseRequest.text = "test";
> > > > reverseRequest.int_value = 50;
> > > >
> > > > and
> > > > When I tried to get response from client
> > > > I used
> > > > ReverseResponse reverseResponse;
> > > > reverseResponse.reversed_int_value;
> > > >
> > > > The thing is that if I use optional keyword, then response will be 0,
> > if
> > > > not, the response is 50. But even when I use optional, I also set the
> > > > int_value and reversed_int_value. Why 0 is returned?
> > > >
> > >
> >
> >
> >
> > --
> > Best Regards,
> > Noam Wolf
> >
>
Re: about optinal field
Posted by Bryan Duxbury <br...@rapleaf.com>.
Or, in Java, use the "private-members" option to force yourself to use the
accessors.
On Mon, May 10, 2010 at 2:36 PM, Mark Slee <ms...@facebook.com> wrote:
> Is this Java or C++?
>
> > > ReverseRequest reverseRequest;
> > > reverseRequest.text = "test";
> > > reverseRequest.int_value = 50;
>
> Try adding (C++):
> reverseRequest.__isset.text = true;
> reverseRequest.__isset.int_value = true;
>
> Or (Java):
> reverseRequest.setText("test");
> reverseRequest.setIntValue(50);
>
>
> If fields are explicitly marked optional, you need to flag the isset bits
> to indicate that they are considered present.
>
> Cheers,
> mcslee
>
> -----Original Message-----
> From: Noam Wolf [mailto:noam.wolf@gmail.com]
> Sent: Monday, May 10, 2010 7:28 AM
> To: thrift-user@incubator.apache.org
> Subject: Re: about optinal field
>
> Can you provide more code of how you're actually passing the response back
> to the client?
>
> On Mon, May 10, 2010 at 10:24 AM, Bryan Duxbury <br...@rapleaf.com> wrote:
>
> > What language are your clients and servers?
> >
> > On Mon, May 10, 2010 at 6:41 AM, thrift thrift <th...@gmail.com>
> > wrote:
> >
> > > Hi,
> > > I met a weard problem like below.
> > >
> > > I have two struct
> > >
> > > struct ReverseRequest {
> > > 1: string text,
> > > 2: optional i32 int_value,
> > > }
> > > struct ReverseResponse {
> > > 1: string reversed_text,
> > > 2: optional i32 reversed_int_value,
> > > }
> > >
> > > In client side, it set like
> > >
> > > ReverseRequest reverseRequest;
> > > reverseRequest.text = "test";
> > > reverseRequest.int_value = 50;
> > >
> > > and
> > > When I tried to get response from client
> > > I used
> > > ReverseResponse reverseResponse;
> > > reverseResponse.reversed_int_value;
> > >
> > > The thing is that if I use optional keyword, then response will be 0,
> if
> > > not, the response is 50. But even when I use optional, I also set the
> > > int_value and reversed_int_value. Why 0 is returned?
> > >
> >
>
>
>
> --
> Best Regards,
> Noam Wolf
>
RE: about optinal field
Posted by Mark Slee <ms...@facebook.com>.
Is this Java or C++?
> > ReverseRequest reverseRequest;
> > reverseRequest.text = "test";
> > reverseRequest.int_value = 50;
Try adding (C++):
reverseRequest.__isset.text = true;
reverseRequest.__isset.int_value = true;
Or (Java):
reverseRequest.setText("test");
reverseRequest.setIntValue(50);
If fields are explicitly marked optional, you need to flag the isset bits to indicate that they are considered present.
Cheers,
mcslee
-----Original Message-----
From: Noam Wolf [mailto:noam.wolf@gmail.com]
Sent: Monday, May 10, 2010 7:28 AM
To: thrift-user@incubator.apache.org
Subject: Re: about optinal field
Can you provide more code of how you're actually passing the response back
to the client?
On Mon, May 10, 2010 at 10:24 AM, Bryan Duxbury <br...@rapleaf.com> wrote:
> What language are your clients and servers?
>
> On Mon, May 10, 2010 at 6:41 AM, thrift thrift <th...@gmail.com>
> wrote:
>
> > Hi,
> > I met a weard problem like below.
> >
> > I have two struct
> >
> > struct ReverseRequest {
> > 1: string text,
> > 2: optional i32 int_value,
> > }
> > struct ReverseResponse {
> > 1: string reversed_text,
> > 2: optional i32 reversed_int_value,
> > }
> >
> > In client side, it set like
> >
> > ReverseRequest reverseRequest;
> > reverseRequest.text = "test";
> > reverseRequest.int_value = 50;
> >
> > and
> > When I tried to get response from client
> > I used
> > ReverseResponse reverseResponse;
> > reverseResponse.reversed_int_value;
> >
> > The thing is that if I use optional keyword, then response will be 0, if
> > not, the response is 50. But even when I use optional, I also set the
> > int_value and reversed_int_value. Why 0 is returned?
> >
>
--
Best Regards,
Noam Wolf
Re: about optinal field
Posted by Noam Wolf <no...@gmail.com>.
Can you provide more code of how you're actually passing the response back
to the client?
On Mon, May 10, 2010 at 10:24 AM, Bryan Duxbury <br...@rapleaf.com> wrote:
> What language are your clients and servers?
>
> On Mon, May 10, 2010 at 6:41 AM, thrift thrift <th...@gmail.com>
> wrote:
>
> > Hi,
> > I met a weard problem like below.
> >
> > I have two struct
> >
> > struct ReverseRequest {
> > 1: string text,
> > 2: optional i32 int_value,
> > }
> > struct ReverseResponse {
> > 1: string reversed_text,
> > 2: optional i32 reversed_int_value,
> > }
> >
> > In client side, it set like
> >
> > ReverseRequest reverseRequest;
> > reverseRequest.text = "test";
> > reverseRequest.int_value = 50;
> >
> > and
> > When I tried to get response from client
> > I used
> > ReverseResponse reverseResponse;
> > reverseResponse.reversed_int_value;
> >
> > The thing is that if I use optional keyword, then response will be 0, if
> > not, the response is 50. But even when I use optional, I also set the
> > int_value and reversed_int_value. Why 0 is returned?
> >
>
--
Best Regards,
Noam Wolf
Re: about optinal field
Posted by Bryan Duxbury <br...@rapleaf.com>.
What language are your clients and servers?
On Mon, May 10, 2010 at 6:41 AM, thrift thrift <th...@gmail.com> wrote:
> Hi,
> I met a weard problem like below.
>
> I have two struct
>
> struct ReverseRequest {
> 1: string text,
> 2: optional i32 int_value,
> }
> struct ReverseResponse {
> 1: string reversed_text,
> 2: optional i32 reversed_int_value,
> }
>
> In client side, it set like
>
> ReverseRequest reverseRequest;
> reverseRequest.text = "test";
> reverseRequest.int_value = 50;
>
> and
> When I tried to get response from client
> I used
> ReverseResponse reverseResponse;
> reverseResponse.reversed_int_value;
>
> The thing is that if I use optional keyword, then response will be 0, if
> not, the response is 50. But even when I use optional, I also set the
> int_value and reversed_int_value. Why 0 is returned?
>