lidavidm commented on code in PR #43255:
URL: https://github.com/apache/arrow/pull/43255#discussion_r1681944012
##########
cpp/src/arrow/flight/types.h:
##########
@@ -159,29 +160,80 @@ struct ARROW_FLIGHT_EXPORT CertKeyPair {
std::string pem_key;
};
+namespace internal {
+
+template <typename T>
+struct remove_unique_ptr {
+ using type = T;
+};
+
+template <typename T>
+struct remove_unique_ptr<std::unique_ptr<T>> {
+ using type = T;
+};
+
+// Base CRTP type
+template <class T>
+struct BaseType {
+ protected:
+ using SelfT = typename remove_unique_ptr<T>::type;
+
+ const SelfT& self() const { return static_cast<const SelfT&>(*this); }
+ SelfT& self() { return static_cast<SelfT&>(*this); }
+
+ public:
+ BaseType() = default;
+
+ 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<std::string> SerializeToString() const {
+ std::string out;
+ ARROW_RETURN_NOT_OK(self().DoSerializeToString(&out));
+ return out;
+ }
+
+ inline static arrow::Result<T> Deserialize(std::string_view serialized) {
+ T out;
+ ARROW_RETURN_NOT_OK(SelfT::DoDeserialize(serialized, &out));
+ return out;
+ }
+
+ inline arrow::Result<std::shared_ptr<Buffer>> SerializeToBuffer() const {
+ std::string out;
+ ARROW_RETURN_NOT_OK(self().DoSerializeToString(&out));
+ return Buffer::FromString(std::move(out));
+ }
+};
+
+} // namespace internal
+
/// \brief A type of action that can be performed with the DoAction RPC.
-struct ARROW_FLIGHT_EXPORT ActionType {
+struct ARROW_FLIGHT_EXPORT ActionType : public internal::BaseType<ActionType> {
/// \brief The name of the action.
std::string type;
/// \brief A human-readable description of the action.
std::string description;
+ ActionType() = default;
+
+ ActionType(std::string type, std::string description)
+ : type(std::move(type)), description(std::move(description)) {}
+
std::string ToString() const;
bool Equals(const ActionType& other) const;
- friend bool operator==(const ActionType& left, const ActionType& right) {
- return left.Equals(right);
- }
- friend bool operator!=(const ActionType& left, const ActionType& right) {
- return !(left == right);
- }
-
/// \brief Serialize this message to its wire-format representation.
- arrow::Result<std::string> SerializeToString() const;
+ arrow::Status DoSerializeToString(std::string* out) const;
Review Comment:
I'd really rather not have so many different methods. If we're going to keep
them, please at least make them overloads (so drop the 'Do') since they are
just the same methods implemented in terms of each other.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]