THRIFT-3654 incorrect serialization of optionals
Client: Haxe
Patch: Jens Geyer
diff --git a/compiler/cpp/src/generate/t_haxe_generator.cc b/compiler/cpp/src/generate/t_haxe_generator.cc
index f34a406..d15958e 100644
--- a/compiler/cpp/src/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/generate/t_haxe_generator.cc
@@ -978,6 +978,11 @@
indent(out) << "oprot.writeStructBegin(STRUCT_DESC);" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ bool could_be_unset = (*f_iter)->get_req() == t_field::T_OPTIONAL;
+ if (could_be_unset) {
+ indent(out) << "if (" << generate_isset_check(*f_iter) << ") {" << endl;
+ indent_up();
+ }
bool null_allowed = type_can_be_null((*f_iter)->get_type());
if (null_allowed) {
out << indent() << "if (this." << (*f_iter)->get_name() << " != null) {" << endl;
@@ -997,6 +1002,10 @@
indent_down();
indent(out) << "}" << endl;
}
+ if (could_be_unset) {
+ indent_down();
+ indent(out) << "}" << endl;
+ }
}
indent(out) << "oprot.writeFieldStop();" << endl;