cyb70289 commented on a change in pull request #10651:
URL: https://github.com/apache/arrow/pull/10651#discussion_r663604126



##########
File path: cpp/src/arrow/util/endian.h
##########
@@ -169,13 +205,47 @@ static inline T FromBigEndian(T value) {
   return value;
 }
 
+template <typename T, size_t N>
+static inline std::array<T, N> FromBigEndian(std::array<T, N> array) {
+  return array;
+}
+
 template <typename T, typename = internal::EnableIfIsOneOf<
                           T, int64_t, uint64_t, int32_t, uint32_t, int16_t, 
uint16_t,
                           uint8_t, int8_t, float, double>>
 static inline T FromLittleEndian(T value) {
   return ByteSwap(value);
 }
+
+template <typename T, size_t N>
+static inline std::array<T, N> FromLittleEndian(std::array<T, N> array) {
+  std::reverse(array.begin(), array.end());
+  return array;
+}
 #endif
 
+// Read a native endian array as little endian
+template <typename T, size_t N>
+struct LittleEndianArrayReader {
+  const std::array<T, N>& arr;
+
+  explicit LittleEndianArrayReader(const std::array<T, N>& arr) : arr(arr) {}
+
+  const T& operator[](size_t i) const { return arr[ARROW_LITTLE_ENDIAN ? i : N 
- 1 - i]; }
+};
+
+// Read/write a native endian array as little endian
+template <typename T, size_t N>
+struct LittleEndianArrayWriter {

Review comment:
       No overhead from these visitor classes, https://godbolt.org/z/3Pn7GMjMo




-- 
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]


Reply via email to