sparrow-ipc 0.3.0
Loading...
Searching...
No Matches
serializer_reserve.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <numeric>
4#include <ranges>
5
6#include <sparrow/record_batch.hpp>
7
12
13namespace sparrow_ipc
14{
15 template <std::ranges::input_range R>
16 requires std::same_as<std::ranges::range_value_t<R>, sparrow::record_batch>
17 [[nodiscard]] std::size_t calculate_serializer_reserve_size(
18 const R& record_batches,
19 std::size_t current_stream_size,
20 bool schema_received,
21 std::optional<CompressionType> compression,
22 const dictionary_tracker& dict_tracker,
23 std::optional<std::reference_wrapper<CompressionCache>> cache = std::nullopt
24 )
25 {
26 if (std::ranges::empty(record_batches))
27 {
28 return current_stream_size;
29 }
30
31 dictionary_tracker reservation_tracker = dict_tracker;
32 const std::size_t total_with_record_batches = std::accumulate(
33 record_batches.begin(),
34 record_batches.end(),
35 current_stream_size,
36 [&cache, &reservation_tracker, compression](std::size_t acc, const sparrow::record_batch& rb)
37 {
38 std::size_t dictionaries_size = 0;
39 for_each_pending_dictionary(rb, reservation_tracker, [&](const dictionary_info& dict_info)
40 {
41 dictionaries_size += calculate_dictionary_batch_message_size(
42 dict_info.id,
43 dict_info.data,
44 dict_info.is_delta,
45 compression,
46 cache
47 );
48 });
49
50 return acc + dictionaries_size
51 + calculate_record_batch_message_size(rb, compression, cache);
52 }
53 );
54
55 if (!schema_received)
56 {
57 return total_with_record_batches
58 + calculate_schema_message_size(*record_batches.begin());
59 }
60
61 return total_with_record_batches;
62 }
63}
Tracks dictionaries during serialization.
std::size_t calculate_serializer_reserve_size(const R &record_batches, std::size_t current_stream_size, bool schema_received, std::optional< CompressionType > compression, const dictionary_tracker &dict_tracker, std::optional< std::reference_wrapper< CompressionCache > > cache=std::nullopt)
SPARROW_IPC_API std::size_t calculate_record_batch_message_size(const sparrow::record_batch &record_batch, std::optional< CompressionType > compression=std::nullopt, std::optional< std::reference_wrapper< CompressionCache > > cache=std::nullopt)
Calculates the total serialized size of a record batch message.
SPARROW_IPC_API std::size_t calculate_schema_message_size(const sparrow::record_batch &record_batch)
Calculates the total serialized size of a schema message.