aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/grpc++/impl/codegen/call.h37
1 files changed, 7 insertions, 30 deletions
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h
index f334ba61d6..9fe2bbb75e 100644
--- a/include/grpc++/impl/codegen/call.h
+++ b/include/grpc++/impl/codegen/call.h
@@ -364,28 +364,6 @@ class CallOpRecvMessage {
bool allow_not_getting_message_;
};
-namespace CallOpGenericRecvMessageHelper {
-class DeserializeFunc {
- public:
- virtual Status Deserialize(grpc_byte_buffer* buf) = 0;
- virtual ~DeserializeFunc() {}
-};
-
-template <class R>
-class DeserializeFuncType final : public DeserializeFunc {
- public:
- DeserializeFuncType(R* message) : message_(message) {}
- Status Deserialize(grpc_byte_buffer* buf) override {
- return SerializationTraits<R>::Deserialize(buf, message_);
- }
-
- ~DeserializeFuncType() override {}
-
- private:
- R* message_; // Not a managed pointer because management is external to this
-};
-} // namespace CallOpGenericRecvMessageHelper
-
class CallOpGenericRecvMessage {
public:
CallOpGenericRecvMessage()
@@ -393,11 +371,9 @@ class CallOpGenericRecvMessage {
template <class R>
void RecvMessage(R* message) {
- // Use an explicit base class pointer to avoid resolution error in the
- // following unique_ptr::reset for some old implementations.
- CallOpGenericRecvMessageHelper::DeserializeFunc* func =
- new CallOpGenericRecvMessageHelper::DeserializeFuncType<R>(message);
- deserialize_.reset(func);
+ deserialize_ = [message](grpc_byte_buffer* buf) -> Status {
+ return SerializationTraits<R>::Deserialize(buf, message);
+ };
}
// Do not change status if no message is received.
@@ -420,7 +396,7 @@ class CallOpGenericRecvMessage {
if (recv_buf_) {
if (*status) {
got_message = true;
- *status = deserialize_->Deserialize(recv_buf_).ok();
+ *status = deserialize_(recv_buf_).ok();
} else {
got_message = false;
g_core_codegen_interface->grpc_byte_buffer_destroy(recv_buf_);
@@ -431,11 +407,12 @@ class CallOpGenericRecvMessage {
*status = false;
}
}
- deserialize_.reset();
+ deserialize_ = DeserializeFunc();
}
private:
- std::unique_ptr<CallOpGenericRecvMessageHelper::DeserializeFunc> deserialize_;
+ typedef std::function<Status(grpc_byte_buffer*)> DeserializeFunc;
+ DeserializeFunc deserialize_;
grpc_byte_buffer* recv_buf_;
bool allow_not_getting_message_;
};