|
|
|
@ -45,23 +45,23 @@ |
|
|
|
|
namespace grpc_cpp_generator { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
bool NoStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
|
bool NoStreaming(const google::protobuf::MethodDescriptor *method) { |
|
|
|
|
return !method->client_streaming() && !method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
|
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor *method) { |
|
|
|
|
return method->client_streaming() && !method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
|
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor *method) { |
|
|
|
|
return !method->client_streaming() && method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) { |
|
|
|
|
bool BidiStreaming(const google::protobuf::MethodDescriptor *method) { |
|
|
|
|
return method->client_streaming() && method->server_streaming(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
for (int i = 0; i < file->service_count(); i++) { |
|
|
|
|
for (int j = 0; j < file->service(i)->method_count(); j++) { |
|
|
|
|
if (ClientOnlyStreaming(file->service(i)->method(j))) { |
|
|
|
@ -72,7 +72,7 @@ bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
for (int i = 0; i < file->service_count(); i++) { |
|
|
|
|
for (int j = 0; j < file->service(i)->method_count(); j++) { |
|
|
|
|
if (ServerOnlyStreaming(file->service(i)->method(j))) { |
|
|
|
@ -83,7 +83,7 @@ bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
bool HasBidiStreaming(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
for (int i = 0; i < file->service_count(); i++) { |
|
|
|
|
for (int j = 0; j < file->service(i)->method_count(); j++) { |
|
|
|
|
if (BidiStreaming(file->service(i)->method(j))) { |
|
|
|
@ -95,7 +95,7 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
} |
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
std::string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
std::string temp = |
|
|
|
|
"#include \"grpc++/impl/internal_stub.h\"\n" |
|
|
|
|
"#include \"grpc++/status.h\"\n" |
|
|
|
@ -131,9 +131,9 @@ std::string GetSourceIncludes() { |
|
|
|
|
"#include \"grpc++/stream.h\"\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderClientMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintHeaderClientMethod(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -160,9 +160,9 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderServerMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintHeaderServerMethod(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -194,9 +194,9 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintHeaderService(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::ServiceDescriptor* service, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintHeaderService(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::ServiceDescriptor *service, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Service"] = service->name(); |
|
|
|
|
|
|
|
|
|
printer->Print(*vars, |
|
|
|
@ -241,7 +241,7 @@ void PrintHeaderService(google::protobuf::io::Printer* printer, |
|
|
|
|
printer->Print("};\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string GetHeaderServices(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
std::string GetHeaderServices(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
std::string output; |
|
|
|
|
google::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
google::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
@ -254,9 +254,9 @@ std::string GetHeaderServices(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceClientMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintSourceClientMethod(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -312,9 +312,9 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceServerMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::MethodDescriptor* method, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintSourceServerMethod(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::MethodDescriptor *method, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -362,9 +362,9 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintSourceService(google::protobuf::io::Printer* printer, |
|
|
|
|
const google::protobuf::ServiceDescriptor* service, |
|
|
|
|
std::map<std::string, std::string>* vars) { |
|
|
|
|
void PrintSourceService(google::protobuf::io::Printer *printer, |
|
|
|
|
const google::protobuf::ServiceDescriptor *service, |
|
|
|
|
std::map<std::string, std::string> *vars) { |
|
|
|
|
(*vars)["Service"] = service->name(); |
|
|
|
|
printer->Print( |
|
|
|
|
*vars, |
|
|
|
@ -394,7 +394,7 @@ void PrintSourceService(google::protobuf::io::Printer* printer, |
|
|
|
|
"}\n"); |
|
|
|
|
printer->Print("service_ = new ::grpc::RpcService();\n"); |
|
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
|
const google::protobuf::MethodDescriptor* method = service->method(i); |
|
|
|
|
const google::protobuf::MethodDescriptor *method = service->method(i); |
|
|
|
|
(*vars)["Method"] = method->name(); |
|
|
|
|
(*vars)["Request"] = |
|
|
|
|
grpc_cpp_generator::ClassName(method->input_type(), true); |
|
|
|
@ -458,7 +458,7 @@ void PrintSourceService(google::protobuf::io::Printer* printer, |
|
|
|
|
printer->Print("}\n\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string GetSourceServices(const google::protobuf::FileDescriptor* file) { |
|
|
|
|
std::string GetSourceServices(const google::protobuf::FileDescriptor *file) { |
|
|
|
|
std::string output; |
|
|
|
|
google::protobuf::io::StringOutputStream output_stream(&output); |
|
|
|
|
google::protobuf::io::Printer printer(&output_stream, '$'); |
|
|
|
|