be/src/core/string_buffer.hpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | #include <fmt/format.h> |
20 | | |
21 | | #include <cstring> |
22 | | |
23 | | #include "core/arena.h" |
24 | | #include "core/column/column_string.h" |
25 | | #include "core/string_ref.h" |
26 | | |
27 | | namespace doris { |
28 | | static constexpr size_t DEFAULT_MAX_STRING_SIZE = 1073741824; // 1GB |
29 | | static constexpr size_t DEFAULT_MAX_JSON_SIZE = 1073741824; // 1GB |
30 | | |
31 | | // store and commit data. only after commit the data is effective on its' base(ColumnString) |
32 | | // everytime commit, the _data add one row. |
33 | | class BufferWritable final { |
34 | | public: |
35 | | explicit BufferWritable(ColumnString& vector) |
36 | 87.2k | : _data(vector.get_chars()), _offsets(vector.get_offsets()) {} |
37 | | |
38 | 71.2M | void write(const char* data, size_t len) { |
39 | 71.2M | _data.insert(data, data + len); |
40 | 71.2M | _now_offset += len; |
41 | 71.2M | } |
42 | | |
43 | 629k | void write(char c) { |
44 | 629k | const char* p = &c; |
45 | 629k | _data.insert(p, p + 1); |
46 | 629k | _now_offset += 1; |
47 | 629k | } |
48 | | |
49 | | // commit may not be called if exception is thrown in writes(e.g. alloc mem failed) |
50 | 65.6M | void commit() { |
51 | 65.6M | ColumnString::check_chars_length(_offsets.back() + _now_offset, 0); |
52 | 65.6M | _offsets.push_back(_offsets.back() + _now_offset); |
53 | 65.6M | _now_offset = 0; |
54 | 65.6M | } |
55 | | |
56 | 0 | char* data() { return reinterpret_cast<char*>(_data.data() + _now_offset + _offsets.back()); } |
57 | | |
58 | 0 | void add_offset(size_t len) { _now_offset += len; } |
59 | | |
60 | 0 | void resize(size_t size) { _data.resize(size + _now_offset + _offsets.back()); } |
61 | | |
62 | | template <typename T> |
63 | 133k | void write_number(T data) { |
64 | 133k | fmt::memory_buffer buffer; |
65 | 133k | fmt::format_to(buffer, "{}", data); |
66 | 133k | write(buffer.data(), buffer.size()); |
67 | 133k | } _ZN5doris14BufferWritable12write_numberIiEEvT_ Line | Count | Source | 63 | 22.0k | void write_number(T data) { | 64 | 22.0k | fmt::memory_buffer buffer; | 65 | 22.0k | fmt::format_to(buffer, "{}", data); | 66 | 22.0k | write(buffer.data(), buffer.size()); | 67 | 22.0k | } |
_ZN5doris14BufferWritable12write_numberIdEEvT_ Line | Count | Source | 63 | 169 | void write_number(T data) { | 64 | 169 | fmt::memory_buffer buffer; | 65 | 169 | fmt::format_to(buffer, "{}", data); | 66 | 169 | write(buffer.data(), buffer.size()); | 67 | 169 | } |
_ZN5doris14BufferWritable12write_numberIhEEvT_ Line | Count | Source | 63 | 3.73k | void write_number(T data) { | 64 | 3.73k | fmt::memory_buffer buffer; | 65 | 3.73k | fmt::format_to(buffer, "{}", data); | 66 | 3.73k | write(buffer.data(), buffer.size()); | 67 | 3.73k | } |
_ZN5doris14BufferWritable12write_numberIaEEvT_ Line | Count | Source | 63 | 25.4k | void write_number(T data) { | 64 | 25.4k | fmt::memory_buffer buffer; | 65 | 25.4k | fmt::format_to(buffer, "{}", data); | 66 | 25.4k | write(buffer.data(), buffer.size()); | 67 | 25.4k | } |
_ZN5doris14BufferWritable12write_numberIsEEvT_ Line | Count | Source | 63 | 23.0k | void write_number(T data) { | 64 | 23.0k | fmt::memory_buffer buffer; | 65 | 23.0k | fmt::format_to(buffer, "{}", data); | 66 | 23.0k | write(buffer.data(), buffer.size()); | 67 | 23.0k | } |
_ZN5doris14BufferWritable12write_numberIlEEvT_ Line | Count | Source | 63 | 41.4k | void write_number(T data) { | 64 | 41.4k | fmt::memory_buffer buffer; | 65 | 41.4k | fmt::format_to(buffer, "{}", data); | 66 | 41.4k | write(buffer.data(), buffer.size()); | 67 | 41.4k | } |
_ZN5doris14BufferWritable12write_numberInEEvT_ Line | Count | Source | 63 | 17.3k | void write_number(T data) { | 64 | 17.3k | fmt::memory_buffer buffer; | 65 | 17.3k | fmt::format_to(buffer, "{}", data); | 66 | 17.3k | write(buffer.data(), buffer.size()); | 67 | 17.3k | } |
|
68 | | |
69 | | // Write a variable-length unsigned integer to the buffer |
70 | | // maybe it's better not to use this |
71 | 3.56k | void write_var_uint(UInt64 x) { |
72 | 3.56k | char bytes[9]; |
73 | 3.56k | uint8_t i = 0; |
74 | 4.78k | while (i < 9) { |
75 | 4.78k | uint8_t byte = x & 0x7F; |
76 | 4.78k | if (x > 0x7F) { |
77 | 1.22k | byte |= 0x80; |
78 | 1.22k | } |
79 | | |
80 | 4.78k | bytes[i++] = byte; |
81 | | |
82 | 4.78k | x >>= 7; |
83 | 4.78k | if (!x) { |
84 | 3.56k | break; |
85 | 3.56k | } |
86 | 4.78k | } |
87 | 3.56k | write((char*)&i, 1); |
88 | 3.56k | write(bytes, i); |
89 | 3.56k | } |
90 | | |
91 | | template <typename Type> |
92 | 3.76k | void write_binary(const Type& x) { |
93 | 3.76k | static_assert(std::is_standard_layout_v<Type>); |
94 | 3.76k | write(reinterpret_cast<const char*>(&x), sizeof(x)); |
95 | 3.76k | } _ZN5doris14BufferWritable12write_binaryIdEEvRKT_ Line | Count | Source | 92 | 332 | void write_binary(const Type& x) { | 93 | 332 | static_assert(std::is_standard_layout_v<Type>); | 94 | 332 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 332 | } |
_ZN5doris14BufferWritable12write_binaryIlEEvRKT_ Line | Count | Source | 92 | 183 | void write_binary(const Type& x) { | 93 | 183 | static_assert(std::is_standard_layout_v<Type>); | 94 | 183 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 183 | } |
_ZN5doris14BufferWritable12write_binaryIiEEvRKT_ Line | Count | Source | 92 | 278 | void write_binary(const Type& x) { | 93 | 278 | static_assert(std::is_standard_layout_v<Type>); | 94 | 278 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 278 | } |
_ZN5doris14BufferWritable12write_binaryIbEEvRKT_ Line | Count | Source | 92 | 7 | void write_binary(const Type& x) { | 93 | 7 | static_assert(std::is_standard_layout_v<Type>); | 94 | 7 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 7 | } |
_ZN5doris14BufferWritable12write_binaryImEEvRKT_ Line | Count | Source | 92 | 2.22k | void write_binary(const Type& x) { | 93 | 2.22k | static_assert(std::is_standard_layout_v<Type>); | 94 | 2.22k | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 2.22k | } |
_ZN5doris14BufferWritable12write_binaryIaEEvRKT_ Line | Count | Source | 92 | 100 | void write_binary(const Type& x) { | 93 | 100 | static_assert(std::is_standard_layout_v<Type>); | 94 | 100 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 100 | } |
_ZN5doris14BufferWritable12write_binaryIsEEvRKT_ Line | Count | Source | 92 | 100 | void write_binary(const Type& x) { | 93 | 100 | static_assert(std::is_standard_layout_v<Type>); | 94 | 100 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 100 | } |
_ZN5doris14BufferWritable12write_binaryInEEvRKT_ Line | Count | Source | 92 | 130 | void write_binary(const Type& x) { | 93 | 130 | static_assert(std::is_standard_layout_v<Type>); | 94 | 130 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 130 | } |
_ZN5doris14BufferWritable12write_binaryIhEEvRKT_ Line | Count | Source | 92 | 81 | void write_binary(const Type& x) { | 93 | 81 | static_assert(std::is_standard_layout_v<Type>); | 94 | 81 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 81 | } |
_ZN5doris14BufferWritable12write_binaryIfEEvRKT_ Line | Count | Source | 92 | 100 | void write_binary(const Type& x) { | 93 | 100 | static_assert(std::is_standard_layout_v<Type>); | 94 | 100 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 100 | } |
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIiEEEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIlEEEEvRKT_ _ZN5doris14BufferWritable12write_binaryINS_14DecimalV2ValueEEEvRKT_ Line | Count | Source | 92 | 11 | void write_binary(const Type& x) { | 93 | 11 | static_assert(std::is_standard_layout_v<Type>); | 94 | 11 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 11 | } |
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_12Decimal128V3EEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIN4wide7integerILm256EiEEEEEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16VecDateTimeValueEEEvRKT_ _ZN5doris14BufferWritable12write_binaryINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvRKT_ Line | Count | Source | 92 | 100 | void write_binary(const Type& x) { | 93 | 100 | static_assert(std::is_standard_layout_v<Type>); | 94 | 100 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 100 | } |
_ZN5doris14BufferWritable12write_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRKT_ Line | Count | Source | 92 | 116 | void write_binary(const Type& x) { | 93 | 116 | static_assert(std::is_standard_layout_v<Type>); | 94 | 116 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 116 | } |
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16TimestampTzValueEEEvRKT_ _ZN5doris14BufferWritable12write_binaryIjEEvRKT_ Line | Count | Source | 92 | 6 | void write_binary(const Type& x) { | 93 | 6 | static_assert(std::is_standard_layout_v<Type>); | 94 | 6 | write(reinterpret_cast<const char*>(&x), sizeof(x)); | 95 | 6 | } |
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryIoEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_10VarMomentsIdLm4EEEEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_10VarMomentsIdLm3EEEEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryIN4wide7integerILm128EjEEEEvRKT_ Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalInEEEEvRKT_ |
96 | | |
97 | | template <typename Type> |
98 | | requires(std::is_same_v<Type, String> || std::is_same_v<Type, PaddedPODArray<UInt8>>) |
99 | 3.28k | void write_binary(const Type& s) { |
100 | 3.28k | write_var_uint(s.size()); |
101 | 3.28k | write(reinterpret_cast<const char*>(s.data()), s.size()); |
102 | 3.28k | } _ZN5doris14BufferWritable12write_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRKS8_ Line | Count | Source | 99 | 3.28k | void write_binary(const Type& s) { | 100 | 3.28k | write_var_uint(s.size()); | 101 | 3.28k | write(reinterpret_cast<const char*>(s.data()), s.size()); | 102 | 3.28k | } |
_ZN5doris14BufferWritable12write_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRKS7_ Line | Count | Source | 99 | 1 | void write_binary(const Type& s) { | 100 | 1 | write_var_uint(s.size()); | 101 | 1 | write(reinterpret_cast<const char*>(s.data()), s.size()); | 102 | 1 | } |
|
103 | | |
104 | 113 | void write_binary(const StringRef& s) { |
105 | 113 | write_var_uint(s.size); |
106 | 113 | write(s.data, s.size); |
107 | 113 | } |
108 | | |
109 | 171k | void write_char(char x) { write(x); } |
110 | | |
111 | | // Writes a C-string without creating a temporary object. If the string is a literal, then `strlen` is executed at the compilation stage. |
112 | | // Use when the string is a literal. |
113 | 21.0k | void write_c_string(const char* s) { write(s, strlen(s)); } |
114 | | |
115 | | /** |
116 | | * @brief Write a string in JSON format, escaping special characters. |
117 | | * |
118 | | * This function takes a string (as a char pointer and size) and writes it to the buffer |
119 | | * as a JSON string literal. This involves: |
120 | | * 1. Enclosing the string in double quotes ("..."). |
121 | | * 2. Escaping control characters (e.g., \n, \t, \b). |
122 | | * 3. Escaping JSON-specific characters like backslash (\\) and double-quote ("). |
123 | | * 4. Escaping ASCII control characters (0x00-0x1F) using `\uXXXX` notation. |
124 | | * 5. Escaping Unicode line separators U+2028 and U+2029 for JavaScript compatibility. |
125 | | * |
126 | | * @param s A pointer to the character data of the string. |
127 | | * @param size The number of bytes in the string. |
128 | | * |
129 | | * @example |
130 | | * // String to be written: |
131 | | * // Hello, "world"! |
132 | | * // (with a newline at the end) |
133 | | * const char* my_str = "Hello, \"world\"!\n"; |
134 | | * size_t my_size = 16; |
135 | | * |
136 | | * // The function will write the following to the buffer: |
137 | | * // "Hello, \"world\"!\\n" |
138 | | */ |
139 | 21.0k | void write_json_string(const char* s, size_t size) { |
140 | 21.0k | write_char('"'); |
141 | 21.0k | const char* begin = s; |
142 | 21.0k | const char* end = s + size; |
143 | 114k | for (const char* it = begin; it != end; ++it) { |
144 | 93.2k | switch (*it) { |
145 | 1 | case '\b': |
146 | 1 | write_char('\\'); |
147 | 1 | write_char('b'); |
148 | 1 | break; |
149 | 1 | case '\f': |
150 | 1 | write_char('\\'); |
151 | 1 | write_char('f'); |
152 | 1 | break; |
153 | 1 | case '\n': |
154 | 1 | write_char('\\'); |
155 | 1 | write_char('n'); |
156 | 1 | break; |
157 | 1 | case '\r': |
158 | 1 | write_char('\\'); |
159 | 1 | write_char('r'); |
160 | 1 | break; |
161 | 1 | case '\t': |
162 | 1 | write_char('\\'); |
163 | 1 | write_char('t'); |
164 | 1 | break; |
165 | 1 | case '\\': |
166 | 1 | write_char('\\'); |
167 | 1 | write_char('\\'); |
168 | 1 | break; |
169 | 1 | case '/': |
170 | 1 | write_char('/'); |
171 | 1 | break; |
172 | 1 | case '"': |
173 | 1 | write_char('\\'); |
174 | 1 | write_char('"'); |
175 | 1 | break; |
176 | 93.2k | default: |
177 | 93.2k | UInt8 c = *it; |
178 | 93.2k | if (c <= 0x1F) { |
179 | | /// Escaping of ASCII control characters. |
180 | | |
181 | 2 | UInt8 higher_half = c >> 4; |
182 | 2 | UInt8 lower_half = c & 0xF; |
183 | | |
184 | 2 | write_c_string("\\u00"); |
185 | 2 | write_char('0' + higher_half); |
186 | | |
187 | 2 | if (lower_half <= 9) { |
188 | 1 | write_char('0' + lower_half); |
189 | 1 | } else { |
190 | 1 | write_char('A' + lower_half - 10); |
191 | 1 | } |
192 | 93.2k | } else if (end - it >= 3 && it[0] == '\xE2' && it[1] == '\x80' && |
193 | 93.2k | (it[2] == '\xA8' || it[2] == '\xA9')) { |
194 | | /// This is for compatibility with JavaScript, because unescaped line separators are prohibited in string literals, |
195 | | /// and these code points are alternative line separators. |
196 | | |
197 | 2 | if (it[2] == '\xA8') { |
198 | 1 | write_c_string("\\u2028"); |
199 | 1 | } |
200 | 2 | if (it[2] == '\xA9') { |
201 | 1 | write_c_string("\\u2029"); |
202 | 1 | } |
203 | | |
204 | | /// Byte sequence is 3 bytes long. We have additional two bytes to skip. |
205 | 2 | it += 2; |
206 | 93.2k | } else { |
207 | 93.2k | write_char(*it); |
208 | 93.2k | } |
209 | 93.2k | } |
210 | 93.2k | } |
211 | 21.0k | write_char('"'); |
212 | 21.0k | } |
213 | | |
214 | 0 | void write_json_string(const StringRef& s) { write_json_string(s.data, s.size); } |
215 | 2 | void write_json_string(const std::string& s) { write_json_string(s.data(), s.size()); } |
216 | 21.0k | void write_json_string(std::string_view s) { write_json_string(s.data(), s.size()); } |
217 | | |
218 | | private: |
219 | | ColumnString::Chars& _data; |
220 | | ColumnString::Offsets& _offsets; |
221 | | size_t _now_offset = 0; |
222 | | }; |
223 | | |
224 | | using VectorBufferWriter = BufferWritable; |
225 | | using BufferWriter = BufferWritable; |
226 | | |
227 | | // There is consumption of the buffer in the read method. |
228 | | class BufferReadable { |
229 | | public: |
230 | 8 | explicit BufferReadable(StringRef& ref) : _data(ref.data) {} |
231 | 2.47k | explicit BufferReadable(StringRef&& ref) : _data(ref.data) {} |
232 | | ~BufferReadable() = default; |
233 | | |
234 | 5.81k | StringRef read(size_t len) { |
235 | 5.81k | StringRef ref(_data, len); |
236 | 5.81k | _data += len; |
237 | 5.81k | return ref; |
238 | 5.81k | } |
239 | | |
240 | 4.70k | void read(char* data, size_t len) { |
241 | 4.70k | memcpy(data, _data, len); |
242 | 4.70k | _data += len; |
243 | 4.70k | } |
244 | | |
245 | 0 | const char* data() { return _data; } |
246 | | |
247 | 0 | void add_offset(size_t len) { _data += len; } |
248 | | |
249 | 3.54k | void read_var_uint(UInt64& x) { |
250 | 3.54k | x = 0; |
251 | | // get length from first byte firstly |
252 | 3.54k | uint8_t len = 0; |
253 | 3.54k | read((char*)&len, 1); |
254 | 3.54k | auto ref = read(len); |
255 | | // read data and set it to x per byte. |
256 | 3.54k | const char* bytes = ref.data; |
257 | 4.77k | for (size_t i = 0; i < 9; ++i) { |
258 | 4.77k | UInt64 byte = bytes[i]; |
259 | 4.77k | x |= (byte & 0x7F) << (7 * i); |
260 | | |
261 | 4.77k | if (!(byte & 0x80)) { |
262 | 3.54k | return; |
263 | 3.54k | } |
264 | 4.77k | } |
265 | 3.54k | } |
266 | | |
267 | | template <typename Type> |
268 | 3.71k | void read_binary(Type& x) { |
269 | 3.71k | static_assert(std::is_standard_layout_v<Type>); |
270 | 3.71k | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); |
271 | 3.71k | _data += sizeof(x); |
272 | 3.71k | } _ZN5doris14BufferReadable11read_binaryIdEEvRT_ Line | Count | Source | 268 | 321 | void read_binary(Type& x) { | 269 | 321 | static_assert(std::is_standard_layout_v<Type>); | 270 | 321 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 321 | _data += sizeof(x); | 272 | 321 | } |
_ZN5doris14BufferReadable11read_binaryIlEEvRT_ Line | Count | Source | 268 | 169 | void read_binary(Type& x) { | 269 | 169 | static_assert(std::is_standard_layout_v<Type>); | 270 | 169 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 169 | _data += sizeof(x); | 272 | 169 | } |
_ZN5doris14BufferReadable11read_binaryIiEEvRT_ Line | Count | Source | 268 | 278 | void read_binary(Type& x) { | 269 | 278 | static_assert(std::is_standard_layout_v<Type>); | 270 | 278 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 278 | _data += sizeof(x); | 272 | 278 | } |
_ZN5doris14BufferReadable11read_binaryIbEEvRT_ Line | Count | Source | 268 | 7 | void read_binary(Type& x) { | 269 | 7 | static_assert(std::is_standard_layout_v<Type>); | 270 | 7 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 7 | _data += sizeof(x); | 272 | 7 | } |
_ZN5doris14BufferReadable11read_binaryImEEvRT_ Line | Count | Source | 268 | 2.21k | void read_binary(Type& x) { | 269 | 2.21k | static_assert(std::is_standard_layout_v<Type>); | 270 | 2.21k | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 2.21k | _data += sizeof(x); | 272 | 2.21k | } |
_ZN5doris14BufferReadable11read_binaryIaEEvRT_ Line | Count | Source | 268 | 100 | void read_binary(Type& x) { | 269 | 100 | static_assert(std::is_standard_layout_v<Type>); | 270 | 100 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 100 | _data += sizeof(x); | 272 | 100 | } |
_ZN5doris14BufferReadable11read_binaryIsEEvRT_ Line | Count | Source | 268 | 100 | void read_binary(Type& x) { | 269 | 100 | static_assert(std::is_standard_layout_v<Type>); | 270 | 100 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 100 | _data += sizeof(x); | 272 | 100 | } |
_ZN5doris14BufferReadable11read_binaryInEEvRT_ Line | Count | Source | 268 | 130 | void read_binary(Type& x) { | 269 | 130 | static_assert(std::is_standard_layout_v<Type>); | 270 | 130 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 130 | _data += sizeof(x); | 272 | 130 | } |
_ZN5doris14BufferReadable11read_binaryIhEEvRT_ Line | Count | Source | 268 | 67 | void read_binary(Type& x) { | 269 | 67 | static_assert(std::is_standard_layout_v<Type>); | 270 | 67 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 67 | _data += sizeof(x); | 272 | 67 | } |
_ZN5doris14BufferReadable11read_binaryIfEEvRT_ Line | Count | Source | 268 | 100 | void read_binary(Type& x) { | 269 | 100 | static_assert(std::is_standard_layout_v<Type>); | 270 | 100 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 100 | _data += sizeof(x); | 272 | 100 | } |
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIiEEEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIlEEEEvRT_ _ZN5doris14BufferReadable11read_binaryINS_14DecimalV2ValueEEEvRT_ Line | Count | Source | 268 | 11 | void read_binary(Type& x) { | 269 | 11 | static_assert(std::is_standard_layout_v<Type>); | 270 | 11 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 11 | _data += sizeof(x); | 272 | 11 | } |
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_12Decimal128V3EEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIN4wide7integerILm256EiEEEEEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16VecDateTimeValueEEEvRT_ _ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvRT_ Line | Count | Source | 268 | 100 | void read_binary(Type& x) { | 269 | 100 | static_assert(std::is_standard_layout_v<Type>); | 270 | 100 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 100 | _data += sizeof(x); | 272 | 100 | } |
_ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRT_ Line | Count | Source | 268 | 116 | void read_binary(Type& x) { | 269 | 116 | static_assert(std::is_standard_layout_v<Type>); | 270 | 116 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 116 | _data += sizeof(x); | 272 | 116 | } |
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16TimestampTzValueEEEvRT_ _ZN5doris14BufferReadable11read_binaryIjEEvRT_ Line | Count | Source | 268 | 6 | void read_binary(Type& x) { | 269 | 6 | static_assert(std::is_standard_layout_v<Type>); | 270 | 6 | memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data); | 271 | 6 | _data += sizeof(x); | 272 | 6 | } |
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryIoEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_10VarMomentsIdLm4EEEEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_10VarMomentsIdLm3EEEEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryIN4wide7integerILm128EjEEEEvRT_ Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalInEEEEvRT_ |
273 | | |
274 | | template <typename Type> |
275 | | requires(std::is_same_v<Type, String> || std::is_same_v<Type, PaddedPODArray<UInt8>>) |
276 | 1.12k | void read_binary(Type& s) { |
277 | 1.12k | UInt64 size = 0; |
278 | 1.12k | read_var_uint(size); |
279 | | |
280 | 1.12k | if (size > DEFAULT_MAX_STRING_SIZE) { |
281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, |
282 | 0 | "Too large string size." |
283 | 0 | " size: {}, max: {}", |
284 | 0 | size, DEFAULT_MAX_STRING_SIZE); |
285 | 0 | } |
286 | | |
287 | 1.12k | s.resize(size); |
288 | 1.12k | read((char*)s.data(), size); |
289 | 1.12k | } _ZN5doris14BufferReadable11read_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRS8_ Line | Count | Source | 276 | 1.12k | void read_binary(Type& s) { | 277 | 1.12k | UInt64 size = 0; | 278 | 1.12k | read_var_uint(size); | 279 | | | 280 | 1.12k | if (size > DEFAULT_MAX_STRING_SIZE) { | 281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, | 282 | 0 | "Too large string size." | 283 | 0 | " size: {}, max: {}", | 284 | 0 | size, DEFAULT_MAX_STRING_SIZE); | 285 | 0 | } | 286 | | | 287 | 1.12k | s.resize(size); | 288 | 1.12k | read((char*)s.data(), size); | 289 | 1.12k | } |
_ZN5doris14BufferReadable11read_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRS7_ Line | Count | Source | 276 | 1 | void read_binary(Type& s) { | 277 | 1 | UInt64 size = 0; | 278 | 1 | read_var_uint(size); | 279 | | | 280 | 1 | if (size > DEFAULT_MAX_STRING_SIZE) { | 281 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, | 282 | 0 | "Too large string size." | 283 | 0 | " size: {}, max: {}", | 284 | 0 | size, DEFAULT_MAX_STRING_SIZE); | 285 | 0 | } | 286 | | | 287 | 1 | s.resize(size); | 288 | 1 | read((char*)s.data(), size); | 289 | 1 | } |
|
290 | | |
291 | | // Note that the StringRef in this function is just a reference, it should be copied outside |
292 | 2.26k | void read_binary(StringRef& s) { |
293 | 2.26k | UInt64 size = 0; |
294 | 2.26k | read_var_uint(size); |
295 | | |
296 | 2.26k | if (size > DEFAULT_MAX_STRING_SIZE) { |
297 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, |
298 | 0 | "Too large string size. " |
299 | 0 | " size: {}, max: {}", |
300 | 0 | size, DEFAULT_MAX_STRING_SIZE); |
301 | 0 | } |
302 | | |
303 | 2.26k | s = read(size); |
304 | 2.26k | } |
305 | | |
306 | | ///TODO: Currently this function is only called in one place, we might need to convert all read_binary(StringRef) to this style? Or directly use read_binary(String) |
307 | 1 | StringRef read_binary_into(Arena& arena) { |
308 | 1 | UInt64 size = 0; |
309 | 1 | read_var_uint(size); |
310 | | |
311 | 1 | char* data = arena.alloc(size); |
312 | 1 | read(data, size); |
313 | | |
314 | 1 | return {data, size}; |
315 | 1 | } |
316 | | |
317 | | private: |
318 | | const char* _data; |
319 | | }; |
320 | | |
321 | | using VectorBufferReader = BufferReadable; |
322 | | using BufferReader = BufferReadable; |
323 | | } // namespace doris |