From: Andrew McGeachie Date: Tue, 21 Jul 2009 15:30:16 +0000 (+0000) Subject: THRIFT-344. Add a 'log_unexpected' option to the cocoa generator. off by default... X-Git-Tag: 0.2.0~69 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=645d7b8d5026f18a61f38213a02a27cbfc9286ab;p=common%2Fthrift.git 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 2b7551f1..5294eff6 100644 --- a/compiler/cpp/src/generate/t_cocoa_generator.cc +++ b/compiler/cpp/src/generate/t_cocoa_generator.cc @@ -43,6 +43,11 @@ class t_cocoa_generator : public t_oop_generator { const std::string& option_string) : t_oop_generator(program) { + std::map::const_iterator iter; + + iter = parsed_options.find("log_unexpected"); + log_unexpected_ = (iter != parsed_options.end()); + out_dir_base_ = "gen-cocoa"; } @@ -194,6 +199,7 @@ class t_cocoa_generator : public t_oop_generator { std::ofstream f_header_; std::ofstream f_impl_; + bool log_unexpected_; }; @@ -679,18 +685,22 @@ void t_cocoa_generator::generate_cocoa_struct_reader(ofstream& out, } 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 @@ string t_cocoa_generator::call_field_setter(t_field* tfield, string fieldName) { } -THRIFT_REGISTER_GENERATOR(cocoa, "Cocoa", ""); +THRIFT_REGISTER_GENERATOR(cocoa, "Cocoa", +" log_unexpected: Log every time an unexpected field ID or type is encountered.\n" +);