|
|
@ -305,9 +305,6 @@ class CallOpSendMessage { |
|
|
|
void FinishOp(bool* status) { send_buf_.Clear(); } |
|
|
|
void FinishOp(bool* status) { send_buf_.Clear(); } |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
template <class M, class T = void> |
|
|
|
|
|
|
|
class MessageSerializer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteBuffer send_buf_; |
|
|
|
ByteBuffer send_buf_; |
|
|
|
WriteOptions write_options_; |
|
|
|
WriteOptions write_options_; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -317,41 +314,12 @@ template <class T> |
|
|
|
T Example(); |
|
|
|
T Example(); |
|
|
|
} // namespace internal
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
|
|
template <class M> |
|
|
|
|
|
|
|
class CallOpSendMessage::MessageSerializer< |
|
|
|
|
|
|
|
M, typename std::enable_if<std::is_same< |
|
|
|
|
|
|
|
::grpc::Status, decltype(SerializationTraits<M>::Serialize( |
|
|
|
|
|
|
|
internal::Example<const M&>(), |
|
|
|
|
|
|
|
internal::Example<grpc_byte_buffer**>(), |
|
|
|
|
|
|
|
internal::Example<bool*>()))>::value>::type> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
static Status SendMessageInternal(const M& message, ByteBuffer* bbuf, |
|
|
|
|
|
|
|
bool* own_buf) { |
|
|
|
|
|
|
|
return SerializationTraits<M>::Serialize(message, bbuf->c_buffer_ptr(), |
|
|
|
|
|
|
|
own_buf); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class M> |
|
|
|
|
|
|
|
class CallOpSendMessage::MessageSerializer< |
|
|
|
|
|
|
|
M, typename std::enable_if<std::is_same< |
|
|
|
|
|
|
|
::grpc::Status, decltype(SerializationTraits<M>::Serialize( |
|
|
|
|
|
|
|
internal::Example<const M&>(), |
|
|
|
|
|
|
|
internal::Example<::grpc::ByteBuffer*>(), |
|
|
|
|
|
|
|
internal::Example<bool*>()))>::value>::type> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
static Status SendMessageInternal(const M& message, ByteBuffer* bbuf, |
|
|
|
|
|
|
|
bool* own_buf) { |
|
|
|
|
|
|
|
return SerializationTraits<M>::Serialize(message, bbuf, own_buf); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
bool own_buf; |
|
|
|
bool own_buf; |
|
|
|
Status result = |
|
|
|
Status result = SerializationTraits<M>::Serialize( |
|
|
|
MessageSerializer<M>::SendMessageInternal(message, &send_buf_, &own_buf); |
|
|
|
message, send_buf_.bbuf_ptr(), &own_buf); |
|
|
|
if (!own_buf) { |
|
|
|
if (!own_buf) { |
|
|
|
send_buf_.Duplicate(); |
|
|
|
send_buf_.Duplicate(); |
|
|
|
} |
|
|
|
} |
|
|
@ -363,36 +331,6 @@ Status CallOpSendMessage::SendMessage(const M& message) { |
|
|
|
return SendMessage(message, WriteOptions()); |
|
|
|
return SendMessage(message, WriteOptions()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace internal { |
|
|
|
|
|
|
|
template <class M, class T = void> |
|
|
|
|
|
|
|
class MessageDeserializer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class M> |
|
|
|
|
|
|
|
class MessageDeserializer< |
|
|
|
|
|
|
|
M, typename std::enable_if<std::is_same< |
|
|
|
|
|
|
|
::grpc::Status, decltype(SerializationTraits<M>::Deserialize( |
|
|
|
|
|
|
|
internal::Example<const ::grpc::ByteBuffer&>(), |
|
|
|
|
|
|
|
internal::Example<M*>()))>::value>::type> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
static Status Deserialize(const ByteBuffer& bbuf, M* message) { |
|
|
|
|
|
|
|
return SerializationTraits<M>::Deserialize(bbuf, message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class M> |
|
|
|
|
|
|
|
class MessageDeserializer< |
|
|
|
|
|
|
|
M, typename std::enable_if<std::is_same< |
|
|
|
|
|
|
|
::grpc::Status, decltype(SerializationTraits<M>::Deserialize( |
|
|
|
|
|
|
|
internal::Example<grpc_byte_buffer*>(), |
|
|
|
|
|
|
|
internal::Example<M*>()))>::value>::type> { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
static Status Deserialize(const ByteBuffer& bbuf, M* message) { |
|
|
|
|
|
|
|
return SerializationTraits<M>::Deserialize( |
|
|
|
|
|
|
|
const_cast<ByteBuffer&>(bbuf).c_buffer(), message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class R> |
|
|
|
template <class R> |
|
|
|
class CallOpRecvMessage { |
|
|
|
class CallOpRecvMessage { |
|
|
|
public: |
|
|
|
public: |
|
|
@ -423,7 +361,7 @@ class CallOpRecvMessage { |
|
|
|
if (recv_buf_.Valid()) { |
|
|
|
if (recv_buf_.Valid()) { |
|
|
|
if (*status) { |
|
|
|
if (*status) { |
|
|
|
got_message = *status = |
|
|
|
got_message = *status = |
|
|
|
internal::MessageDeserializer<R>::Deserialize(recv_buf_, message_) |
|
|
|
SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_) |
|
|
|
.ok(); |
|
|
|
.ok(); |
|
|
|
recv_buf_.Release(); |
|
|
|
recv_buf_.Release(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -448,7 +386,7 @@ class CallOpRecvMessage { |
|
|
|
namespace CallOpGenericRecvMessageHelper { |
|
|
|
namespace CallOpGenericRecvMessageHelper { |
|
|
|
class DeserializeFunc { |
|
|
|
class DeserializeFunc { |
|
|
|
public: |
|
|
|
public: |
|
|
|
virtual Status Deserialize(const ByteBuffer& buf) = 0; |
|
|
|
virtual Status Deserialize(ByteBuffer* buf) = 0; |
|
|
|
virtual ~DeserializeFunc() {} |
|
|
|
virtual ~DeserializeFunc() {} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -456,8 +394,8 @@ template <class R> |
|
|
|
class DeserializeFuncType final : public DeserializeFunc { |
|
|
|
class DeserializeFuncType final : public DeserializeFunc { |
|
|
|
public: |
|
|
|
public: |
|
|
|
DeserializeFuncType(R* message) : message_(message) {} |
|
|
|
DeserializeFuncType(R* message) : message_(message) {} |
|
|
|
Status Deserialize(const ByteBuffer& buf) override { |
|
|
|
Status Deserialize(ByteBuffer* buf) override { |
|
|
|
return grpc::internal::MessageDeserializer<R>::Deserialize(buf, message_); |
|
|
|
return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~DeserializeFuncType() override {} |
|
|
|
~DeserializeFuncType() override {} |
|
|
@ -501,7 +439,7 @@ class CallOpGenericRecvMessage { |
|
|
|
if (recv_buf_.Valid()) { |
|
|
|
if (recv_buf_.Valid()) { |
|
|
|
if (*status) { |
|
|
|
if (*status) { |
|
|
|
got_message = true; |
|
|
|
got_message = true; |
|
|
|
*status = deserialize_->Deserialize(recv_buf_).ok(); |
|
|
|
*status = deserialize_->Deserialize(&recv_buf_).ok(); |
|
|
|
recv_buf_.Release(); |
|
|
|
recv_buf_.Release(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
got_message = false; |
|
|
|
got_message = false; |
|
|
|