Zhoutian Feng created THRIFT-4627:
-------------------------------------
Summary: member of __isset is initialized as true for optional
fields with default values
Key: THRIFT-4627
URL: https://issues.apache.org/jira/browse/THRIFT-4627
Project: Thrift
Issue Type: Question
Components: C++ - Compiler
Affects Versions: 0.11.0
Reporter: Zhoutian Feng
I'm a little confused about the behavior of optional fields with default values
in a struct.
If I define a struct like this:
{code:c++}
struct Message {
1: optional string msg_type = "raw";
}
{code}
The cpp generator will generate codes like this:
{code:c++}
typedef struct _Message__isset {
_Message__isset() : msg_type(true) {}
bool msg_type: 1;
} _Message__isset;
{code}
Even though the server side does not receive any *Message* from the client, it
generates a *Message* with Message.msg_type = "raw" and
Message.__isset.msg_type = true.
However, the related part of the document says that "only fields with this flag
set are written, and conversely the flag is only set when a field value has
been read from the input stream" (see [Thrift
IDL|https://thrift.apache.org/docs/idl])
So I think for a field with default value, its __isset flag should still be
*false* if its value is not read from a input stream.
I want to give a default value to the field but I also want to distinguish the
situation that users don't set it (for example, users use an older client that
does not have the Message struct at all)
Can anybody explain about the reason of this design and tell me how can I
implement the requirement mentioned above? Appreciate for that.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)