|
|
|
@ -86,23 +86,25 @@ grpc::string FilenameIdentifier(const grpc::string &filename) { |
|
|
|
|
grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, "// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n"); |
|
|
|
|
printer.Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, "// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n"); |
|
|
|
|
printer.Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -626,100 +628,108 @@ void PrintHeaderService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
vars["services_namespace"] = params.services_namespace; |
|
|
|
|
printer.Print(vars, "\nnamespace $services_namespace$ {\n\n"); |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
vars["services_namespace"] = params.services_namespace; |
|
|
|
|
printer.Print(vars, "\nnamespace $services_namespace$ {\n\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintHeaderService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintHeaderService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
printer.Print(vars, "} // namespace $services_namespace$\n\n"); |
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
printer.Print(vars, "} // namespace $services_namespace$\n\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetHeaderEpilogue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.rbegin(); part != parts.rend(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "} // namespace $part$\n"); |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_identifier"] = FilenameIdentifier(file->name()); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.rbegin(); part != parts.rend(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "} // namespace $part$\n"); |
|
|
|
|
} |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
printer.Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n"); |
|
|
|
|
|
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, "// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
vars["filename"] = file->name(); |
|
|
|
|
vars["filename_base"] = grpc_generator::StripProto(file->name()); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); |
|
|
|
|
printer.Print(vars, "// If you make any local change, they will be lost.\n"); |
|
|
|
|
printer.Print(vars, "// source: $filename$\n\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); |
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc::string GetSourceIncludes(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶m) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "#include <grpc++/async_unary_call.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/channel_interface.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/client_unary_call.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/rpc_service_method.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/service_type.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/stream.h>\n"); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.begin(); part != parts.end(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "namespace $part$ {\n"); |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "#include <grpc++/async_unary_call.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/channel_interface.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/client_unary_call.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/rpc_service_method.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/impl/service_type.h>\n"); |
|
|
|
|
printer.Print(vars, "#include <grpc++/stream.h>\n"); |
|
|
|
|
|
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
std::vector<grpc::string> parts = |
|
|
|
|
grpc_generator::tokenize(file->package(), "."); |
|
|
|
|
|
|
|
|
|
for (auto part = parts.begin(); part != parts.end(); part++) { |
|
|
|
|
vars["part"] = *part; |
|
|
|
|
printer.Print(vars, "namespace $part$ {\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
|
|
|
|
|
printer.Print(vars, "\n"); |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1077,26 +1087,29 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, |
|
|
|
|
grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file, |
|
|
|
|
const Parameters ¶ms) { |
|
|
|
|
grpc::string output; |
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
// Package string is empty or ends with a dot. It is used to fully qualify
|
|
|
|
|
// method names.
|
|
|
|
|
vars["Package"] = file->package(); |
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
vars["Package"].append("."); |
|
|
|
|
} |
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
vars["ns"] = params.services_namespace + "::"; |
|
|
|
|
vars["prefix"] = params.services_namespace; |
|
|
|
|
} else { |
|
|
|
|
vars["ns"] = ""; |
|
|
|
|
vars["prefix"] = ""; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// Scope the output stream so it closes and finalizes output to the string.
|
|
|
|
|
grpc::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
grpc::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|
std::map<grpc::string, grpc::string> vars; |
|
|
|
|
// Package string is empty or ends with a dot. It is used to fully qualify
|
|
|
|
|
// method names.
|
|
|
|
|
vars["Package"] = file->package(); |
|
|
|
|
if (!file->package().empty()) { |
|
|
|
|
vars["Package"].append("."); |
|
|
|
|
} |
|
|
|
|
if (!params.services_namespace.empty()) { |
|
|
|
|
vars["ns"] = params.services_namespace + "::"; |
|
|
|
|
vars["prefix"] = params.services_namespace; |
|
|
|
|
} else { |
|
|
|
|
vars["ns"] = ""; |
|
|
|
|
vars["prefix"] = ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintSourceService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
for (int i = 0; i < file->service_count(); ++i) { |
|
|
|
|
PrintSourceService(&printer, file->service(i), &vars); |
|
|
|
|
printer.Print("\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|