Skip to content

Commit

Permalink
添加RepeatedMessageFieldGenerator 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
guanshoukui committed Mar 6, 2024
1 parent 43615e7 commit 6f83d8b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/struct_pb/protoc-plugin/MessageFieldGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6f83d8b

Please sign in to comment.