Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: fix pb derialization failed at server #114

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions trpc/server/rpc/unary_rpc_method_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class UnaryRpcMethodHandler : public RpcMethodHandlerInterface {

#ifdef TRPC_PROTO_USE_ARENA
static constexpr bool IsEnablePbArena() {
return std::is_convertible_v<RequestType*, google::protobuf::Message*> &&
return std::is_convertible_v<RequestType*, google::protobuf::MessageLite*> &&
google::protobuf::Arena::is_arena_constructable<RequestType>::value &&
std::is_convertible_v<ResponseType*, google::protobuf::Message*> &&
std::is_convertible_v<ResponseType*, google::protobuf::MessageLite*> &&
google::protobuf::Arena::is_arena_constructable<ResponseType>::value;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion trpc/server/server_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ServerContext::SetDyeingKey(const std::string& key, const std::string& valu
invoke_info_.message_type |= TrpcMessageType::TRPC_DYEING_MESSAGE;
}

void ServerContext::SendUnaryResponse(const Status& status, google::protobuf::Message* pb) {
void ServerContext::SendUnaryResponse(const Status& status, google::protobuf::MessageLite* pb) {
void* rsp_data = static_cast<void*>(pb);
SendUnaryResponse(status, rsp_data, serialization::kPbMessage);
}
Expand Down
6 changes: 3 additions & 3 deletions trpc/server/server_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ class ServerContext : public RefCounted<ServerContext> {
/// @note before calling this method, you should call `SetResponse(false)` in the rpc interface implemented
template <typename T>
void SendUnaryResponse(const Status& status, T& biz_rsp) {
if constexpr (std::is_convertible_v<T*, google::protobuf::Message*>) {
SendUnaryResponse(status, static_cast<google::protobuf::Message*>(&biz_rsp));
if constexpr (std::is_convertible_v<T*, google::protobuf::MessageLite*>) {
SendUnaryResponse(status, static_cast<google::protobuf::MessageLite*>(&biz_rsp));
} else if constexpr (std::is_convertible_v<T*, rapidjson::Document*>) {
SendUnaryResponse(status, static_cast<rapidjson::Document*>(&biz_rsp));
} else if constexpr (std::is_convertible_v<T*, flatbuffers::trpc::MessageFbs*>) {
Expand Down Expand Up @@ -600,7 +600,7 @@ class ServerContext : public RefCounted<ServerContext> {

private:
// Implementation of asynchronous packet return on the server side
void SendUnaryResponse(const Status& status, google::protobuf::Message* pb);
void SendUnaryResponse(const Status& status, google::protobuf::MessageLite* pb);

// Implementation of asynchronous packet return on the server side
void SendUnaryResponse(const Status& status, flatbuffers::trpc::MessageFbs* fbs);
Expand Down
4 changes: 2 additions & 2 deletions trpc/stream/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StreamReaderImpl : public RefCounted<StreamReaderImpl<R>> {
private:
inline bool Deserialize(NoncontiguousBuffer* buffer, void* msg) {
serialization::DataType type;
if constexpr (std::is_convertible_v<R*, google::protobuf::Message*>) {
if constexpr (std::is_convertible_v<R*, google::protobuf::MessageLite*>) {
type = serialization::kPbMessage;
} else if constexpr (std::is_convertible_v<R*, rapidjson::Document*>) {
type = serialization::kRapidJson;
Expand Down Expand Up @@ -132,7 +132,7 @@ class StreamWriterImpl : public RefCounted<StreamWriterImpl<W>> {
private:
inline bool Serialize(void* msg, NoncontiguousBuffer* buffer) {
serialization::DataType type;
if constexpr (std::is_convertible_v<W*, google::protobuf::Message*>) {
if constexpr (std::is_convertible_v<W*, google::protobuf::MessageLite*>) {
type = serialization::kPbMessage;
} else if constexpr (std::is_convertible_v<W*, rapidjson::Document*>) {
type = serialization::kRapidJson;
Expand Down
Loading