1 | #include "duckdb/common/serializer/binary_deserializer.hpp" |
---|---|
2 | |
3 | namespace duckdb { |
4 | |
5 | void BinaryDeserializer::SetTag(const char *tag) { |
6 | current_tag = tag; |
7 | stack.back().read_field_count++; |
8 | } |
9 | |
10 | //===--------------------------------------------------------------------===// |
11 | // Nested Types Hooks |
12 | //===--------------------------------------------------------------------===// |
13 | void 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 | |
22 | void 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 | |
31 | idx_t BinaryDeserializer::OnListBegin() { |
32 | return ReadPrimitive<idx_t>(); |
33 | } |
34 | |
35 | void BinaryDeserializer::OnListEnd() { |
36 | } |
37 | |
38 | // Deserialize maps as [ { key: ..., value: ... } ] |
39 | idx_t BinaryDeserializer::OnMapBegin() { |
40 | return ReadPrimitive<idx_t>(); |
41 | } |
42 | |
43 | void BinaryDeserializer::OnMapEntryBegin() { |
44 | } |
45 | |
46 | void BinaryDeserializer::OnMapKeyBegin() { |
47 | } |
48 | |
49 | void BinaryDeserializer::OnMapValueBegin() { |
50 | } |
51 | |
52 | void BinaryDeserializer::OnMapEntryEnd() { |
53 | } |
54 | |
55 | void BinaryDeserializer::OnMapEnd() { |
56 | } |
57 | |
58 | void BinaryDeserializer::OnPairBegin() { |
59 | } |
60 | |
61 | void BinaryDeserializer::OnPairKeyBegin() { |
62 | } |
63 | |
64 | void BinaryDeserializer::OnPairValueBegin() { |
65 | } |
66 | |
67 | void BinaryDeserializer::OnPairEnd() { |
68 | } |
69 | |
70 | bool BinaryDeserializer::OnOptionalBegin() { |
71 | return ReadPrimitive<bool>(); |
72 | } |
73 | |
74 | //===--------------------------------------------------------------------===// |
75 | // Primitive Types |
76 | //===--------------------------------------------------------------------===// |
77 | bool BinaryDeserializer::ReadBool() { |
78 | return ReadPrimitive<bool>(); |
79 | } |
80 | |
81 | int8_t BinaryDeserializer::ReadSignedInt8() { |
82 | return ReadPrimitive<int8_t>(); |
83 | } |
84 | |
85 | uint8_t BinaryDeserializer::ReadUnsignedInt8() { |
86 | return ReadPrimitive<uint8_t>(); |
87 | } |
88 | |
89 | int16_t BinaryDeserializer::ReadSignedInt16() { |
90 | return ReadPrimitive<int16_t>(); |
91 | } |
92 | |
93 | uint16_t BinaryDeserializer::ReadUnsignedInt16() { |
94 | return ReadPrimitive<uint16_t>(); |
95 | } |
96 | |
97 | int32_t BinaryDeserializer::ReadSignedInt32() { |
98 | return ReadPrimitive<int32_t>(); |
99 | } |
100 | |
101 | uint32_t BinaryDeserializer::ReadUnsignedInt32() { |
102 | return ReadPrimitive<uint32_t>(); |
103 | } |
104 | |
105 | int64_t BinaryDeserializer::ReadSignedInt64() { |
106 | return ReadPrimitive<int64_t>(); |
107 | } |
108 | |
109 | uint64_t BinaryDeserializer::ReadUnsignedInt64() { |
110 | return ReadPrimitive<uint64_t>(); |
111 | } |
112 | |
113 | float BinaryDeserializer::ReadFloat() { |
114 | return ReadPrimitive<float>(); |
115 | } |
116 | |
117 | double BinaryDeserializer::ReadDouble() { |
118 | return ReadPrimitive<double>(); |
119 | } |
120 | |
121 | string 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 | |
131 | interval_t BinaryDeserializer::ReadInterval() { |
132 | return ReadPrimitive<interval_t>(); |
133 | } |
134 | |
135 | hugeint_t BinaryDeserializer::ReadHugeInt() { |
136 | return ReadPrimitive<hugeint_t>(); |
137 | } |
138 | |
139 | void BinaryDeserializer::ReadDataPtr(data_ptr_t &ptr, idx_t count) { |
140 | ReadData(buffer: ptr, read_size: count); |
141 | } |
142 | |
143 | } // namespace duckdb |
144 |