Reduce code paths

pull/24527/head
Vijay Pai 4 years ago
parent 3c9fcac01b
commit 96503e3c72
  1. 34
      include/grpcpp/impl/codegen/call_op_set.h

@ -330,6 +330,7 @@ class CallOpSendMessage {
} }
void FinishOp(bool* status) { void FinishOp(bool* status) {
if (msg_ == nullptr && !send_buf_.Valid()) return; if (msg_ == nullptr && !send_buf_.Valid()) return;
send_buf_.Clear();
if (hijacked_ && failed_send_) { if (hijacked_ && failed_send_) {
// Hijacking interceptor failed this Op // Hijacking interceptor failed this Op
*status = false; *status = false;
@ -378,27 +379,18 @@ class CallOpSendMessage {
template <class M> template <class M>
Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) {
write_options_ = options; write_options_ = options;
serializer_ = [this](const void* message) { // Serialize immediately since we do not have access to the message pointer
bool own_buf; bool own_buf;
send_buf_.Clear();
// TODO(vjpai): Remove the void below when possible // TODO(vjpai): Remove the void below when possible
// The void in the template parameter below should not be needed // The void in the template parameter below should not be needed
// (since it should be implicit) but is needed due to an observed // (since it should be implicit) but is needed due to an observed
// difference in behavior between clang and gcc for certain internal users // difference in behavior between clang and gcc for certain internal users
Status result = SerializationTraits<M, void>::Serialize( Status result = SerializationTraits<M, void>::Serialize(
*static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf); message, send_buf_.bbuf_ptr(), &own_buf);
if (!own_buf) { if (!own_buf) {
send_buf_.Duplicate(); send_buf_.Duplicate();
} }
return result; return result;
};
// Serialize immediately only if we do not have access to the message pointer
if (msg_ == nullptr) {
Status result = serializer_(&message);
serializer_ = nullptr;
return result;
}
return Status();
} }
template <class M> template <class M>
@ -410,13 +402,27 @@ template <class M>
Status CallOpSendMessage::SendMessagePtr(const M* message, Status CallOpSendMessage::SendMessagePtr(const M* message,
WriteOptions options) { WriteOptions options) {
msg_ = message; msg_ = message;
return SendMessage(*message, options); write_options_ = options;
// Store the serializer for later since we have access to the message
serializer_ = [this](const void* message) {
bool own_buf;
// TODO(vjpai): Remove the void below when possible
// The void in the template parameter below should not be needed
// (since it should be implicit) but is needed due to an observed
// difference in behavior between clang and gcc for certain internal users
Status result = SerializationTraits<M, void>::Serialize(
*static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf);
if (!own_buf) {
send_buf_.Duplicate();
}
return result;
};
return Status();
} }
template <class M> template <class M>
Status CallOpSendMessage::SendMessagePtr(const M* message) { Status CallOpSendMessage::SendMessagePtr(const M* message) {
msg_ = message; return SendMessagePtr(message, WriteOptions());
return SendMessage(*message, WriteOptions());
} }
template <class R> template <class R>

Loading…
Cancel
Save