Coverage Report

Created: 2026-07-25 15:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
175k
            : _data(vector.get_chars()), _offsets(vector.get_offsets()) {}
37
38
142M
    void write(const char* data, size_t len) {
39
142M
        _data.insert(data, data + len);
40
142M
        _now_offset += len;
41
142M
    }
42
43
1.24M
    void write(char c) {
44
1.24M
        const char* p = &c;
45
1.24M
        _data.insert(p, p + 1);
46
1.24M
        _now_offset += 1;
47
1.24M
    }
48
49
    // commit may not be called if exception is thrown in writes(e.g. alloc mem failed)
50
131M
    void commit() {
51
131M
        ColumnString::check_chars_length(_offsets.back() + _now_offset, 0);
52
131M
        _offsets.push_back(_offsets.back() + _now_offset);
53
131M
        _now_offset = 0;
54
131M
    }
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
258k
    void write_number(T data) {
64
258k
        fmt::memory_buffer buffer;
65
258k
        fmt::format_to(buffer, "{}", data);
66
258k
        write(buffer.data(), buffer.size());
67
258k
    }
_ZN5doris14BufferWritable12write_numberIiEEvT_
Line
Count
Source
63
42.6k
    void write_number(T data) {
64
42.6k
        fmt::memory_buffer buffer;
65
42.6k
        fmt::format_to(buffer, "{}", data);
66
42.6k
        write(buffer.data(), buffer.size());
67
42.6k
    }
_ZN5doris14BufferWritable12write_numberIdEEvT_
Line
Count
Source
63
338
    void write_number(T data) {
64
338
        fmt::memory_buffer buffer;
65
338
        fmt::format_to(buffer, "{}", data);
66
338
        write(buffer.data(), buffer.size());
67
338
    }
_ZN5doris14BufferWritable12write_numberIhEEvT_
Line
Count
Source
63
7.19k
    void write_number(T data) {
64
7.19k
        fmt::memory_buffer buffer;
65
7.19k
        fmt::format_to(buffer, "{}", data);
66
7.19k
        write(buffer.data(), buffer.size());
67
7.19k
    }
_ZN5doris14BufferWritable12write_numberIaEEvT_
Line
Count
Source
63
49.1k
    void write_number(T data) {
64
49.1k
        fmt::memory_buffer buffer;
65
49.1k
        fmt::format_to(buffer, "{}", data);
66
49.1k
        write(buffer.data(), buffer.size());
67
49.1k
    }
_ZN5doris14BufferWritable12write_numberIsEEvT_
Line
Count
Source
63
44.5k
    void write_number(T data) {
64
44.5k
        fmt::memory_buffer buffer;
65
44.5k
        fmt::format_to(buffer, "{}", data);
66
44.5k
        write(buffer.data(), buffer.size());
67
44.5k
    }
_ZN5doris14BufferWritable12write_numberIlEEvT_
Line
Count
Source
63
80.8k
    void write_number(T data) {
64
80.8k
        fmt::memory_buffer buffer;
65
80.8k
        fmt::format_to(buffer, "{}", data);
66
80.8k
        write(buffer.data(), buffer.size());
67
80.8k
    }
_ZN5doris14BufferWritable12write_numberInEEvT_
Line
Count
Source
63
33.5k
    void write_number(T data) {
64
33.5k
        fmt::memory_buffer buffer;
65
33.5k
        fmt::format_to(buffer, "{}", data);
66
33.5k
        write(buffer.data(), buffer.size());
67
33.5k
    }
68
69
    // Write a variable-length unsigned integer to the buffer
70
    // maybe it's better not to use this
71
7.17k
    void write_var_uint(UInt64 x) {
72
7.17k
        char bytes[9];
73
7.17k
        uint8_t i = 0;
74
9.62k
        while (i < 9) {
75
9.62k
            uint8_t byte = x & 0x7F;
76
9.62k
            if (x > 0x7F) {
77
2.45k
                byte |= 0x80;
78
2.45k
            }
79
80
9.62k
            bytes[i++] = byte;
81
82
9.62k
            x >>= 7;
83
9.62k
            if (!x) {
84
7.17k
                break;
85
7.17k
            }
86
9.62k
        }
87
7.17k
        write((char*)&i, 1);
88
7.17k
        write(bytes, i);
89
7.17k
    }
90
91
    template <typename Type>
92
7.73k
    void write_binary(const Type& x) {
93
7.73k
        static_assert(std::is_standard_layout_v<Type>);
94
7.73k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
7.73k
    }
_ZN5doris14BufferWritable12write_binaryIdEEvRKT_
Line
Count
Source
92
680
    void write_binary(const Type& x) {
93
680
        static_assert(std::is_standard_layout_v<Type>);
94
680
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
680
    }
_ZN5doris14BufferWritable12write_binaryIlEEvRKT_
Line
Count
Source
92
378
    void write_binary(const Type& x) {
93
378
        static_assert(std::is_standard_layout_v<Type>);
94
378
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
378
    }
_ZN5doris14BufferWritable12write_binaryIiEEvRKT_
Line
Count
Source
92
590
    void write_binary(const Type& x) {
93
590
        static_assert(std::is_standard_layout_v<Type>);
94
590
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
590
    }
_ZN5doris14BufferWritable12write_binaryIbEEvRKT_
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
    }
_ZN5doris14BufferWritable12write_binaryImEEvRKT_
Line
Count
Source
92
4.46k
    void write_binary(const Type& x) {
93
4.46k
        static_assert(std::is_standard_layout_v<Type>);
94
4.46k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
4.46k
    }
_ZN5doris14BufferWritable12write_binaryIaEEvRKT_
Line
Count
Source
92
200
    void write_binary(const Type& x) {
93
200
        static_assert(std::is_standard_layout_v<Type>);
94
200
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
200
    }
_ZN5doris14BufferWritable12write_binaryIsEEvRKT_
Line
Count
Source
92
200
    void write_binary(const Type& x) {
93
200
        static_assert(std::is_standard_layout_v<Type>);
94
200
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
200
    }
_ZN5doris14BufferWritable12write_binaryInEEvRKT_
Line
Count
Source
92
260
    void write_binary(const Type& x) {
93
260
        static_assert(std::is_standard_layout_v<Type>);
94
260
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
260
    }
_ZN5doris14BufferWritable12write_binaryIhEEvRKT_
Line
Count
Source
92
162
    void write_binary(const Type& x) {
93
162
        static_assert(std::is_standard_layout_v<Type>);
94
162
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
162
    }
_ZN5doris14BufferWritable12write_binaryIfEEvRKT_
Line
Count
Source
92
200
    void write_binary(const Type& x) {
93
200
        static_assert(std::is_standard_layout_v<Type>);
94
200
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
200
    }
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIiEEEEvRKT_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIlEEEEvRKT_
_ZN5doris14BufferWritable12write_binaryINS_14DecimalV2ValueEEEvRKT_
Line
Count
Source
92
22
    void write_binary(const Type& x) {
93
22
        static_assert(std::is_standard_layout_v<Type>);
94
22
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
22
    }
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_12Decimal128V3EEEvRKT_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_7DecimalIN4wide7integerILm256EiEEEEEEvRKT_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16VecDateTimeValueEEEvRKT_
_ZN5doris14BufferWritable12write_binaryINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvRKT_
Line
Count
Source
92
200
    void write_binary(const Type& x) {
93
200
        static_assert(std::is_standard_layout_v<Type>);
94
200
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
200
    }
_ZN5doris14BufferWritable12write_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRKT_
Line
Count
Source
92
250
    void write_binary(const Type& x) {
93
250
        static_assert(std::is_standard_layout_v<Type>);
94
250
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
250
    }
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16TimestampTzValueEEEvRKT_
_ZN5doris14BufferWritable12write_binaryIjEEvRKT_
Line
Count
Source
92
14
    void write_binary(const Type& x) {
93
14
        static_assert(std::is_standard_layout_v<Type>);
94
14
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
14
    }
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
6.58k
    void write_binary(const Type& s) {
100
6.58k
        write_var_uint(s.size());
101
6.58k
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
6.58k
    }
_ZN5doris14BufferWritable12write_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRKS8_
Line
Count
Source
99
6.57k
    void write_binary(const Type& s) {
100
6.57k
        write_var_uint(s.size());
101
6.57k
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
6.57k
    }
_ZN5doris14BufferWritable12write_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRKS7_
Line
Count
Source
99
2
    void write_binary(const Type& s) {
100
2
        write_var_uint(s.size());
101
2
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
2
    }
103
104
244
    void write_binary(const StringRef& s) {
105
244
        write_var_uint(s.size);
106
244
        write(s.data, s.size);
107
244
    }
108
109
344k
    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
42.2k
    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
42.2k
    void write_json_string(const char* s, size_t size) {
140
42.2k
        write_char('"');
141
42.2k
        const char* begin = s;
142
42.2k
        const char* end = s + size;
143
229k
        for (const char* it = begin; it != end; ++it) {
144
187k
            switch (*it) {
145
2
            case '\b':
146
2
                write_char('\\');
147
2
                write_char('b');
148
2
                break;
149
2
            case '\f':
150
2
                write_char('\\');
151
2
                write_char('f');
152
2
                break;
153
2
            case '\n':
154
2
                write_char('\\');
155
2
                write_char('n');
156
2
                break;
157
2
            case '\r':
158
2
                write_char('\\');
159
2
                write_char('r');
160
2
                break;
161
2
            case '\t':
162
2
                write_char('\\');
163
2
                write_char('t');
164
2
                break;
165
2
            case '\\':
166
2
                write_char('\\');
167
2
                write_char('\\');
168
2
                break;
169
2
            case '/':
170
2
                write_char('/');
171
2
                break;
172
2
            case '"':
173
2
                write_char('\\');
174
2
                write_char('"');
175
2
                break;
176
187k
            default:
177
187k
                UInt8 c = *it;
178
187k
                if (c <= 0x1F) {
179
                    /// Escaping of ASCII control characters.
180
181
4
                    UInt8 higher_half = c >> 4;
182
4
                    UInt8 lower_half = c & 0xF;
183
184
4
                    write_c_string("\\u00");
185
4
                    write_char('0' + higher_half);
186
187
4
                    if (lower_half <= 9) {
188
2
                        write_char('0' + lower_half);
189
2
                    } else {
190
2
                        write_char('A' + lower_half - 10);
191
2
                    }
192
187k
                } else if (end - it >= 3 && it[0] == '\xE2' && it[1] == '\x80' &&
193
187k
                           (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
4
                    if (it[2] == '\xA8') {
198
2
                        write_c_string("\\u2028");
199
2
                    }
200
4
                    if (it[2] == '\xA9') {
201
2
                        write_c_string("\\u2029");
202
2
                    }
203
204
                    /// Byte sequence is 3 bytes long. We have additional two bytes to skip.
205
4
                    it += 2;
206
187k
                } else {
207
187k
                    write_char(*it);
208
187k
                }
209
187k
            }
210
187k
        }
211
42.2k
        write_char('"');
212
42.2k
    }
213
214
0
    void write_json_string(const StringRef& s) { write_json_string(s.data, s.size); }
215
4
    void write_json_string(const std::string& s) { write_json_string(s.data(), s.size()); }
216
42.2k
    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
34
    explicit BufferReadable(StringRef& ref) : _data(ref.data) {}
231
5.03k
    explicit BufferReadable(StringRef&& ref) : _data(ref.data) {}
232
    ~BufferReadable() = default;
233
234
11.7k
    StringRef read(size_t len) {
235
11.7k
        StringRef ref(_data, len);
236
11.7k
        _data += len;
237
11.7k
        return ref;
238
11.7k
    }
239
240
9.49k
    void read(char* data, size_t len) {
241
9.49k
        memcpy(data, _data, len);
242
9.49k
        _data += len;
243
9.49k
    }
244
245
0
    const char* data() { return _data; }
246
247
0
    void add_offset(size_t len) { _data += len; }
248
249
7.14k
    void read_var_uint(UInt64& x) {
250
7.14k
        x = 0;
251
        // get length from first byte firstly
252
7.14k
        uint8_t len = 0;
253
7.14k
        read((char*)&len, 1);
254
7.14k
        auto ref = read(len);
255
        // read data and set it to x per byte.
256
7.14k
        const char* bytes = ref.data;
257
9.59k
        for (size_t i = 0; i < 9; ++i) {
258
9.59k
            UInt64 byte = bytes[i];
259
9.59k
            x |= (byte & 0x7F) << (7 * i);
260
261
9.59k
            if (!(byte & 0x80)) {
262
7.14k
                return;
263
7.14k
            }
264
9.59k
        }
265
7.14k
    }
266
267
    template <typename Type>
268
7.63k
    void read_binary(Type& x) {
269
7.63k
        static_assert(std::is_standard_layout_v<Type>);
270
7.63k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
7.63k
        _data += sizeof(x);
272
7.63k
    }
_ZN5doris14BufferReadable11read_binaryIdEEvRT_
Line
Count
Source
268
658
    void read_binary(Type& x) {
269
658
        static_assert(std::is_standard_layout_v<Type>);
270
658
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
658
        _data += sizeof(x);
272
658
    }
_ZN5doris14BufferReadable11read_binaryIlEEvRT_
Line
Count
Source
268
350
    void read_binary(Type& x) {
269
350
        static_assert(std::is_standard_layout_v<Type>);
270
350
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
350
        _data += sizeof(x);
272
350
    }
_ZN5doris14BufferReadable11read_binaryIiEEvRT_
Line
Count
Source
268
590
    void read_binary(Type& x) {
269
590
        static_assert(std::is_standard_layout_v<Type>);
270
590
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
590
        _data += sizeof(x);
272
590
    }
_ZN5doris14BufferReadable11read_binaryIbEEvRT_
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
    }
_ZN5doris14BufferReadable11read_binaryImEEvRT_
Line
Count
Source
268
4.44k
    void read_binary(Type& x) {
269
4.44k
        static_assert(std::is_standard_layout_v<Type>);
270
4.44k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
4.44k
        _data += sizeof(x);
272
4.44k
    }
_ZN5doris14BufferReadable11read_binaryIaEEvRT_
Line
Count
Source
268
200
    void read_binary(Type& x) {
269
200
        static_assert(std::is_standard_layout_v<Type>);
270
200
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
200
        _data += sizeof(x);
272
200
    }
_ZN5doris14BufferReadable11read_binaryIsEEvRT_
Line
Count
Source
268
200
    void read_binary(Type& x) {
269
200
        static_assert(std::is_standard_layout_v<Type>);
270
200
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
200
        _data += sizeof(x);
272
200
    }
_ZN5doris14BufferReadable11read_binaryInEEvRT_
Line
Count
Source
268
260
    void read_binary(Type& x) {
269
260
        static_assert(std::is_standard_layout_v<Type>);
270
260
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
260
        _data += sizeof(x);
272
260
    }
_ZN5doris14BufferReadable11read_binaryIhEEvRT_
Line
Count
Source
268
134
    void read_binary(Type& x) {
269
134
        static_assert(std::is_standard_layout_v<Type>);
270
134
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
134
        _data += sizeof(x);
272
134
    }
_ZN5doris14BufferReadable11read_binaryIfEEvRT_
Line
Count
Source
268
200
    void read_binary(Type& x) {
269
200
        static_assert(std::is_standard_layout_v<Type>);
270
200
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
200
        _data += sizeof(x);
272
200
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIiEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIlEEEEvRT_
_ZN5doris14BufferReadable11read_binaryINS_14DecimalV2ValueEEEvRT_
Line
Count
Source
268
22
    void read_binary(Type& x) {
269
22
        static_assert(std::is_standard_layout_v<Type>);
270
22
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
22
        _data += sizeof(x);
272
22
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_12Decimal128V3EEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIN4wide7integerILm256EiEEEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16VecDateTimeValueEEEvRT_
_ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvRT_
Line
Count
Source
268
200
    void read_binary(Type& x) {
269
200
        static_assert(std::is_standard_layout_v<Type>);
270
200
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
200
        _data += sizeof(x);
272
200
    }
_ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRT_
Line
Count
Source
268
250
    void read_binary(Type& x) {
269
250
        static_assert(std::is_standard_layout_v<Type>);
270
250
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
250
        _data += sizeof(x);
272
250
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16TimestampTzValueEEEvRT_
_ZN5doris14BufferReadable11read_binaryIjEEvRT_
Line
Count
Source
268
14
    void read_binary(Type& x) {
269
14
        static_assert(std::is_standard_layout_v<Type>);
270
14
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
271
14
        _data += sizeof(x);
272
14
    }
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
2.26k
    void read_binary(Type& s) {
277
2.26k
        UInt64 size = 0;
278
2.26k
        read_var_uint(size);
279
280
2.26k
        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
2.26k
        s.resize(size);
288
2.26k
        read((char*)s.data(), size);
289
2.26k
    }
_ZN5doris14BufferReadable11read_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRS8_
Line
Count
Source
276
2.26k
    void read_binary(Type& s) {
277
2.26k
        UInt64 size = 0;
278
2.26k
        read_var_uint(size);
279
280
2.26k
        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
2.26k
        s.resize(size);
288
2.26k
        read((char*)s.data(), size);
289
2.26k
    }
_ZN5doris14BufferReadable11read_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRS7_
Line
Count
Source
276
2
    void read_binary(Type& s) {
277
2
        UInt64 size = 0;
278
2
        read_var_uint(size);
279
280
2
        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
2
        s.resize(size);
288
2
        read((char*)s.data(), size);
289
2
    }
290
291
    // Note that the StringRef in this function is just a reference, it should be copied outside
292
4.54k
    void read_binary(StringRef& s) {
293
4.54k
        UInt64 size = 0;
294
4.54k
        read_var_uint(size);
295
296
4.54k
        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
4.54k
        s = read(size);
304
4.54k
    }
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
2
    StringRef read_binary_into(Arena& arena) {
308
2
        UInt64 size = 0;
309
2
        read_var_uint(size);
310
311
2
        char* data = arena.alloc(size);
312
2
        read(data, size);
313
314
2
        return {data, size};
315
2
    }
316
317
private:
318
    const char* _data;
319
};
320
321
using VectorBufferReader = BufferReadable;
322
using BufferReader = BufferReadable;
323
} // namespace doris