Author: geechorama
Date: Tue Jul 21 15:30:16 2009
New Revision: 796347
URL: http://svn.apache.org/viewvc?rev=796347&view=rev
Log:
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.
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_cocoa_generator.cc
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_cocoa_generator.cc
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_cocoa_generator.cc?rev=796347&r1=796346&r2=796347&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_cocoa_generator.cc
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_cocoa_generator.cc Tue
Jul 21 15:30:16 2009
@@ -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"
+);