THRIFT-344. Add a 'log_unexpected' option to the cocoa generator. off by default. when supplied, unexpected field IDs and types are logged when reading a struct.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@796347 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index 2b7551f..5294eff 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -43,6 +43,11 @@
const std::string& option_string)
: t_oop_generator(program)
{
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("log_unexpected");
+ log_unexpected_ = (iter != parsed_options.end());
+
out_dir_base_ = "gen-cocoa";
}
@@ -194,6 +199,7 @@
std::ofstream f_header_;
std::ofstream f_impl_;
+ bool log_unexpected_;
};
@@ -679,18 +685,22 @@
}
indent_down();
- out <<
- indent() << "} else { " << endl <<
- indent() << " [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
+ out << indent() << "} else { " << endl;
+ if (log_unexpected_) {
+ out << indent() << " NSLog(@\"%s: field ID %i has unexpected type %i. Skipping.\", __PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
+ }
+ out << indent() << " [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
indent() << "}" << endl <<
indent() << "break;" << endl;
indent_down();
}
// In the default case we skip the field
- out <<
- indent() << "default:" << endl <<
- indent() << " [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
+ out << indent() << "default:" << endl;
+ if (log_unexpected_) {
+ out << indent() << " NSLog(@\"%s: unexpected field ID %i with type %i. Skipping.\", __PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
+ }
+ out << indent() << " [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
indent() << " break;" << endl;
scope_down(out);
@@ -2076,4 +2086,6 @@
}
-THRIFT_REGISTER_GENERATOR(cocoa, "Cocoa", "");
+THRIFT_REGISTER_GENERATOR(cocoa, "Cocoa",
+" log_unexpected: Log every time an unexpected field ID or type is encountered.\n"
+);