return "";
}
+std::string GetCSharpServerMethodType(MethodType method_type) {
+ switch (method_type) {
+ case METHODTYPE_NO_STREAMING:
+ return "grpc::UnaryServerMethod";
+ case METHODTYPE_CLIENT_STREAMING:
+ return "grpc::ClientStreamingServerMethod";
+ case METHODTYPE_SERVER_STREAMING:
+ return "grpc::ServerStreamingServerMethod";
+ case METHODTYPE_BIDI_STREAMING:
+ return "grpc::DuplexStreamingServerMethod";
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
std::string GetServiceNameFieldName() { return "__ServiceName"; }
std::string GetMarshallerFieldName(const Descriptor* message) {
"/// <summary>Base class for server-side implementations of "
"$servicename$</summary>\n",
"servicename", GetServiceClassName(service));
+ out->Print(
+ "[grpc::BindServiceMethod(typeof($classname$), "
+ "\"BindService\")]\n",
+ "classname", GetServiceClassName(service));
out->Print("public abstract partial class $name$\n", "name",
GetServerClassName(service));
out->Print("{\n");
out->Print("\n");
}
-void GenerateClientStub(Printer* out, const ServiceDescriptor* service) {
- out->Print("/// <summary>Client for $servicename$</summary>\n", "servicename",
- GetServiceClassName(service));
- out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", "name",
- GetClientClassName(service));
+void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
+ bool lite_client) {
+ if (!lite_client) {
+ out->Print("/// <summary>Client for $servicename$</summary>\n",
+ "servicename", GetServiceClassName(service));
+ out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n",
+ "name", GetClientClassName(service));
+ } else {
+ out->Print("/// <summary>Lite client for $servicename$</summary>\n",
+ "servicename", GetServiceClassName(service));
+ out->Print("public partial class $name$ : grpc::LiteClientBase\n", "name",
+ GetClientClassName(service));
+ }
out->Print("{\n");
out->Indent();
// constructors
- out->Print(
- "/// <summary>Creates a new client for $servicename$</summary>\n"
- "/// <param name=\"channel\">The channel to use to make remote "
- "calls.</param>\n",
- "servicename", GetServiceClassName(service));
- out->Print("public $name$(grpc::Channel channel) : base(channel)\n", "name",
- GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n");
+ if (!lite_client) {
+ out->Print(
+ "/// <summary>Creates a new client for $servicename$</summary>\n"
+ "/// <param name=\"channel\">The channel to use to make remote "
+ "calls.</param>\n",
+ "servicename", GetServiceClassName(service));
+ out->Print("public $name$(grpc::Channel channel) : base(channel)\n", "name",
+ GetClientClassName(service));
+ out->Print("{\n");
+ out->Print("}\n");
+ }
out->Print(
"/// <summary>Creates a new client for $servicename$ that uses a custom "
"<c>CallInvoker</c>.</summary>\n"
GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
- out->Print(
- "/// <summary>Protected constructor to allow creation of configured "
- "clients.</summary>\n"
- "/// <param name=\"configuration\">The client configuration.</param>\n");
- out->Print(
- "protected $name$(ClientBaseConfiguration configuration)"
- " : base(configuration)\n",
- "name", GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n\n");
+ if (!lite_client) {
+ out->Print(
+ "/// <summary>Protected constructor to allow creation of configured "
+ "clients.</summary>\n"
+ "/// <param name=\"configuration\">The client "
+ "configuration.</param>\n");
+ out->Print(
+ "protected $name$(ClientBaseConfiguration configuration)"
+ " : base(configuration)\n",
+ "name", GetClientClassName(service));
+ out->Print("{\n");
+ out->Print("}\n");
+ }
+ out->Print("\n");
for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
}
// override NewInstance method
- out->Print(
- "/// <summary>Creates a new instance of client from given "
- "<c>ClientBaseConfiguration</c>.</summary>\n");
- out->Print(
- "protected override $name$ NewInstance(ClientBaseConfiguration "
- "configuration)\n",
- "name", GetClientClassName(service));
- out->Print("{\n");
- out->Indent();
- out->Print("return new $name$(configuration);\n", "name",
- GetClientClassName(service));
- out->Outdent();
- out->Print("}\n");
+ if (!lite_client) {
+ out->Print(
+ "/// <summary>Creates a new instance of client from given "
+ "<c>ClientBaseConfiguration</c>.</summary>\n");
+ out->Print(
+ "protected override $name$ NewInstance(ClientBaseConfiguration "
+ "configuration)\n",
+ "name", GetClientClassName(service));
+ out->Print("{\n");
+ out->Indent();
+ out->Print("return new $name$(configuration);\n", "name",
+ GetClientClassName(service));
+ out->Outdent();
+ out->Print("}\n");
+ }
out->Outdent();
out->Print("}\n");
void GenerateBindServiceWithBinderMethod(Printer* out,
const ServiceDescriptor* service) {
out->Print(
- "/// <summary>Register service method implementations with a service "
- "binder. Useful when customizing the service binding logic.\n"
+ "/// <summary>Register service method with a service "
+ "binder with or without implementation. Useful when customizing the "
+ "service binding logic.\n"
"/// Note: this method is part of an experimental API that can change or "
"be "
"removed without any prior notice.</summary>\n");
for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
out->Print(
- "serviceBinder.AddMethod($methodfield$, serviceImpl.$methodname$);\n",
- "methodfield", GetMethodFieldName(method), "methodname",
- method->name());
+ "serviceBinder.AddMethod($methodfield$, serviceImpl == null ? null : "
+ "new $servermethodtype$<$inputtype$, $outputtype$>("
+ "serviceImpl.$methodname$));\n",
+ "methodfield", GetMethodFieldName(method), "servermethodtype",
+ GetCSharpServerMethodType(GetMethodType(method)), "inputtype",
+ GetClassName(method->input_type()), "outputtype",
+ GetClassName(method->output_type()), "methodname", method->name());
}
out->Outdent();
void GenerateService(Printer* out, const ServiceDescriptor* service,
bool generate_client, bool generate_server,
- bool internal_access) {
+ bool internal_access, bool lite_client) {
GenerateDocCommentBody(out, service);
out->Print("$access_level$ static partial class $classname$\n",
"access_level", GetAccessLevel(internal_access), "classname",
GenerateServerClass(out, service);
}
if (generate_client) {
- GenerateClientStub(out, service);
+ GenerateClientStub(out, service, lite_client);
}
+
if (generate_server) {
GenerateBindServiceMethod(out, service);
GenerateBindServiceWithBinderMethod(out, service);
} // anonymous namespace
grpc::string GetServices(const FileDescriptor* file, bool generate_client,
- bool generate_server, bool internal_access) {
+ bool generate_server, bool internal_access,
+ bool lite_client) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
}
for (int i = 0; i < file->service_count(); i++) {
GenerateService(&out, file->service(i), generate_client, generate_server,
- internal_access);
+ internal_access, lite_client);
}
if (file_namespace != "") {
out.Outdent();