| 351 | |
| 352 | template <typename Int> |
| 353 | inline bool BitWriter::PutVlqInt(Int v) { |
| 354 | static_assert(std::is_integral_v<Int>); |
| 355 | |
| 356 | constexpr auto kBufferSize = kMaxLEB128ByteLenFor<Int>; |
| 357 | |
| 358 | uint8_t buffer[kBufferSize] = {}; |
| 359 | const auto bytes_written = WriteLEB128(v, buffer, kBufferSize); |
| 360 | ARROW_DCHECK_LE(bytes_written, kBufferSize); |
| 361 | if constexpr (std::is_signed_v<Int>) { |
| 362 | // Can fail if negative |
| 363 | if (ARROW_PREDICT_FALSE(!bytes_written == 0)) { |
| 364 | return false; |
| 365 | } |
| 366 | } else { |
| 367 | // Cannot fail since we gave max space |
| 368 | ARROW_DCHECK_GT(bytes_written, 0); |
| 369 | } |
| 370 | |
| 371 | for (int i = 0; i < bytes_written; ++i) { |
| 372 | const bool success = PutAligned(buffer[i], 1); |
| 373 | if (ARROW_PREDICT_FALSE(!success)) { |
| 374 | return false; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | template <typename Int> |
| 382 | inline bool BitReader::GetVlqInt(Int* v) { |
no test coverage detected