Skip to content

Commit 533b71f

Browse files
committed
Factorize more
1 parent dbd4e77 commit 533b71f

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

include/sparrow_ipc/compression.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ namespace sparrow_ipc
1818

1919
// CompressionType to_compression_type(org::apache::arrow::flatbuf::CompressionType compression_type);
2020

21-
std::vector<std::uint8_t> compress(org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data);
22-
std::vector<std::uint8_t> decompress(org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data);
21+
std::vector<std::uint8_t> compress(const org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data);
22+
std::vector<std::uint8_t> decompress(const org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data);
2323
}

include/sparrow_ipc/serialize_utils.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,23 @@ namespace sparrow_ipc
117117
return total_size;
118118
}
119119

120-
void fill_body_and_get_buffers_compressed(const sparrow::arrow_proxy& arrow_proxy, std::vector<uint8_t>& body, std::vector<org::apache::arrow::flatbuf::Buffer>& flatbuf_buffers, int64_t& offset, org::apache::arrow::flatbuf::CompressionType compression_type);
120+
/**
121+
* @brief Generates the compressed message body and buffer metadata for a record batch.
122+
*
123+
* This function traverses the record batch, compresses each buffer using the specified
124+
* compression algorithm, and constructs the message body. For each compressed buffer,
125+
* it is prefixed by its 8-byte uncompressed size. Padding is added after each
126+
* compressed buffer to ensure 8-byte alignment.
127+
*
128+
* @param record_batch The record batch to serialize.
129+
* @param compression_type The compression algorithm to use (e.g., LZ4_FRAME, ZSTD).
130+
* @return A std::pair containing:
131+
* - first: A vector of bytes representing the complete compressed message body.
132+
* - second: A vector of FlatBuffer Buffer objects describing the offset and
133+
* size of each buffer within the compressed body.
134+
*/
135+
[[nodiscard]] SPARROW_IPC_API std::pair<std::vector<uint8_t>, std::vector<org::apache::arrow::flatbuf::Buffer>>
136+
generate_compressed_body_and_buffers(const sparrow::record_batch& record_batch, const org::apache::arrow::flatbuf::CompressionType compression_type);
121137

122138
/**
123139
* @brief Fills the body vector with serialized data from an arrow proxy and its children.

src/compression.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace sparrow_ipc
2020
// }
2121
// }
2222

23-
std::vector<std::uint8_t> compress(org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data)
23+
std::vector<std::uint8_t> compress(const org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data)
2424
{
2525
if (data.empty())
2626
{
@@ -30,7 +30,7 @@ namespace sparrow_ipc
3030
{
3131
case org::apache::arrow::flatbuf::CompressionType::LZ4_FRAME:
3232
{
33-
std::int64_t uncompressed_size = data.size();
33+
const std::int64_t uncompressed_size = data.size();
3434
const size_t max_compressed_size = LZ4F_compressFrameBound(uncompressed_size, nullptr);
3535
std::vector<std::uint8_t> compressed_data(max_compressed_size);
3636
const size_t compressed_size = LZ4F_compressFrame(compressed_data.data(), max_compressed_size, data.data(), uncompressed_size, nullptr);
@@ -46,7 +46,7 @@ namespace sparrow_ipc
4646
}
4747
}
4848

49-
std::vector<std::uint8_t> decompress(org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data)
49+
std::vector<std::uint8_t> decompress(const org::apache::arrow::flatbuf::CompressionType compression_type, std::span<const std::uint8_t> data)
5050
{
5151
if (data.empty())
5252
{

src/serialize_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <tuple>
12
#include <lz4frame.h>
23

34
#include "sparrow_ipc/flatbuffer_utils.hpp"

0 commit comments

Comments
 (0)