sparrow-ipc 0.2.0
Loading...
Searching...
No Matches
deserializer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <iterator>
5#include <numeric>
6#include <ranges>
7
8#include <sparrow/record_batch.hpp>
9
10#include "deserialize.hpp"
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>
18 {
19 public:
20
21 deserializer(R& data)
22 : m_data(&data)
23 {
24 }
25
26 void deserialize(std::span<const uint8_t> data)
27 {
28 // Insert at the end of m_data container the deserialized record batches
29 auto& container = *m_data;
30 auto deserialized_batches = sparrow_ipc::deserialize_stream(data);
31 container.insert(
32 std::end(container),
33 std::make_move_iterator(std::begin(deserialized_batches)),
34 std::make_move_iterator(std::end(deserialized_batches))
35 );
36 }
37
38 deserializer& operator<<(std::span<const uint8_t> data)
39 {
40 deserialize(data);
41 return *this;
42 }
43
44 private:
45
46 R* m_data;
47 };
48}
void deserialize(std::span< const uint8_t > data)
deserializer & operator<<(std::span< const uint8_t > data)
SPARROW_IPC_API std::vector< sparrow::record_batch > deserialize_stream(std::span< const uint8_t > data)
Deserializes an Arrow IPC stream from binary data into a vector of record batches.