THRIFT-1518. cpp: Generated C++ code only sends the first optional field in the write() function for a struct

There was some incorrect else if logic added to the CPP generated code, which this patch replaces with the proper functionality.

Patch: Thomas Wiggins

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1292508 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bryan Duxbury 2012-02-22 21:14:10 +00:00
parent efa2fcf325
commit b2507dbb0c

View File

@ -1368,26 +1368,14 @@ void t_cpp_generator::generate_struct_writer(ofstream& out,
indent(out) <<
"xfer += oprot->writeStructBegin(\"" << name << "\");" << endl;
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
bool check_if_set = (*f_iter)->get_req() == t_field::T_OPTIONAL ||
(*f_iter)->get_type()->is_xception();
if (check_if_set) {
if (first) {
first = false;
out <<
endl <<
indent() << "if ";
} else {
out <<
" else if ";
}
out << "(this->__isset." << (*f_iter)->get_name() << ") {" << endl;
out << endl << indent() << "if (this->__isset." << (*f_iter)->get_name() << ") {" << endl;
indent_up();
} else {
if (!first)
out << endl;
first = true;
out << endl;
}
// Write field header
@ -1411,9 +1399,7 @@ void t_cpp_generator::generate_struct_writer(ofstream& out,
}
}
if (!first) {
out << endl;
}
out << endl;
// Write the struct map
out <<