diff --git a/cpp/src/arrow/flight/serialization_internal.cc b/cpp/src/arrow/flight/serialization_internal.cc index 2f419462ed804..fedfc7d5cd590 100644 --- a/cpp/src/arrow/flight/serialization_internal.cc +++ b/cpp/src/arrow/flight/serialization_internal.cc @@ -268,6 +268,13 @@ Status FromProto(const pb::FlightInfo& pb_info, FlightInfo::Data* info) { return Status::OK(); } +Status FromProto(const pb::FlightInfo& pb_info, std::unique_ptr* info) { + FlightInfo::Data info_data; + RETURN_NOT_OK(FromProto(pb_info, &info_data)); + *info = std::make_unique(std::move(info_data)); + return Status::OK(); +} + Status FromProto(const pb::BasicAuth& pb_basic_auth, BasicAuth* basic_auth) { basic_auth->password = pb_basic_auth.password(); basic_auth->username = pb_basic_auth.username(); @@ -340,6 +347,13 @@ Status FromProto(const pb::PollInfo& pb_info, PollInfo* info) { return Status::OK(); } +Status FromProto(const pb::PollInfo& pb_info, std::unique_ptr* info) { + PollInfo poll_info; + RETURN_NOT_OK(FromProto(pb_info, &poll_info)); + *info = std::make_unique(std::move(poll_info)); + return Status::OK(); +} + Status ToProto(const PollInfo& info, pb::PollInfo* pb_info) { if (info.info) { RETURN_NOT_OK(ToProto(*info.info, pb_info->mutable_info())); diff --git a/cpp/src/arrow/flight/serialization_internal.h b/cpp/src/arrow/flight/serialization_internal.h index cdb8ca5cf7842..ffde47d43c00e 100644 --- a/cpp/src/arrow/flight/serialization_internal.h +++ b/cpp/src/arrow/flight/serialization_internal.h @@ -61,7 +61,9 @@ Status FromProto(const pb::FlightEndpoint& pb_endpoint, FlightEndpoint* endpoint Status FromProto(const pb::RenewFlightEndpointRequest& pb_request, RenewFlightEndpointRequest* request); Status FromProto(const pb::FlightInfo& pb_info, FlightInfo::Data* info); +Status FromProto(const pb::FlightInfo& pb_info, std::unique_ptr* info); Status FromProto(const pb::PollInfo& pb_info, PollInfo* info); +Status FromProto(const pb::PollInfo& pb_info, std::unique_ptr* info); Status FromProto(const pb::CancelFlightInfoRequest& pb_request, CancelFlightInfoRequest* request); Status FromProto(const pb::SchemaResult& pb_result, std::string* result); diff --git a/cpp/src/arrow/flight/types.h b/cpp/src/arrow/flight/types.h index 11f629791a3c0..ab5138cff9689 100644 --- a/cpp/src/arrow/flight/types.h +++ b/cpp/src/arrow/flight/types.h @@ -162,18 +162,34 @@ struct ARROW_FLIGHT_EXPORT CertKeyPair { namespace internal { +template +struct remove_unique_ptr { + using type = T; +}; + +template +struct remove_unique_ptr> { + using type = T; +}; + // Base CRTP type template struct BaseType { protected: - const T& self() const { return static_cast(*this); } - T& self() { return static_cast(*this); } + using SelfT = typename remove_unique_ptr::type; + + const SelfT& self() const { return static_cast(*this); } + SelfT& self() { return static_cast(*this); } public: BaseType() = default; - friend bool operator==(const T& left, const T& right) { return left.Equals(right); } - friend bool operator!=(const T& left, const T& right) { return !left.Equals(right); } + friend bool operator==(const SelfT& left, const SelfT& right) { + return left.Equals(right); + } + friend bool operator!=(const SelfT& left, const SelfT& right) { + return !left.Equals(right); + } /// \brief Serialize this message to its wire-format representation. inline arrow::Result SerializeToString() const { @@ -589,7 +605,8 @@ struct ARROW_FLIGHT_EXPORT SchemaResult : public internal::BaseType { +class ARROW_FLIGHT_EXPORT FlightInfo + : public internal::BaseType> { public: struct Data { std::string schema; @@ -668,7 +685,8 @@ class ARROW_FLIGHT_EXPORT FlightInfo : public internal::BaseType { }; /// \brief The information to process a long-running query. -class ARROW_FLIGHT_EXPORT PollInfo : public internal::BaseType { +class ARROW_FLIGHT_EXPORT PollInfo + : public internal::BaseType> { public: /// The currently available results so far. std::unique_ptr info = NULLPTR;