Get a batch of values return the number of decoded elements. May write fewer elements to the output than requested if there are not enough values left.
| 372 | /// May write fewer elements to the output than requested if there are not enough values |
| 373 | /// left. |
| 374 | [[nodiscard]] rle_size_t GetBatch(value_type* out, rle_size_t batch_size, |
| 375 | rle_size_t value_bit_width) { |
| 376 | const int64_t bits_read = static_cast<int64_t>(values_read_) * value_bit_width; |
| 377 | const int64_t bytes_fully_read = bits_read / 8; |
| 378 | // The parser only creates runs whose full payload fits in max_read_bytes_ (see |
| 379 | // BitPackedRun), so the max_read_bytes difference below is in [0, max_read_bytes_] |
| 380 | // and fits an int. A negative (unbounded) max_read_bytes_ stays negative. |
| 381 | ARROW_DCHECK(max_read_bytes_ < 0 || bytes_fully_read <= max_read_bytes_); |
| 382 | const uint8_t* unread_data = data_ + bytes_fully_read; |
| 383 | |
| 384 | const ::arrow::internal::UnpackOptions opts{ |
| 385 | /* .batch_size= */ std::min(batch_size, remaining()), |
| 386 | /* .bit_width= */ value_bit_width, |
| 387 | /* .bit_offset= */ static_cast<int>(bits_read % 8), |
| 388 | /* .max_read_bytes= */ static_cast<int>(max_read_bytes_ - bytes_fully_read), |
| 389 | }; |
| 390 | |
| 391 | if constexpr (std::is_same_v<T, bool>) { |
| 392 | ::arrow::internal::unpack(unread_data, out, opts); |
| 393 | |
| 394 | } else { |
| 395 | ::arrow::internal::unpack( |
| 396 | unread_data, reinterpret_cast<std::make_unsigned_t<value_type>*>(out), opts); |
| 397 | } |
| 398 | values_read_ += opts.batch_size; |
| 399 | return opts.batch_size; |
| 400 | } |
| 401 | |
| 402 | private: |
| 403 | /// The pointer to the beginning of the run |