kiszk commented on a change in pull request #7507: URL: https://github.com/apache/arrow/pull/7507#discussion_r567382132
########## File path: cpp/src/arrow/array/util.cc ########## @@ -74,6 +75,220 @@ class ArrayDataWrapper { std::shared_ptr<Array>* out_; }; +class ArrayDataEndianSwapper { + public: + ArrayDataEndianSwapper(std::shared_ptr<ArrayData>& data, int64_t length, + std::shared_ptr<ArrayData>* out) + : data_(data), length_(length), out_(out) {} + + Status SwapType(const DataType& type) { + RETURN_NOT_OK(VisitTypeInline(type, this)); + RETURN_NOT_OK(SwapChildren(type.fields())); + return Status::OK(); + } + + Status SwapChildren(std::vector<std::shared_ptr<Field>> child_fields) { + int i = 0; + for (const auto& child_field : child_fields) { + ARROW_ASSIGN_OR_RAISE( + (*out_)->child_data[i], + SwapEndianArrayData(data_->child_data[i], child_field.get()->type())); + i++; + } + return Status::OK(); + } + + template <typename T> + Result<std::shared_ptr<Buffer>> ByteSwapBuffer(std::shared_ptr<Buffer>& in_buffer, + int64_t length, int64_t extra_size) { + auto in_data = reinterpret_cast<const T*>(in_buffer->data()); + ARROW_ASSIGN_OR_RAISE(auto out_buffer, AllocateBuffer(in_buffer->size())); Review comment: As I wrote below, it would be fine if we can reuse the existing buffer. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org