From 6f83d8b1c0d0798fd4650ac88296bb4cc3cea162 Mon Sep 17 00:00:00 2001 From: guanshoukui Date: Wed, 6 Mar 2024 15:29:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0RepeatedMessageFieldGenerator?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protoc-plugin/MessageFieldGenerator.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/struct_pb/protoc-plugin/MessageFieldGenerator.cpp b/src/struct_pb/protoc-plugin/MessageFieldGenerator.cpp index 8f71e445d..16eece7ac 100644 --- a/src/struct_pb/protoc-plugin/MessageFieldGenerator.cpp +++ b/src/struct_pb/protoc-plugin/MessageFieldGenerator.cpp @@ -177,12 +177,26 @@ void MessageFieldGenerator::generate_class_to_struct( } void RepeatedMessageFieldGenerator::generate_struct_to_class( - google::protobuf::io2::Printer *p) const {} + google::protobuf::io2::Printer *p) const { + Formatter format(p); + auto v_class_name = "result.mutable_" + name() + "()"; + auto v_struct_name = "in." + name(); + p->Print({{"result", v_class_name}, {"in", v_struct_name}}, +R"($result$->Reserve($in$.size()); +for(int i = 0;i < $in$.size();++i) { *$result$->Mutable(i) = StructToClass($in$[i]);} +)"); +} void RepeatedMessageFieldGenerator::generate_class_to_struct( google::protobuf::io2::Printer *p) const { - - } + Formatter format(p); + auto v_class_name = "in." + name() + "()"; + auto v_struct_name = "result." + name(); + p->Print({{"in", v_class_name}, {"result", v_struct_name}}, +R"($result$.reserve($in$.size()); +for(auto const& elem : $in$) { $result$.emplace_back(ClassToStruct(elem));} +)"); +} } // namespace compiler } // namespace struct_pb \ No newline at end of file