Coverage Report

Created: 2026-09-29 12:58

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
241k
            : _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
802k
    void write(char c) {
44
802k
        const char* p = &c;
45
802k
        _data.insert(p, p + 1);
46
802k
        _now_offset += 1;
47
802k
    }
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
38
    char* data() { return reinterpret_cast<char*>(_data.data() + _now_offset + _offsets.back()); }
57
58
18
    void add_offset(size_t len) { _now_offset += len; }
59
60
38
    void resize(size_t size) { _data.resize(size + _now_offset + _offsets.back()); }
61
62
    template <typename T>
63
235k
    void write_number(T data) {
64
235k
        fmt::memory_buffer buffer;
65
235k
        fmt::format_to(buffer, "{}", data);
66
235k
        write(buffer.data(), buffer.size());
67
235k
    }
_ZN5doris14BufferWritable12write_numberIiEEvT_
Line
Count
Source
63
42.5k
    void write_number(T data) {
64
42.5k
        fmt::memory_buffer buffer;
65
42.5k
        fmt::format_to(buffer, "{}", data);
66
42.5k
        write(buffer.data(), buffer.size());
67
42.5k
    }
_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
57.8k
    void write_number(T data) {
64
57.8k
        fmt::memory_buffer buffer;
65
57.8k
        fmt::format_to(buffer, "{}", data);
66
57.8k
        write(buffer.data(), buffer.size());
67
57.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
13.0k
    void write_var_uint(UInt64 x) {
72
13.0k
        char bytes[9];
73
13.0k
        uint8_t i = 0;
74
16.8k
        while (i < 9) {
75
16.8k
            uint8_t byte = x & 0x7F;
76
16.8k
            if (x > 0x7F) {
77
3.86k
                byte |= 0x80;
78
3.86k
            }
79
80
16.8k
            bytes[i++] = byte;
81
82
16.8k
            x >>= 7;
83
16.8k
            if (!x) {
84
13.0k
                break;
85
13.0k
            }
86
16.8k
        }
87
13.0k
        write((char*)&i, 1);
88
13.0k
        write(bytes, i);
89
13.0k
    }
90
91
    template <typename Type>
92
18.4k
    void write_binary(const Type& x) {
93
18.4k
        static_assert(std::is_standard_layout_v<Type>);
94
18.4k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
18.4k
    }
_ZN5doris14BufferWritable12write_binaryIdEEvRKT_
Line
Count
Source
92
2.18k
    void write_binary(const Type& x) {
93
2.18k
        static_assert(std::is_standard_layout_v<Type>);
94
2.18k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
2.18k
    }
_ZN5doris14BufferWritable12write_binaryIlEEvRKT_
Line
Count
Source
92
434
    void write_binary(const Type& x) {
93
434
        static_assert(std::is_standard_layout_v<Type>);
94
434
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
434
    }
_ZN5doris14BufferWritable12write_binaryIiEEvRKT_
Line
Count
Source
92
2.29k
    void write_binary(const Type& x) {
93
2.29k
        static_assert(std::is_standard_layout_v<Type>);
94
2.29k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
2.29k
    }
_ZN5doris14BufferWritable12write_binaryIbEEvRKT_
Line
Count
Source
92
2.36k
    void write_binary(const Type& x) {
93
2.36k
        static_assert(std::is_standard_layout_v<Type>);
94
2.36k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
2.36k
    }
_ZN5doris14BufferWritable12write_binaryIfEEvRKT_
Line
Count
Source
92
616
    void write_binary(const Type& x) {
93
616
        static_assert(std::is_standard_layout_v<Type>);
94
616
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
616
    }
_ZN5doris14BufferWritable12write_binaryImEEvRKT_
Line
Count
Source
92
8.57k
    void write_binary(const Type& x) {
93
8.57k
        static_assert(std::is_standard_layout_v<Type>);
94
8.57k
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
8.57k
    }
_ZN5doris14BufferWritable12write_binaryIaEEvRKT_
Line
Count
Source
92
206
    void write_binary(const Type& x) {
93
206
        static_assert(std::is_standard_layout_v<Type>);
94
206
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
206
    }
_ZN5doris14BufferWritable12write_binaryIsEEvRKT_
Line
Count
Source
92
206
    void write_binary(const Type& x) {
93
206
        static_assert(std::is_standard_layout_v<Type>);
94
206
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
206
    }
_ZN5doris14BufferWritable12write_binaryInEEvRKT_
Line
Count
Source
92
268
    void write_binary(const Type& x) {
93
268
        static_assert(std::is_standard_layout_v<Type>);
94
268
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
268
    }
_ZN5doris14BufferWritable12write_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRKT_
Line
Count
Source
92
310
    void write_binary(const Type& x) {
93
310
        static_assert(std::is_standard_layout_v<Type>);
94
310
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
310
    }
_ZN5doris14BufferWritable12write_binaryIjEEvRKT_
Line
Count
Source
92
154
    void write_binary(const Type& x) {
93
154
        static_assert(std::is_standard_layout_v<Type>);
94
154
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
154
    }
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16TimeStampNsValueEEEvRKT_
_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
    }
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_16TimestampTzValueEEEvRKT_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_10VarMomentsIdLm3EEEEEvRKT_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryINS_10VarMomentsIdLm4EEEEEvRKT_
_ZN5doris14BufferWritable12write_binaryIhEEvRKT_
Line
Count
Source
92
594
    void write_binary(const Type& x) {
93
594
        static_assert(std::is_standard_layout_v<Type>);
94
594
        write(reinterpret_cast<const char*>(&x), sizeof(x));
95
594
    }
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_
Unexecuted instantiation: _ZN5doris14BufferWritable12write_binaryIoEEvRKT_
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
8.09k
    void write_binary(const Type& s) {
100
8.09k
        write_var_uint(s.size());
101
8.09k
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
8.09k
    }
_ZN5doris14BufferWritable12write_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRKS8_
Line
Count
Source
99
7.99k
    void write_binary(const Type& s) {
100
7.99k
        write_var_uint(s.size());
101
7.99k
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
7.99k
    }
_ZN5doris14BufferWritable12write_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRKS7_
Line
Count
Source
99
104
    void write_binary(const Type& s) {
100
104
        write_var_uint(s.size());
101
104
        write(reinterpret_cast<const char*>(s.data()), s.size());
102
104
    }
103
104
524
    void write_binary(const StringRef& s) {
105
524
        write_var_uint(s.size);
106
524
        write(s.data, s.size);
107
524
    }
108
109
66
    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
12
    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
6
    void write_json_string(const char* s, size_t size) {
140
6
        write_char('"');
141
6
        const char* begin = s;
142
6
        const char* end = s + size;
143
46
        for (const char* it = begin; it != end; ++it) {
144
40
            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
24
            default:
177
24
                UInt8 c = *it;
178
24
                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
20
                } else if (end - it >= 3 && it[0] == '\xE2' && it[1] == '\x80' &&
193
20
                           (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
16
                } else {
207
16
                    write_char(*it);
208
16
                }
209
40
            }
210
40
        }
211
6
        write_char('"');
212
6
    }
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
0
    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
48
    explicit BufferReadable(StringRef& ref) : _data(ref.data), _end(ref.data + ref.size) {}
231
9.71k
    explicit BufferReadable(StringRef&& ref) : _data(ref.data), _end(ref.data + ref.size) {}
232
    ~BufferReadable() = default;
233
234
19.2k
    StringRef read(size_t len) {
235
19.2k
        StringRef ref(_data, len);
236
19.2k
        _data += len;
237
19.2k
        return ref;
238
19.2k
    }
239
240
19.1k
    void read(char* data, size_t len) {
241
19.1k
        memcpy(data, _data, len);
242
19.1k
        _data += len;
243
19.1k
    }
244
245
18
    const char* data() { return _data; }
246
247
6
    bool has_remaining() const { return _data < _end; }
248
249
16
    void add_offset(size_t len) { _data += len; }
250
251
14.0k
    void read_var_uint(UInt64& x) {
252
14.0k
        x = 0;
253
        // get length from first byte firstly
254
14.0k
        uint8_t len = 0;
255
14.0k
        read((char*)&len, 1);
256
14.0k
        auto ref = read(len);
257
        // read data and set it to x per byte.
258
14.0k
        const char* bytes = ref.data;
259
18.4k
        for (size_t i = 0; i < 9; ++i) {
260
18.4k
            UInt64 byte = bytes[i];
261
18.4k
            x |= (byte & 0x7F) << (7 * i);
262
263
18.4k
            if (!(byte & 0x80)) {
264
14.0k
                return;
265
14.0k
            }
266
18.4k
        }
267
14.0k
    }
268
269
    template <typename Type>
270
18.7k
    void read_binary(Type& x) {
271
18.7k
        static_assert(std::is_standard_layout_v<Type>);
272
18.7k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
18.7k
        _data += sizeof(x);
274
18.7k
    }
_ZN5doris14BufferReadable11read_binaryIdEEvRT_
Line
Count
Source
270
2.37k
    void read_binary(Type& x) {
271
2.37k
        static_assert(std::is_standard_layout_v<Type>);
272
2.37k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
2.37k
        _data += sizeof(x);
274
2.37k
    }
_ZN5doris14BufferReadable11read_binaryIlEEvRT_
Line
Count
Source
270
450
    void read_binary(Type& x) {
271
450
        static_assert(std::is_standard_layout_v<Type>);
272
450
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
450
        _data += sizeof(x);
274
450
    }
_ZN5doris14BufferReadable11read_binaryIiEEvRT_
Line
Count
Source
270
2.53k
    void read_binary(Type& x) {
271
2.53k
        static_assert(std::is_standard_layout_v<Type>);
272
2.53k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
2.53k
        _data += sizeof(x);
274
2.53k
    }
_ZN5doris14BufferReadable11read_binaryIbEEvRT_
Line
Count
Source
270
1.81k
    void read_binary(Type& x) {
271
1.81k
        static_assert(std::is_standard_layout_v<Type>);
272
1.81k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
1.81k
        _data += sizeof(x);
274
1.81k
    }
_ZN5doris14BufferReadable11read_binaryIfEEvRT_
Line
Count
Source
270
672
    void read_binary(Type& x) {
271
672
        static_assert(std::is_standard_layout_v<Type>);
272
672
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
672
        _data += sizeof(x);
274
672
    }
_ZN5doris14BufferReadable11read_binaryImEEvRT_
Line
Count
Source
270
8.95k
    void read_binary(Type& x) {
271
8.95k
        static_assert(std::is_standard_layout_v<Type>);
272
8.95k
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
8.95k
        _data += sizeof(x);
274
8.95k
    }
_ZN5doris14BufferReadable11read_binaryIaEEvRT_
Line
Count
Source
270
218
    void read_binary(Type& x) {
271
218
        static_assert(std::is_standard_layout_v<Type>);
272
218
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
218
        _data += sizeof(x);
274
218
    }
_ZN5doris14BufferReadable11read_binaryIsEEvRT_
Line
Count
Source
270
218
    void read_binary(Type& x) {
271
218
        static_assert(std::is_standard_layout_v<Type>);
272
218
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
218
        _data += sizeof(x);
274
218
    }
_ZN5doris14BufferReadable11read_binaryInEEvRT_
Line
Count
Source
270
280
    void read_binary(Type& x) {
271
280
        static_assert(std::is_standard_layout_v<Type>);
272
280
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
280
        _data += sizeof(x);
274
280
    }
_ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvRT_
Line
Count
Source
270
326
    void read_binary(Type& x) {
271
326
        static_assert(std::is_standard_layout_v<Type>);
272
326
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
326
        _data += sizeof(x);
274
326
    }
_ZN5doris14BufferReadable11read_binaryIjEEvRT_
Line
Count
Source
270
170
    void read_binary(Type& x) {
271
170
        static_assert(std::is_standard_layout_v<Type>);
272
170
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
170
        _data += sizeof(x);
274
170
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16TimeStampNsValueEEEvRT_
_ZN5doris14BufferReadable11read_binaryINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvRT_
Line
Count
Source
270
200
    void read_binary(Type& x) {
271
200
        static_assert(std::is_standard_layout_v<Type>);
272
200
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
200
        _data += sizeof(x);
274
200
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16TimestampTzValueEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_10VarMomentsIdLm3EEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_10VarMomentsIdLm4EEEEEvRT_
_ZN5doris14BufferReadable11read_binaryIhEEvRT_
Line
Count
Source
270
486
    void read_binary(Type& x) {
271
486
        static_assert(std::is_standard_layout_v<Type>);
272
486
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
486
        _data += sizeof(x);
274
486
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIiEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIlEEEEvRT_
_ZN5doris14BufferReadable11read_binaryINS_14DecimalV2ValueEEEvRT_
Line
Count
Source
270
22
    void read_binary(Type& x) {
271
22
        static_assert(std::is_standard_layout_v<Type>);
272
22
        memcpy_fixed<Type>(reinterpret_cast<char*>(&x), _data);
273
22
        _data += sizeof(x);
274
22
    }
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_12Decimal128V3EEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalIN4wide7integerILm256EiEEEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_16VecDateTimeValueEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryIoEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryIN4wide7integerILm128EjEEEEvRT_
Unexecuted instantiation: _ZN5doris14BufferReadable11read_binaryINS_7DecimalInEEEEvRT_
275
276
    template <typename Type>
277
        requires(std::is_same_v<Type, String> || std::is_same_v<Type, PaddedPODArray<UInt8>>)
278
4.06k
    void read_binary(Type& s) {
279
4.06k
        UInt64 size = 0;
280
4.06k
        read_var_uint(size);
281
282
4.06k
        if (size > DEFAULT_MAX_STRING_SIZE) {
283
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
284
0
                                   "Too large string size."
285
0
                                   " size: {}, max: {}",
286
0
                                   size, DEFAULT_MAX_STRING_SIZE);
287
0
        }
288
289
4.06k
        s.resize(size);
290
4.06k
        read((char*)s.data(), size);
291
4.06k
    }
_ZN5doris14BufferReadable11read_binaryINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_S7_Esr3stdE9is_same_vIS8_NS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEEEEvRS8_
Line
Count
Source
278
3.93k
    void read_binary(Type& s) {
279
3.93k
        UInt64 size = 0;
280
3.93k
        read_var_uint(size);
281
282
3.93k
        if (size > DEFAULT_MAX_STRING_SIZE) {
283
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
284
0
                                   "Too large string size."
285
0
                                   " size: {}, max: {}",
286
0
                                   size, DEFAULT_MAX_STRING_SIZE);
287
0
        }
288
289
3.93k
        s.resize(size);
290
3.93k
        read((char*)s.data(), size);
291
3.93k
    }
_ZN5doris14BufferReadable11read_binaryINS_8PODArrayIhLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEQoosr3stdE9is_same_vIT_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEsr3stdE9is_same_vIS7_S6_EEEvRS7_
Line
Count
Source
278
128
    void read_binary(Type& s) {
279
128
        UInt64 size = 0;
280
128
        read_var_uint(size);
281
282
128
        if (size > DEFAULT_MAX_STRING_SIZE) {
283
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
284
0
                                   "Too large string size."
285
0
                                   " size: {}, max: {}",
286
0
                                   size, DEFAULT_MAX_STRING_SIZE);
287
0
        }
288
289
128
        s.resize(size);
290
128
        read((char*)s.data(), size);
291
128
    }
292
293
    // Note that the StringRef in this function is just a reference, it should be copied outside
294
4.89k
    void read_binary(StringRef& s) {
295
4.89k
        UInt64 size = 0;
296
4.89k
        read_var_uint(size);
297
298
4.89k
        if (size > DEFAULT_MAX_STRING_SIZE) {
299
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR,
300
0
                                   "Too large string size. "
301
0
                                   " size: {}, max: {}",
302
0
                                   size, DEFAULT_MAX_STRING_SIZE);
303
0
        }
304
305
4.89k
        s = read(size);
306
4.89k
    }
307
308
    ///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)
309
2
    StringRef read_binary_into(Arena& arena) {
310
2
        UInt64 size = 0;
311
2
        read_var_uint(size);
312
313
2
        char* data = arena.alloc(size);
314
2
        read(data, size);
315
316
2
        return {data, size};
317
2
    }
318
319
private:
320
    const char* _data;
321
    const char* _end;
322
};
323
324
using VectorBufferReader = BufferReadable;
325
using BufferReader = BufferReadable;
326
} // namespace doris