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
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index db19c90..08a6fbe 100755
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -1368,26 +1368,14 @@
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 @@
}
}
- if (!first) {
- out << endl;
- }
+ out << endl;
// Write the struct map
out <<