1#include "duckdb/common/serializer/buffered_serializer.hpp"
2
3#include <cstring>
4
5using namespace duckdb;
6using namespace std;
7
8BufferedSerializer::BufferedSerializer(idx_t maximum_size)
9 : BufferedSerializer(unique_ptr<data_t[]>(new data_t[maximum_size]), maximum_size) {
10}
11
12BufferedSerializer::BufferedSerializer(unique_ptr<data_t[]> data, idx_t size) : maximum_size(size), data(data.get()) {
13 blob.size = 0;
14 blob.data = move(data);
15}
16
17void BufferedSerializer::WriteData(const_data_ptr_t buffer, idx_t write_size) {
18 if (blob.size + write_size >= maximum_size) {
19 do {
20 maximum_size *= 2;
21 } while (blob.size + write_size > maximum_size);
22 auto new_data = new data_t[maximum_size];
23 memcpy(new_data, data, blob.size);
24 data = new_data;
25 blob.data = unique_ptr<data_t[]>(new_data);
26 }
27
28 memcpy(blob.data.get() + blob.size, buffer, write_size);
29 blob.size += write_size;
30}
31