| 82 | /// Use BitWriter to pack values into a vector. |
| 83 | template <typename Int> |
| 84 | std::vector<uint8_t> PackValues(const std::vector<Int>& values, int num_values, |
| 85 | int bit_width, int bit_offset) { |
| 86 | if (bit_width == 0) { |
| 87 | return {}; |
| 88 | } |
| 89 | |
| 90 | const auto num_bytes = GetNumBytes(num_values, bit_width, bit_offset); |
| 91 | |
| 92 | std::vector<uint8_t> out(static_cast<std::size_t>(num_bytes)); |
| 93 | bit_util::BitWriter writer(out.data(), num_bytes); |
| 94 | |
| 95 | // Write a first 0 value to make an offset |
| 96 | const bool written = writer.PutValue(0, bit_offset); |
| 97 | ARROW_DCHECK(written); |
| 98 | for (const auto& v : values) { |
| 99 | const bool written = writer.PutValue(v, bit_width); |
| 100 | ARROW_DCHECK(written); |
| 101 | } |
| 102 | |
| 103 | writer.Flush(); |
| 104 | |
| 105 | return out; |
| 106 | } |
| 107 | |
| 108 | template <typename Int> |
| 109 | class TestUnpack : public ::testing::Test { |
no test coverage detected