| 857 | ((cit) == IDL_AUTO || is_integral_type(cit))) |
| 858 | |
| 859 | static bool generate_serializing(const google::protobuf::Descriptor* d, |
| 860 | std::set<std::string> & ref_msgs, |
| 861 | std::set<std::string> & ref_maps, |
| 862 | google::protobuf::io::Printer & impl) { |
| 863 | std::string var_name = mcpack2pb::to_var_name(butil::EnsureString(d->full_name())); |
| 864 | std::string cpp_name = mcpack2pb::to_cpp_name(butil::EnsureString(d->full_name())); |
| 865 | ref_msgs.insert(var_name); |
| 866 | impl.Print( |
| 867 | "void serialize_$vmsg$_body(\n" |
| 868 | " const ::google::protobuf::Message& msg_base,\n" |
| 869 | " ::mcpack2pb::Serializer& serializer,\n" |
| 870 | " ::mcpack2pb::SerializationFormat format) {\n" |
| 871 | " (void)format; // suppress compiler warning when it's not used\n" |
| 872 | , "vmsg", var_name); |
| 873 | if (d->field_count()) { |
| 874 | impl.Print( |
| 875 | " const $msg$& msg = static_cast<const $msg$&>(msg_base);\n" |
| 876 | , "msg", cpp_name); |
| 877 | } else { |
| 878 | impl.Print(" (void)msg_base; // ^\n" |
| 879 | " (void)serializer; // ^\n"); |
| 880 | } |
| 881 | impl.Indent(); |
| 882 | for (int i = 0; i < d->field_count(); ++i) { |
| 883 | const google::protobuf::FieldDescriptor* f = d->field(i); |
| 884 | ConvertibleIdlType cit = f->options().GetExtension(idl_type); |
| 885 | // Print the field as comment. |
| 886 | std::string comment_template; |
| 887 | if (cit == IDL_AUTO) { |
| 888 | butil::string_printf(&comment_template, |
| 889 | "// %s $type$ $name$ = $number$;\n", |
| 890 | (f->is_repeated() ? "repeated" : |
| 891 | (f->is_required() ? "required" : "optional"))); |
| 892 | } else { |
| 893 | butil::string_printf(&comment_template, |
| 894 | "// %s $type$ $name$ = $number$ [(idl_type)=%s];\n", |
| 895 | (f->is_repeated() ? "repeated" : |
| 896 | (f->is_required() ? "required" : "optional")), |
| 897 | describe_idl_type(cit)); |
| 898 | } |
| 899 | impl.Print(comment_template.c_str() |
| 900 | , "type", field_to_string(f) |
| 901 | , "name", f->name() |
| 902 | , "number", butil::string_printf("%d", f->number())); |
| 903 | if (f->is_repeated()) { |
| 904 | switch (f->cpp_type()) { |
| 905 | case google::protobuf::FieldDescriptor::CPPTYPE_INT32: |
| 906 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: |
| 907 | case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: |
| 908 | TEMPLATE_SERIALIZE_REPEATED_INTEGRAL( |
| 909 | cit, impl, f, (cit == IDL_INT32 || cit == IDL_UINT32)); |
| 910 | break; |
| 911 | case google::protobuf::FieldDescriptor::CPPTYPE_INT64: |
| 912 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: |
| 913 | TEMPLATE_SERIALIZE_REPEATED_INTEGRAL( |
| 914 | cit, impl, f, (cit == IDL_INT64 || cit == IDL_UINT64)); |
| 915 | break; |
| 916 | case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: |
no test coverage detected