AntoinePrv commented on code in PR #47294: URL: https://github.com/apache/arrow/pull/47294#discussion_r2307043163
########## cpp/src/arrow/util/bit_util.h: ########## @@ -365,5 +365,118 @@ void PackBits(const uint32_t* values, uint8_t* out) { } } +constexpr int64_t MaxLEB128ByteLen(int64_t n_bits) { return CeilDiv(n_bits, 7); } + +template <typename Int> +constexpr int64_t MaxLEB128ByteLenFor = MaxLEB128ByteLen(sizeof(Int) * 8); + +/// Write a integer as LEB128 +/// +/// Write the input value as LEB128 into the outptu buffer and return the number of bytes +/// written. +/// If the output buffer size is insufficient, return 0 but the output may have been +/// written to. +/// +/// \see https://en.wikipedia.org/wiki/LEB128 +/// \see MaxLEB128ByteLenFor +template <typename Int> +constexpr int32_t WriteLEB128(Int value, uint8_t* out, int32_t max_out_size) { Review Comment: The intent *is* to move the functions and refactor them. The reason is previous function was a method of `BitReader` while this PR need to be able to parse ints without a bit reader. `BitReader::GetVlqInt` uses this new function, though because the previous function parses from a contiguous array while the `BitReader` used `GetAligned` there is are checks to find such an array. Another way could be that the new function takes a callback to get the next int but that felt less readable (would have been quite generic with C++ iterators but there are no such APIs in this part of the code). > why is BitWriter::PutVlqInt(uint32_t v) not replaced? An oversight, I should modify it. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org