1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/serializer/buffered_serializer.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/serializer.hpp"
12#include "duckdb/common/unique_ptr.hpp"
13
14namespace duckdb {
15
16#define SERIALIZER_DEFAULT_SIZE 1024
17
18struct BinaryData {
19 unsafe_unique_array<data_t> data;
20 idx_t size;
21};
22
23class BufferedSerializer : public Serializer {
24public:
25 //! Serializes to a buffer allocated by the serializer, will expand when
26 //! writing past the initial threshold
27 DUCKDB_API explicit BufferedSerializer(idx_t maximum_size = SERIALIZER_DEFAULT_SIZE);
28 //! Serializes to a provided (owned) data pointer
29 BufferedSerializer(unsafe_unique_array<data_t> data, idx_t size);
30 BufferedSerializer(data_ptr_t data, idx_t size);
31
32 idx_t maximum_size;
33 data_ptr_t data;
34
35 BinaryData blob;
36
37public:
38 void WriteData(const_data_ptr_t buffer, uint64_t write_size) override;
39
40 //! Retrieves the data after the writing has been completed
41 BinaryData GetData() {
42 return std::move(blob);
43 }
44
45 void Reset() {
46 blob.size = 0;
47 }
48};
49
50} // namespace duckdb
51