Skip to content

Commit

Permalink
BugFix: fix pb derialization failed at server
Browse files Browse the repository at this point in the history
- Enable lite via `option optimize_for = LITE_RUNTIME;` at proto file
  • Loading branch information
weimch committed Jan 31, 2024
1 parent bacbc06 commit 3ed57bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
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

0 comments on commit 3ed57bb

Please sign in to comment.