| 1298 | } |
| 1299 | |
| 1300 | static bool generate_registration( |
| 1301 | const google::protobuf::FileDescriptor* file, |
| 1302 | google::protobuf::io::Printer & impl) { |
| 1303 | const std::string cpp_ns = to_cpp_name(butil::EnsureString(file->package())); |
| 1304 | std::string norm_fname = protobuf_style_normalize_filename(butil::EnsureString(file->name())); |
| 1305 | impl.Print( |
| 1306 | "\n// register all message handlers\n" |
| 1307 | "struct RegisterMcpackFunctions_$norm_fname$ {\n" |
| 1308 | " RegisterMcpackFunctions_$norm_fname$() {\n" |
| 1309 | , "norm_fname", norm_fname); |
| 1310 | impl.Indent(); |
| 1311 | impl.Indent(); |
| 1312 | for (int i = 0; i < file->message_type_count(); ++i) { |
| 1313 | const google::protobuf::Descriptor* d = file->message_type(i); |
| 1314 | std::string var_name = mcpack2pb::to_var_name(butil::EnsureString(d->full_name())); |
| 1315 | |
| 1316 | impl.Print( |
| 1317 | "\n" |
| 1318 | "g_$vmsg$_fields = new ::mcpack2pb::FieldMap;\n" |
| 1319 | "CHECK_EQ(0, g_$vmsg$_fields->init(std::max($field_count$, 1), 30));\n" |
| 1320 | , "vmsg", var_name |
| 1321 | , "field_count", ::butil::string_printf("%d", d->field_count())); |
| 1322 | for (int i = 0; i < d->field_count(); ++i) { |
| 1323 | const google::protobuf::FieldDescriptor* f = d->field(i); |
| 1324 | impl.Print("(*g_$vmsg$_fields)[\"$field$\"] = ::set_$vmsg$_$lcfield$;\n" |
| 1325 | , "vmsg", var_name |
| 1326 | , "field", get_idl_name(f) |
| 1327 | , "lcfield", f->lowercase_name()); |
| 1328 | } |
| 1329 | impl.Print( |
| 1330 | "::mcpack2pb::MessageHandler $vmsg$_handler = {\n" |
| 1331 | " parse_$vmsg$,\n" |
| 1332 | " parse_$vmsg$_body,\n" |
| 1333 | " serialize_$vmsg$,\n" |
| 1334 | " serialize_$vmsg$_body\n" |
| 1335 | "};\n" |
| 1336 | "::mcpack2pb::register_message_handler_or_die(\"$fmsg$\", $vmsg$_handler);\n" |
| 1337 | , "fmsg", d->full_name() |
| 1338 | , "vmsg", var_name); |
| 1339 | } |
| 1340 | impl.Outdent(); |
| 1341 | impl.Outdent(); |
| 1342 | impl.Print(" }\n" |
| 1343 | "} static_init_mcpack_$suffix$;\n" |
| 1344 | , "suffix", norm_fname); |
| 1345 | return !impl.failed(); |
| 1346 | } |
| 1347 | |
| 1348 | class McpackToProtobuf : public google::protobuf::compiler::CodeGenerator { |
| 1349 | public: |
no test coverage detected