A transform that swaps every pair of bytes
| 456 | struct SwappingTransform { |
| 457 | // A transform that swaps every pair of bytes |
| 458 | Result<std::shared_ptr<Buffer>> operator()(const std::shared_ptr<Buffer>& buf) { |
| 459 | int64_t dest_size = bit_util::RoundDown(buf->size() + has_pending_, 2); |
| 460 | ARROW_ASSIGN_OR_RAISE(auto dest, AllocateBuffer(dest_size)); |
| 461 | const uint8_t* data = buf->data(); |
| 462 | uint8_t* out_data = dest->mutable_data(); |
| 463 | if (has_pending_ && dest_size > 0) { |
| 464 | *out_data++ = *data++; |
| 465 | *out_data++ = pending_byte_; |
| 466 | dest_size -= 2; |
| 467 | } |
| 468 | for (int64_t i = 0; i < dest_size; i += 2) { |
| 469 | out_data[i] = data[i + 1]; |
| 470 | out_data[i + 1] = data[i]; |
| 471 | } |
| 472 | has_pending_ = has_pending_ ^ (buf->size() & 1); |
| 473 | if (has_pending_) { |
| 474 | pending_byte_ = buf->data()[buf->size() - 1]; |
| 475 | } |
| 476 | return std::shared_ptr<Buffer>(std::move(dest)); |
| 477 | } |
| 478 | |
| 479 | protected: |
| 480 | bool has_pending_ = 0; |
nothing calls this directly
no test coverage detected