diff --git a/include/grpcpp/impl/codegen/config_protobuf.h b/include/grpcpp/impl/codegen/config_protobuf.h index 06561cf121047..b4095ff08f599 100644 --- a/include/grpcpp/impl/codegen/config_protobuf.h +++ b/include/grpcpp/impl/codegen/config_protobuf.h @@ -71,6 +71,7 @@ #define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \ ::google::protobuf::io::ZeroCopyInputStream #define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream +#define GRPC_CUSTOM_CODEDOUTPUTSTREAM ::google::protobuf::io::CodedOutputStream #endif #ifndef GRPC_CUSTOM_JSONUTIL @@ -113,6 +114,7 @@ namespace io { typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream; typedef GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream; typedef GRPC_CUSTOM_CODEDINPUTSTREAM CodedInputStream; +typedef GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream; } // namespace io } // namespace protobuf diff --git a/include/grpcpp/impl/proto_utils.h b/include/grpcpp/impl/proto_utils.h index 20d1435842621..f2cd8d21b76c4 100644 --- a/include/grpcpp/impl/proto_utils.h +++ b/include/grpcpp/impl/proto_utils.h @@ -61,7 +61,9 @@ Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb, return grpc::Status::OK; } ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size); - return msg.SerializeToZeroCopyStream(&writer) + protobuf::io::CodedOutputStream cs(&writer); + msg.SerializeWithCachedSizes(&cs); + return !cs.HadError() ? grpc::Status::OK : Status(StatusCode::INTERNAL, "Failed to serialize message"); }