Skip to content

Commit

Permalink
Merge pull request grpc#24420 from vjpai/sync_client_code_size_v2
Browse files Browse the repository at this point in the history
Reduce sync client templating for protobuf without protobuf dependence
  • Loading branch information
vjpai authored Oct 20, 2020
2 parents 8f9233c + ef212a9 commit 97924fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions include/grpcpp/impl/codegen/client_unary_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ namespace grpc {
class ClientContext;
namespace internal {
class RpcMethod;
/// Wrapper that performs a blocking unary call
template <class InputMessage, class OutputMessage>

/// 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 <class InputMessage, class OutputMessage,
class BaseInputMessage = InputMessage,
class BaseOutputMessage = OutputMessage>
Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method,
grpc::ClientContext* context,
const InputMessage& request, OutputMessage* result) {
return BlockingUnaryCallImpl<InputMessage, OutputMessage>(
static_assert(std::is_base_of<BaseInputMessage, InputMessage>::value,
"Invalid input message specification");
static_assert(std::is_base_of<BaseOutputMessage, OutputMessage>::value,
"Invalid output message specification");
return BlockingUnaryCallImpl<BaseInputMessage, BaseOutputMessage>(
channel, method, context, request, result)
.status();
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/cpp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 97924fc

Please sign in to comment.