1#include "duckdb/common/serializer/binary_deserializer.hpp"
2
3namespace duckdb {
4
5void BinaryDeserializer::SetTag(const char *tag) {
6 current_tag = tag;
7 stack.back().read_field_count++;
8}
9
10//===--------------------------------------------------------------------===//
11// Nested Types Hooks
12//===--------------------------------------------------------------------===//
13void BinaryDeserializer::OnObjectBegin() {
14 auto expected_field_count = ReadPrimitive<uint32_t>();
15 auto expected_size = ReadPrimitive<uint64_t>();
16 D_ASSERT(expected_field_count > 0);
17 D_ASSERT(expected_size > 0);
18
19 stack.emplace_back(args&: expected_field_count, args&: expected_size);
20}
21
22void BinaryDeserializer::OnObjectEnd() {
23 auto &frame = stack.back();
24 if (frame.read_field_count < frame.expected_field_count) {
25 throw SerializationException("Not all fields were read. This file might have been written with a newer version "
26 "of DuckDB and is incompatible with this version of DuckDB.");
27 }
28 stack.pop_back();
29}
30
31idx_t BinaryDeserializer::OnListBegin() {
32 return ReadPrimitive<idx_t>();
33}
34
35void BinaryDeserializer::OnListEnd() {
36}
37
38// Deserialize maps as [ { key: ..., value: ... } ]
39idx_t BinaryDeserializer::OnMapBegin() {
40 return ReadPrimitive<idx_t>();
41}
42
43void BinaryDeserializer::OnMapEntryBegin() {
44}
45
46void BinaryDeserializer::OnMapKeyBegin() {
47}
48
49void BinaryDeserializer::OnMapValueBegin() {
50}
51
52void BinaryDeserializer::OnMapEntryEnd() {
53}
54
55void BinaryDeserializer::OnMapEnd() {
56}
57
58void BinaryDeserializer::OnPairBegin() {
59}
60
61void BinaryDeserializer::OnPairKeyBegin() {
62}
63
64void BinaryDeserializer::OnPairValueBegin() {
65}
66
67void BinaryDeserializer::OnPairEnd() {
68}
69
70bool BinaryDeserializer::OnOptionalBegin() {
71 return ReadPrimitive<bool>();
72}
73
74//===--------------------------------------------------------------------===//
75// Primitive Types
76//===--------------------------------------------------------------------===//
77bool BinaryDeserializer::ReadBool() {
78 return ReadPrimitive<bool>();
79}
80
81int8_t BinaryDeserializer::ReadSignedInt8() {
82 return ReadPrimitive<int8_t>();
83}
84
85uint8_t BinaryDeserializer::ReadUnsignedInt8() {
86 return ReadPrimitive<uint8_t>();
87}
88
89int16_t BinaryDeserializer::ReadSignedInt16() {
90 return ReadPrimitive<int16_t>();
91}
92
93uint16_t BinaryDeserializer::ReadUnsignedInt16() {
94 return ReadPrimitive<uint16_t>();
95}
96
97int32_t BinaryDeserializer::ReadSignedInt32() {
98 return ReadPrimitive<int32_t>();
99}
100
101uint32_t BinaryDeserializer::ReadUnsignedInt32() {
102 return ReadPrimitive<uint32_t>();
103}
104
105int64_t BinaryDeserializer::ReadSignedInt64() {
106 return ReadPrimitive<int64_t>();
107}
108
109uint64_t BinaryDeserializer::ReadUnsignedInt64() {
110 return ReadPrimitive<uint64_t>();
111}
112
113float BinaryDeserializer::ReadFloat() {
114 return ReadPrimitive<float>();
115}
116
117double BinaryDeserializer::ReadDouble() {
118 return ReadPrimitive<double>();
119}
120
121string BinaryDeserializer::ReadString() {
122 uint32_t size = ReadPrimitive<uint32_t>();
123 if (size == 0) {
124 return string();
125 }
126 auto buffer = make_unsafe_uniq_array<data_t>(n: size);
127 ReadData(buffer: buffer.get(), read_size: size);
128 return string(const_char_ptr_cast(src: buffer.get()), size);
129}
130
131interval_t BinaryDeserializer::ReadInterval() {
132 return ReadPrimitive<interval_t>();
133}
134
135hugeint_t BinaryDeserializer::ReadHugeInt() {
136 return ReadPrimitive<hugeint_t>();
137}
138
139void BinaryDeserializer::ReadDataPtr(data_ptr_t &ptr, idx_t count) {
140 ReadData(buffer: ptr, read_size: count);
141}
142
143} // namespace duckdb
144