From 3b26451025118b1f2764dcc618cb3a5fd8abdd4b Mon Sep 17 00:00:00 2001 From: James Eady Date: Tue, 2 May 2017 10:45:34 -0400 Subject: [PATCH 1/2] Add static method to generated code to return fully qualified protobuf service name. --- src/compiler/cpp_generator.cc | 7 +++++++ test/cpp/codegen/compiler_test_golden | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d3e71625d65..bbf17314e99 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -804,6 +804,13 @@ void PrintHeaderService(grpc_generator::Printer *printer, " public:\n"); printer->Indent(); + // Service metadata + printer->Print( + *vars, + "static constexpr char const* service_full_name() {\n" + " return \"$Package$$Service$\";\n" + "}\n"); + // Client side printer->Print( "class StubInterface {\n" diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index 8e3ae32a494..eb12d371eaf 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -69,6 +69,9 @@ namespace testing { // ServiceA leading comment 1 class ServiceA final { public: + static constexpr char const* service_full_name() { + return "grpc.testing.ServiceA"; + } class StubInterface { public: virtual ~StubInterface() {} @@ -373,6 +376,9 @@ class ServiceA final { // ServiceB leading comment 1 class ServiceB final { public: + static constexpr char const* service_full_name() { + return "grpc.testing.ServiceB"; + } class StubInterface { public: virtual ~StubInterface() {} From be6ccdbc14a328bcaad4e911a9d3ad7ffe7fe596 Mon Sep 17 00:00:00 2001 From: James Eady Date: Thu, 4 May 2017 10:41:24 -0400 Subject: [PATCH 2/2] Proper clang formatting. --- src/compiler/cpp_generator.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index bbf17314e99..a1a0258c680 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -805,11 +805,10 @@ void PrintHeaderService(grpc_generator::Printer *printer, printer->Indent(); // Service metadata - printer->Print( - *vars, - "static constexpr char const* service_full_name() {\n" - " return \"$Package$$Service$\";\n" - "}\n"); + printer->Print(*vars, + "static constexpr char const* service_full_name() {\n" + " return \"$Package$$Service$\";\n" + "}\n"); // Client side printer->Print(