MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / Generate

Method Generate

core/pdcodegen/src/pdcodegen.cpp:90–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88class PdsCodeGenerator : public CodeGenerator {
89 public:
90 virtual bool Generate(const FileDescriptor* file,
91 const string& parameter,
92 GeneratorContext* context,
93 std::string* error) const {
94 const string header = strip_proto(file->name()) + ".pb.h";
95 const string body = strip_proto(file->name()) + ".pb.cc";
96 bool include_inserted = false;
97 for (int i = 0; i < file->service_count(); ++i) {
98 const ServiceDescriptor* descriptor = file->service(i);
99 if (!descriptor) {
100 *error = "get descriptor failed";
101 return false;
102 }
103 pds::PaddleServiceOption options =
104 descriptor->options().GetExtension(pds::options);
105 bool generate_impl = options.generate_impl();
106 bool generate_stub = options.generate_stub();
107 if (!generate_impl && !generate_stub) {
108 return true;
109 }
110 if (!include_inserted) {
111 boost::scoped_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
112 context->OpenForInsert(header, "includes"));
113 google::protobuf::io::Printer printer(output.get(), '$');
114 if (generate_impl) {
115 printer.Print("#include \"core/predictor/common/inner_common.h\"\n");
116 printer.Print("#include \"core/predictor/framework/service.h\"\n");
117 printer.Print("#include \"core/predictor/framework/manager.h\"\n");
118 printer.Print(
119 "#include \"core/predictor/framework/service_manager.h\"\n");
120 }
121 if (generate_stub) {
122 printer.Print("#include <baidu/rpc/parallel_channel.h>\n");
123 printer.Print("#include \"core/sdk-cpp/include/factory.h\"\n");
124 printer.Print("#include \"core/sdk-cpp/include/stub.h\"\n");
125 printer.Print("#include \"core/sdk-cpp/include/stub_impl.h\"\n");
126 }
127 include_inserted = true;
128 }
129 const std::string& class_name = descriptor->name();
130 const std::string& service_name = descriptor->name();
131 // xxx.ph.h
132 {
133 if (generate_impl) {
134 // service scope
135 // namespace scope
136 boost::scoped_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
137 context->OpenForInsert(header, "namespace_scope"));
138 google::protobuf::io::Printer printer(output.get(), '$');
139 if (!generate_paddle_serving_head(
140 &printer, descriptor, error, service_name, class_name)) {
141 return false;
142 }
143 }
144 if (generate_stub) {
145 // service class scope
146
147 // namespace scope

Callers

nothing calls this directly

Calls 4

strip_protoFunction · 0.85
serviceMethod · 0.80
nameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected