diff --git a/include/grpcpp/impl/codegen/client_unary_call.h b/include/grpcpp/impl/codegen/client_unary_call.h index 098bb50ee2c..b2430aded67 100644 --- a/include/grpcpp/impl/codegen/client_unary_call.h +++ b/include/grpcpp/impl/codegen/client_unary_call.h @@ -30,12 +30,23 @@ namespace grpc { class ClientContext; namespace internal { class RpcMethod; -/// Wrapper that performs a blocking unary call -template + +/// Wrapper that performs a blocking unary call. May optionally specify the base +/// class of the Request and Response so that the internal calls and structures +/// below this may be based on those base classes and thus achieve code reuse +/// across different RPCs (e.g., for protobuf, MessageLite would be a base +/// class). +template Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, grpc::ClientContext* context, const InputMessage& request, OutputMessage* result) { - return BlockingUnaryCallImpl( + static_assert(std::is_base_of::value, + "Invalid input message specification"); + static_assert(std::is_base_of::value, + "Invalid output message specification"); + return BlockingUnaryCallImpl( channel, method, context, request, result) .status(); } diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 7ed74eb2302..df212784d82 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1887,6 +1887,8 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer, "const $Request$& request, $Response$* response) {\n"); printer->Print(*vars, " return ::grpc::internal::BlockingUnaryCall" + "< $Request$, $Response$, ::grpc::protobuf::MessageLite, " + "::grpc::protobuf::MessageLite>" "(channel_.get(), rpcmethod_$Method$_, " "context, request, response);\n}\n\n");