fuzz coverage

Coverage Report

Created: 2025-06-01 19:34

/Users/eugenesiegel/btc/bitcoin/src/streams.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_STREAMS_H
7
#define BITCOIN_STREAMS_H
8
9
#include <serialize.h>
10
#include <span.h>
11
#include <support/allocators/zeroafterfree.h>
12
#include <util/overflow.h>
13
14
#include <algorithm>
15
#include <assert.h>
16
#include <cstddef>
17
#include <cstdio>
18
#include <ios>
19
#include <limits>
20
#include <optional>
21
#include <stdint.h>
22
#include <string.h>
23
#include <string>
24
#include <utility>
25
#include <vector>
26
27
namespace util {
28
inline void Xor(std::span<std::byte> write, std::span<const std::byte> key, size_t key_offset = 0)
29
20.4M
{
30
20.4M
    if (key.size() == 0) {
31
0
        return;
32
0
    }
33
20.4M
    key_offset %= key.size();
34
35
2.83G
    for (size_t i = 0, j = key_offset; i != write.size(); 
i++2.81G
) {
36
2.81G
        write[i] ^= key[j++];
37
38
        // This potentially acts on very many bytes of data, so it's
39
        // important that we calculate `j`, i.e. the `key` index in this
40
        // way instead of doing a %, which would effectively be a division
41
        // for each byte Xor'd -- much slower than need be.
42
2.81G
        if (j == key.size())
43
351M
            j = 0;
44
2.81G
    }
45
20.4M
}
46
} // namespace util
47
48
/* Minimal stream for overwriting and/or appending to an existing byte vector
49
 *
50
 * The referenced vector will grow as necessary
51
 */
52
class VectorWriter
53
{
54
public:
55
/*
56
 * @param[in]  vchDataIn  Referenced byte vector to overwrite/append
57
 * @param[in]  nPosIn Starting position. Vector index where writes should start. The vector will initially
58
 *                    grow as necessary to max(nPosIn, vec.size()). So to append, use vec.size().
59
*/
60
2.37M
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn) : vchData{vchDataIn}, nPos{nPosIn}
61
2.37M
    {
62
2.37M
        if(nPos > vchData.size())
63
0
            vchData.resize(nPos);
64
2.37M
    }
65
/*
66
 * (other params same as above)
67
 * @param[in]  args  A list of items to serialize starting at nPosIn.
68
*/
69
    template <typename... Args>
70
2.03M
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
2.03M
    {
72
2.03M
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
2.03M
    }
_ZN12VectorWriterC1IJR25CBlockHeaderAndShortTxIDsEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
164k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
164k
    {
72
164k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
164k
    }
_ZN12VectorWriterC1IJR17BlockTransactionsEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
123k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
123k
    {
72
123k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
123k
    }
_ZN12VectorWriterC1IJ13ParamsWrapperI20TransactionSerParamsNSt3__16vectorI6CBlockNS3_9allocatorIS5_EEEEEEEERNS4_IhNS6_IhEEEEmDpOT_
Line
Count
Source
70
79.4k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
79.4k
    {
72
79.4k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
79.4k
    }
_ZN12VectorWriterC1IJRbyEEERNSt3__16vectorIhNS2_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
30.1k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
30.1k
    {
72
30.1k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
30.1k
    }
Unexecuted instantiation: _ZN12VectorWriterC1IJ13ParamsWrapperI20TransactionSerParams25CBlockHeaderAndShortTxIDsEEEERNSt3__16vectorIhNS5_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJ13ParamsWrapperI20TransactionSerParams6CBlockEEEERNSt3__16vectorIhNS5_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJNSt3__14spanISt4byteLm18446744073709551615EEEEEERNS1_6vectorIhNS1_9allocatorIhEEEEmDpOT_
_ZN12VectorWriterC1IJRi7WrapperI19CustomUintFormatterILi8ELb0EER12ServiceFlagsExx13ParamsWrapperIN8CNetAddr9SerParamsE8CServiceExSC_yNSt3__112basic_stringIcNSD_11char_traitsIcEENSD_9allocatorIcEEEEiRbEEERNSD_6vectorIhNSH_IhEEEEmDpOT_
Line
Count
Source
70
149k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
149k
    {
72
149k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
149k
    }
_ZN12VectorWriterC1IJR14CMessageHeaderEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
1.14M
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
1.14M
    {
72
1.14M
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
1.14M
    }
_ZN12VectorWriterC1IJbRKyEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
35.7k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
35.7k
    {
72
35.7k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
35.7k
    }
_ZN12VectorWriterC1IJRK25CBlockHeaderAndShortTxIDsEEERNSt3__16vectorIhNS4_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
81
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
81
    {
72
81
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
81
    }
_ZN12VectorWriterC1IJRNSt3__16vectorI4CInvNS1_9allocatorIS3_EEEEEEERNS2_IhNS4_IhEEEEmDpOT_
Line
Count
Source
70
38.5k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
38.5k
    {
72
38.5k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
38.5k
    }
_ZN12VectorWriterC1IJRKiRyRKxS3_13ParamsWrapperIN8CNetAddr9SerParamsE8CServiceES3_SA_S3_RNSt3__112basic_stringIcNSB_11char_traitsIcEENSB_9allocatorIcEEEES2_RKbEEERNSB_6vectorIhNSF_IhEEEEmDpOT_
Line
Count
Source
70
149k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
149k
    {
72
149k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
149k
    }
_ZN12VectorWriterC1IJRKjRKyEEERNSt3__16vectorIhNS5_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
17.6k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
17.6k
    {
72
17.6k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
17.6k
    }
_ZN12VectorWriterC1IJRKNSt3__15arrayISt4byteLm168EEEEEERNS1_6vectorIhNS1_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
15.3k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
15.3k
    {
72
15.3k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
15.3k
    }
_ZN12VectorWriterC1IJRK13CBlockLocator7uint256EEERNSt3__16vectorIhNS5_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
22.5k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
22.5k
    {
72
22.5k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
22.5k
    }
Unexecuted instantiation: _ZN12VectorWriterC1IJ13ParamsWrapperI20TransactionSerParamsK12CTransactionEEEERNSt3__16vectorIhNS6_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJNSt3__14spanIhLm18446744073709551615EEEEEERNS1_6vectorIhNS1_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJ13ParamsWrapperI20TransactionSerParamsK6CBlockEEEERNSt3__16vectorIhNS6_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJR12CMerkleBlockEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJNSt3__16vectorI12CBlockHeaderNS1_9allocatorIS3_EEEEEEERNS2_IhNS4_IhEEEEmDpOT_
_ZN12VectorWriterC1IJR24BlockTransactionsRequestEEERNSt3__16vectorIhNS3_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
1.23k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
1.23k
    {
72
1.23k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
1.23k
    }
_ZN12VectorWriterC1IJRyEEERNSt3__16vectorIhNS2_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
34.9k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
34.9k
    {
72
34.9k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
34.9k
    }
Unexecuted instantiation: _ZN12VectorWriterC1IJRK11BlockFilterEEERNSt3__16vectorIhNS4_9allocatorIhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJRh7uint256RS2_RNSt3__16vectorIS2_NS4_9allocatorIS2_EEEEEEERNS5_IhNS6_IhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJRh7uint256RNSt3__16vectorIS2_NS3_9allocatorIS2_EEEEEEERNS4_IhNS5_IhEEEEmDpOT_
Unexecuted instantiation: _ZN12VectorWriterC1IJ13ParamsWrapperIN8CAddress9SerParamsENSt3__16vectorIS2_NS4_9allocatorIS2_EEEEEEEERNS5_IhNS6_IhEEEEmDpOT_
_ZN12VectorWriterC1IJRxEEERNSt3__16vectorIhNS2_9allocatorIhEEEEmDpOT_
Line
Count
Source
70
28.6k
    VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71
28.6k
    {
72
28.6k
        ::SerializeMany(*this, std::forward<Args>(args)...);
73
28.6k
    }
74
    void write(std::span<const std::byte> src)
75
31.0M
    {
76
31.0M
        assert(nPos <= vchData.size());
77
31.0M
        size_t nOverwrite = std::min(src.size(), vchData.size() - nPos);
78
31.0M
        if (nOverwrite) {
79
0
            memcpy(vchData.data() + nPos, src.data(), nOverwrite);
80
0
        }
81
31.0M
        if (nOverwrite < src.size()) {
82
31.0M
            vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.data() + src.size()));
83
31.0M
        }
84
31.0M
        nPos += src.size();
85
31.0M
    }
86
    template <typename T>
87
    VectorWriter& operator<<(const T& obj)
88
944k
    {
89
944k
        ::Serialize(*this, obj);
90
944k
        return (*this);
91
944k
    }
Unexecuted instantiation: cluster_linearize.cpp:_ZN12VectorWriterlsI7WrapperIN12_GLOBAL__N_117DepGraphFormatterERKN17cluster_linearize8DepGraphIN13bitset_detail9IntBitSetIjEEEEEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsI7WrapperI15VarIntFormatterIL10VarIntMode1EERKiEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsIhEERS_RKT_
_ZN12VectorWriterlsINSt3__14spanIKhLm32EEEEERS_RKT_
Line
Count
Source
88
944k
    {
89
944k
        ::Serialize(*this, obj);
90
944k
        return (*this);
91
944k
    }
Unexecuted instantiation: _ZN12VectorWriterlsINSt3__13setI7uint256NS1_4lessIS3_EENS1_9allocatorIS3_EEEEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsIA4_hEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsIjEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsINSt3__14spanIKhLm18446744073709551615EEEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsINSt3__16vectorIhNS1_9allocatorIhEEEEEERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsI7uint256EERS_RKT_
Unexecuted instantiation: _ZN12VectorWriterlsIiEERS_RKT_
92
93
private:
94
    std::vector<unsigned char>& vchData;
95
    size_t nPos;
96
};
97
98
/** Minimal stream for reading from an existing byte array by std::span.
99
 */
100
class SpanReader
101
{
102
private:
103
    std::span<const unsigned char> m_data;
104
105
public:
106
    /**
107
     * @param[in]  data Referenced byte vector to overwrite/append
108
     */
109
50.8k
    explicit SpanReader(std::span<const unsigned char> data) : m_data{data} {}
110
111
    template<typename T>
112
    SpanReader& operator>>(T&& obj)
113
50.8k
    {
114
50.8k
        ::Unserialize(*this, obj);
115
50.8k
        return (*this);
116
50.8k
    }
Unexecuted instantiation: cluster_linearize.cpp:_ZN10SpanReaderrsI7WrapperIN12_GLOBAL__N_117DepGraphFormatterERN17cluster_linearize8DepGraphIN13bitset_detail9IntBitSetIjEEEEEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsI7WrapperI15VarIntFormatterIL10VarIntMode1EERiEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIRyEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIRhEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIRNSt3__16vectorIhNS1_9allocatorIhEEEEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIR11XOnlyPubKeyEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIR7uint256EERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsINSt3__14spanISt4byteLm33EEEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsI13ParamsWrapperI20TransactionSerParams19CMutableTransactionEEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIR6CTxOutEERS_OT_
_ZN10SpanReaderrsI13ParamsWrapperI20TransactionSerParams6CBlockEEERS_OT_
Line
Count
Source
113
50.8k
    {
114
50.8k
        ::Unserialize(*this, obj);
115
50.8k
        return (*this);
116
50.8k
    }
Unexecuted instantiation: _ZN10SpanReaderrsIR7CScriptEERS_OT_
Unexecuted instantiation: _ZN10SpanReaderrsIRNSt3__16vectorINS2_IhNS1_9allocatorIhEEEENS3_IS5_EEEEEERS_OT_
117
118
0
    size_t size() const { return m_data.size(); }
119
0
    bool empty() const { return m_data.empty(); }
120
121
    void read(std::span<std::byte> dst)
122
966k
    {
123
966k
        if (dst.size() == 0) {
124
0
            return;
125
0
        }
126
127
        // Read from the beginning of the buffer
128
966k
        if (dst.size() > m_data.size()) {
129
0
            throw std::ios_base::failure("SpanReader::read(): end of data");
130
0
        }
131
966k
        memcpy(dst.data(), m_data.data(), dst.size());
132
966k
        m_data = m_data.subspan(dst.size());
133
966k
    }
134
135
    void ignore(size_t n)
136
0
    {
137
0
        m_data = m_data.subspan(n);
138
0
    }
139
};
140
141
/** Double ended buffer combining vector and stream-like interfaces.
142
 *
143
 * >> and << read and write unformatted data using the above serialization templates.
144
 * Fills with data in linear time; some stringstream implementations take N^2 time.
145
 */
146
class DataStream
147
{
148
protected:
149
    using vector_type = SerializeData;
150
    vector_type vch;
151
    vector_type::size_type m_read_pos{0};
152
153
public:
154
    typedef vector_type::allocator_type   allocator_type;
155
    typedef vector_type::size_type        size_type;
156
    typedef vector_type::difference_type  difference_type;
157
    typedef vector_type::reference        reference;
158
    typedef vector_type::const_reference  const_reference;
159
    typedef vector_type::value_type       value_type;
160
    typedef vector_type::iterator         iterator;
161
    typedef vector_type::const_iterator   const_iterator;
162
    typedef vector_type::reverse_iterator reverse_iterator;
163
164
41.5M
    explicit DataStream() = default;
165
0
    explicit DataStream(std::span<const uint8_t> sp) : DataStream{std::as_bytes(sp)} {}
166
0
    explicit DataStream(std::span<const value_type> sp) : vch(sp.data(), sp.data() + sp.size()) {}
167
168
    std::string str() const
169
0
    {
170
0
        return std::string{UCharCast(data()), UCharCast(data() + size())};
171
0
    }
172
173
174
    //
175
    // Vector subset
176
    //
177
0
    const_iterator begin() const                     { return vch.begin() + m_read_pos; }
178
542k
    iterator begin()                                 { return vch.begin() + m_read_pos; }
179
0
    const_iterator end() const                       { return vch.end(); }
180
271k
    iterator end()                                   { return vch.end(); }
181
41.9M
    size_type size() const                           { return vch.size() - m_read_pos; }
182
366k
    bool empty() const                               { return vch.size() == m_read_pos; }
183
1.40M
    void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); }
184
41.1M
    void reserve(size_type n)                        { vch.reserve(n + m_read_pos); }
185
0
    const_reference operator[](size_type pos) const  { return vch[pos + m_read_pos]; }
186
1.25M
    reference operator[](size_type pos)              { return vch[pos + m_read_pos]; }
187
2.24M
    void clear()                                     { vch.clear(); m_read_pos = 0; }
188
41.3M
    value_type* data()                               { return vch.data() + m_read_pos; }
189
0
    const value_type* data() const                   { return vch.data() + m_read_pos; }
190
191
    inline void Compact()
192
0
    {
193
0
        vch.erase(vch.begin(), vch.begin() + m_read_pos);
194
0
        m_read_pos = 0;
195
0
    }
196
197
    bool Rewind(std::optional<size_type> n = std::nullopt)
198
0
    {
199
0
        // Total rewind if no size is passed
200
0
        if (!n) {
201
0
            m_read_pos = 0;
202
0
            return true;
203
0
        }
204
0
        // Rewind by n characters if the buffer hasn't been compacted yet
205
0
        if (*n > m_read_pos)
206
0
            return false;
207
0
        m_read_pos -= *n;
208
0
        return true;
209
0
    }
210
211
212
    //
213
    // Stream subset
214
    //
215
0
    bool eof() const             { return size() == 0; }
216
0
    int in_avail() const         { return size(); }
217
218
    void read(std::span<value_type> dst)
219
20.1M
    {
220
20.1M
        if (dst.size() == 0) 
return0
;
221
222
        // Read from the beginning of the buffer
223
20.1M
        auto next_read_pos{CheckedAdd(m_read_pos, dst.size())};
224
20.1M
        if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
225
29.1k
            throw std::ios_base::failure("DataStream::read(): end of data");
226
29.1k
        }
227
20.0M
        memcpy(dst.data(), &vch[m_read_pos], dst.size());
228
20.0M
        if (next_read_pos.value() == vch.size()) {
229
1.25M
            m_read_pos = 0;
230
1.25M
            vch.clear();
231
1.25M
            return;
232
1.25M
        }
233
18.8M
        m_read_pos = next_read_pos.value();
234
18.8M
    }
235
236
    void ignore(size_t num_ignore)
237
233k
    {
238
        // Ignore from the beginning of the buffer
239
233k
        auto next_read_pos{CheckedAdd(m_read_pos, num_ignore)};
240
233k
        if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
241
0
            throw std::ios_base::failure("DataStream::ignore(): end of data");
242
0
        }
243
233k
        if (next_read_pos.value() == vch.size()) {
244
0
            m_read_pos = 0;
245
0
            vch.clear();
246
0
            return;
247
0
        }
248
233k
        m_read_pos = next_read_pos.value();
249
233k
    }
250
251
    void write(std::span<const value_type> src)
252
126M
    {
253
        // Write to the end of the buffer
254
126M
        vch.insert(vch.end(), src.begin(), src.end());
255
126M
    }
256
257
    template<typename T>
258
    DataStream& operator<<(const T& obj)
259
83.5M
    {
260
83.5M
        ::Serialize(*this, obj);
261
83.5M
        return (*this);
262
83.5M
    }
Unexecuted instantiation: _ZN10DataStreamlsI7AddrManEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI20AddrManDeterministicEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI11BlockFilterEERS_RKT_
_ZN10DataStreamlsIhEERS_RKT_
Line
Count
Source
259
573k
    {
260
573k
        ::Serialize(*this, obj);
261
573k
        return (*this);
262
573k
    }
_ZN10DataStreamlsI7uint256EERS_RKT_
Line
Count
Source
259
517
    {
260
517
        ::Serialize(*this, obj);
261
517
        return (*this);
262
517
    }
_ZN10DataStreamlsINSt3__14spanIKhLm32EEEEERS_RKT_
Line
Count
Source
259
41.0M
    {
260
41.0M
        ::Serialize(*this, obj);
261
41.0M
        return (*this);
262
41.0M
    }
_ZN10DataStreamlsINSt3__16vectorIhNS1_9allocatorIhEEEEEERS_RKT_
Line
Count
Source
259
319k
    {
260
319k
        ::Serialize(*this, obj);
261
319k
        return (*this);
262
319k
    }
_ZN10DataStreamlsI14CBlockFileInfoEERS_RKT_
Line
Count
Source
259
517
    {
260
517
        ::Serialize(*this, obj);
261
517
        return (*this);
262
517
    }
Unexecuted instantiation: _ZN10DataStreamlsI25CBlockHeaderAndShortTxIDsEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI8CFeeRateEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI12CMerkleBlockEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI9COutPointEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI18CPartialMerkleTreeEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI7CPubKeyEERS_RKT_
_ZN10DataStreamlsINSt3__14spanIKhLm18446744073709551615EEEEERS_RKT_
Line
Count
Source
259
103k
    {
260
103k
        ::Serialize(*this, obj);
261
103k
        return (*this);
262
103k
    }
Unexecuted instantiation: _ZN10DataStreamlsI7CScriptEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI5CTxInEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI11FlatFilePosEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13KeyOriginInfoEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI26PartiallySignedTransactionEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIA5_hEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIA4_hEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIjEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI9PSBTInputEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI10PSBTOutputEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI20PrefilledTransactionEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperI20TransactionSerParams6CBlockEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13CBlockLocatorEERS_RKT_
_ZN10DataStreamlsI12CBlockHeaderEERS_RKT_
Line
Count
Source
259
271k
    {
260
271k
        ::Serialize(*this, obj);
261
271k
        return (*this);
262
271k
    }
Unexecuted instantiation: _ZN10DataStreamlsI7CTxUndoEERS_RKT_
_ZN10DataStreamlsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_RKT_
Line
Count
Source
259
103k
    {
260
103k
        ::Serialize(*this, obj);
261
103k
        return (*this);
262
103k
    }
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14spanIhLm18446744073709551615EEEEERS_RKT_
_ZN10DataStreamlsI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS_RKT_
Line
Count
Source
259
103k
    {
260
103k
        ::Serialize(*this, obj);
261
103k
        return (*this);
262
103k
    }
Unexecuted instantiation: _ZN10DataStreamlsI10CBlockUndoEERS_RKT_
_ZN10DataStreamlsI4CoinEERS_RKT_
Line
Count
Source
259
103k
    {
260
103k
        ::Serialize(*this, obj);
261
103k
        return (*this);
262
103k
    }
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperIN8CNetAddr9SerParamsEKS2_EEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperIN8CNetAddr9SerParamsEK8CServiceEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI14CMessageHeaderEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperIN8CAddress9SerParamsEKS2_EEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI4CInvEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI12CBloomFilterEERS_RKT_
_ZN10DataStreamlsI15CDiskBlockIndexEERS_RKT_
Line
Count
Source
259
104k
    {
260
104k
        ::Serialize(*this, obj);
261
104k
        return (*this);
262
104k
    }
Unexecuted instantiation: _ZN10DataStreamlsI7WrapperI16TxOutCompressionR6CTxOutEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI17BlockTransactionsEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI24BlockTransactionsRequestEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIN4node16SnapshotMetadataEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__15arrayIhLm5EEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsItEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__15arrayIhLm4EEEEERS_RKT_
_ZN10DataStreamlsIyEERS_RKT_
Line
Count
Source
259
271k
    {
260
271k
        ::Serialize(*this, obj);
261
271k
        return (*this);
262
271k
    }
Unexecuted instantiation: _ZN10DataStreamlsI7uint160EERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14spanIKhLm20EEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIxEERS_RKT_
_ZN10DataStreamlsIiEERS_RKT_
Line
Count
Source
259
517
    {
260
517
        ::Serialize(*this, obj);
261
517
        return (*this);
262
517
    }
Unexecuted instantiation: _ZN10DataStreamlsIsEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIaEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIbEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__16vectorIiNS1_9allocatorIiEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI9prevectorILj8EijiEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperI20TransactionSerParams19CMutableTransactionEEERS_RKT_
_ZN10DataStreamlsINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERS_RKT_
Line
Count
Source
259
149k
    {
260
149k
        ::Serialize(*this, obj);
261
149k
        return (*this);
262
149k
    }
Unexecuted instantiation: _ZN10DataStreamlsI7WrapperI22LimitedStringFormatterILm10EERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperI20TransactionSerParamsK12CTransactionEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14spanIKSt4byteLm18446744073709551615EEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES8_EEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE22transaction_identifierILb0EEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIN6wallet9CWalletTxEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperI20TransactionSerParamsKNSt3__110shared_ptrIK12CTransactionEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__13mapINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__16vectorINS1_4pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_EENS7_ISA_EEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE7uint256EEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE7CPubKeyEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIN6wallet12CKeyMetadataEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_6vectorIh16secure_allocatorIhEEE7uint256EEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_6vectorIhNS1_9allocatorIhEEEE7uint256EEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEjEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIN6wallet10CMasterKeyEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE7CScriptEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEhEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS2_I7uint2567CPubKeyEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsIN6wallet16WalletDescriptorEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS2_INS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE7uint256EENS2_IjjEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS2_INS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE7uint256EEjEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS2_I22transaction_identifierILb0EEjEEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsINSt3__14pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS2_IS8_S8_EEEEEERS_RKT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_111DBHeightKeyEEERS_RKT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_19DBHashKeyEEERS_RKT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_15DBValEEERS_RKT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamlsINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEERS_RKT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_111DBHeightKeyEEERS_RKT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_19DBHashKeyEEERS_RKT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_15DBValEEERS_RKT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamlsINSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI10MuHash3072EERS_RKT_
_ZN10DataStreamlsINSt3__14pairIh7uint256EEEERS_RKT_
Line
Count
Source
259
204k
    {
260
204k
        ::Serialize(*this, obj);
261
204k
        return (*this);
262
204k
    }
Unexecuted instantiation: _ZN10DataStreamlsI10CDiskTxPosEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI6CTxOutEERS_RKT_
_ZN10DataStreamlsINSt3__14pairIhiEEEERS_RKT_
Line
Count
Source
259
100k
    {
260
100k
        ::Serialize(*this, obj);
261
100k
        return (*this);
262
100k
    }
_ZN10DataStreamlsINSt3__14pairIhNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEEEERS_RKT_
Line
Count
Source
259
49.9k
    {
260
49.9k
        ::Serialize(*this, obj);
261
49.9k
        return (*this);
262
49.9k
    }
Unexecuted instantiation: _ZN10DataStreamlsINSt3__16vectorI5CCoinNS1_9allocatorIS3_EEEEEERS_RKT_
Unexecuted instantiation: _ZN10DataStreamlsI13ParamsWrapperI20TransactionSerParamsK6CBlockEEERS_RKT_
txdb.cpp:_ZN10DataStreamlsIN12_GLOBAL__N_19CoinEntryEEERS_RKT_
Line
Count
Source
259
40.0M
    {
260
40.0M
        ::Serialize(*this, obj);
261
40.0M
        return (*this);
262
40.0M
    }
_ZN10DataStreamlsINSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEERS_RKT_
Line
Count
Source
259
517
    {
260
517
        ::Serialize(*this, obj);
261
517
        return (*this);
262
517
    }
263
264
    template<typename T>
265
    DataStream& operator>>(T&& obj)
266
2.19M
    {
267
2.19M
        ::Unserialize(*this, obj);
268
2.19M
        return (*this);
269
2.19M
    }
Unexecuted instantiation: _ZN10DataStreamrsIR20AddrManDeterministicEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperI20TransactionSerParams6CBlockEEERS_OT_
_ZN10DataStreamrsIR12CBlockHeaderEERS_OT_
Line
Count
Source
266
42.6k
    {
267
42.6k
        ::Unserialize(*this, obj);
268
42.6k
        return (*this);
269
42.6k
    }
Unexecuted instantiation: _ZN10DataStreamrsIR13CBlockLocatorEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR14CBlockFileInfoEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR11BlockFilterEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRhEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7uint256EERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorIhNS1_9allocatorIhEEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR9COutPointEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperI20TransactionSerParams19CMutableTransactionEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR15CDiskBlockIndexEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR4CoinEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsINSt3__14spanIhLm18446744073709551615EEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperIN8CAddress9SerParamsE8AddrInfoEEERS_OT_
_ZN10DataStreamrsIR25CBlockHeaderAndShortTxIDsEERS_OT_
Line
Count
Source
266
115k
    {
267
115k
        ::Unserialize(*this, obj);
268
115k
        return (*this);
269
115k
    }
Unexecuted instantiation: _ZN10DataStreamrsIR8CFeeRateEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR12CMerkleBlockEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR18CPartialMerkleTreeEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7CPubKeyEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7CScriptEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR5CTxInEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR11FlatFilePosEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR13KeyOriginInfoEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR26PartiallySignedTransactionEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRA5_hEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRA4_hEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRjEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR9PSBTInputEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__13setI7uint256NS1_4lessIS3_EENS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR10PSBTOutputEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR20PrefilledTransactionEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR13ParamsWrapperI20TransactionSerParams6CBlockEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7CTxUndoEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR10CBlockUndoEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperIN8CNetAddr9SerParamsES2_EEERS_OT_
_ZN10DataStreamrsI13ParamsWrapperIN8CNetAddr9SerParamsE8CServiceEEERS_OT_
Line
Count
Source
266
141k
    {
267
141k
        ::Unserialize(*this, obj);
268
141k
        return (*this);
269
141k
    }
_ZN10DataStreamrsIR14CMessageHeaderEERS_OT_
Line
Count
Source
266
711k
    {
267
711k
        ::Unserialize(*this, obj);
268
711k
        return (*this);
269
711k
    }
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperIN8CAddress9SerParamsES2_EEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR4CInvEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR12CBloomFilterEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7WrapperI16TxOutCompressionR6CTxOutEEERS_OT_
_ZN10DataStreamrsIR17BlockTransactionsEERS_OT_
Line
Count
Source
266
94.7k
    {
267
94.7k
        ::Unserialize(*this, obj);
268
94.7k
        return (*this);
269
94.7k
    }
Unexecuted instantiation: _ZN10DataStreamrsIR24BlockTransactionsRequestEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRN4node16SnapshotMetadataEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__15arrayIhLm5EEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRtEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__15arrayIhLm4EEEEERS_OT_
_ZN10DataStreamrsIRyEERS_OT_
Line
Count
Source
266
103k
    {
267
103k
        ::Unserialize(*this, obj);
268
103k
        return (*this);
269
103k
    }
Unexecuted instantiation: _ZN10DataStreamrsIR7uint160EERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI12CBlockHeaderNS1_9allocatorIS3_EEEEEERS_OT_
_ZN10DataStreamrsIRxEERS_OT_
Line
Count
Source
266
141k
    {
267
141k
        ::Unserialize(*this, obj);
268
141k
        return (*this);
269
141k
    }
_ZN10DataStreamrsIRiEERS_OT_
Line
Count
Source
266
233k
    {
267
233k
        ::Unserialize(*this, obj);
268
233k
        return (*this);
269
233k
    }
Unexecuted instantiation: _ZN10DataStreamrsIRsEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRaEERS_OT_
_ZN10DataStreamrsIRbEERS_OT_
Line
Count
Source
266
103k
    {
267
103k
        ::Unserialize(*this, obj);
268
103k
        return (*this);
269
103k
    }
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI5CTxInNS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI6CTxOutNS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorINS2_IhNS1_9allocatorIhEEEENS3_IS5_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR6CTxOutEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR7WrapperI22LimitedStringFormatterILm10EERNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERS_OT_
_ZN10DataStreamrsI13ParamsWrapperIN8CAddress9SerParamsE8CNetAddrEEERS_OT_
Line
Count
Source
266
269k
    {
267
269k
        ::Unserialize(*this, obj);
268
269k
        return (*this);
269
269k
    }
Unexecuted instantiation: _ZN10DataStreamrsIRN6wallet12CKeyMetadataEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRN6wallet16WalletDescriptorEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRN6wallet9CWalletTxEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperI20TransactionSerParamsNSt3__110shared_ptrIK12CTransactionEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI7uint256NS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorIN6wallet9CMerkleTxENS1_9allocatorIS4_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__13mapINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES8_NS1_4lessIS8_EENS6_INS1_4pairIKS8_S8_EEEEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorINS1_4pairINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_EENS7_ISA_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR22transaction_identifierILb0EEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorIh16secure_allocatorIhEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRN6wallet10CMasterKeyEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRN6wallet8CHDChainEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsI7WrapperI19CustomUintFormatterILi1ELb0EERN11AddrManImpl6FormatEEEERS_OT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamrsIRN12_GLOBAL__N_111DBHeightKeyEEERS_OT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamrsIRNSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEERS_OT_
Unexecuted instantiation: blockfilterindex.cpp:_ZN10DataStreamrsIRN12_GLOBAL__N_15DBValEEERS_OT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamrsIRN12_GLOBAL__N_111DBHeightKeyEEERS_OT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamrsIRNSt3__14pairI7uint256N12_GLOBAL__N_15DBValEEEEERS_OT_
Unexecuted instantiation: coinstatsindex.cpp:_ZN10DataStreamrsIRN12_GLOBAL__N_15DBValEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR10MuHash3072EERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIR10CDiskTxPosEERS_OT_
_ZN10DataStreamrsI7WrapperI19CustomUintFormatterILi8ELb0EER12ServiceFlagsEEERS_OT_
Line
Count
Source
266
141k
    {
267
141k
        ::Unserialize(*this, obj);
268
141k
        return (*this);
269
141k
    }
_ZN10DataStreamrsI7WrapperI22LimitedStringFormatterILm256EERNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEEEERS_OT_
Line
Count
Source
266
91.6k
    {
267
91.6k
        ::Unserialize(*this, obj);
268
91.6k
        return (*this);
269
91.6k
    }
Unexecuted instantiation: _ZN10DataStreamrsI13ParamsWrapperIN8CAddress9SerParamsENSt3__16vectorIS2_NS4_9allocatorIS2_EEEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI4CInvNS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__14pairIh7uint256EEEERS_OT_
Unexecuted instantiation: _ZN10DataStreamrsIRNSt3__16vectorI9COutPointNS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: txdb.cpp:_ZN10DataStreamrsIRN12_GLOBAL__N_19CoinEntryEEERS_OT_
270
271
    /**
272
     * XOR the contents of this stream with a certain key.
273
     *
274
     * @param[in] key    The key used to XOR the data in this stream.
275
     */
276
    void Xor(const std::vector<unsigned char>& key)
277
261k
    {
278
261k
        util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key));
279
261k
    }
280
281
    /** Compute total memory usage of this object (own memory + any dynamic memory). */
282
    size_t GetMemoryUsage() const noexcept;
283
};
284
285
template <typename IStream>
286
class BitStreamReader
287
{
288
private:
289
    IStream& m_istream;
290
291
    /// Buffered byte read in from the input stream. A new byte is read into the
292
    /// buffer when m_offset reaches 8.
293
    uint8_t m_buffer{0};
294
295
    /// Number of high order bits in m_buffer already returned by previous
296
    /// Read() calls. The next bit to be returned is at this offset from the
297
    /// most significant bit position.
298
    int m_offset{8};
299
300
public:
301
0
    explicit BitStreamReader(IStream& istream) : m_istream(istream) {}
302
303
    /** Read the specified number of bits from the stream. The data is returned
304
     * in the nbits least significant bits of a 64-bit uint.
305
     */
306
0
    uint64_t Read(int nbits) {
307
0
        if (nbits < 0 || nbits > 64) {
308
0
            throw std::out_of_range("nbits must be between 0 and 64");
309
0
        }
310
311
0
        uint64_t data = 0;
312
0
        while (nbits > 0) {
313
0
            if (m_offset == 8) {
314
0
                m_istream >> m_buffer;
315
0
                m_offset = 0;
316
0
            }
317
318
0
            int bits = std::min(8 - m_offset, nbits);
319
0
            data <<= bits;
320
0
            data |= static_cast<uint8_t>(m_buffer << m_offset) >> (8 - bits);
321
0
            m_offset += bits;
322
0
            nbits -= bits;
323
0
        }
324
0
        return data;
325
0
    }
326
};
327
328
template <typename OStream>
329
class BitStreamWriter
330
{
331
private:
332
    OStream& m_ostream;
333
334
    /// Buffered byte waiting to be written to the output stream. The byte is
335
    /// written buffer when m_offset reaches 8 or Flush() is called.
336
    uint8_t m_buffer{0};
337
338
    /// Number of high order bits in m_buffer already written by previous
339
    /// Write() calls and not yet flushed to the stream. The next bit to be
340
    /// written to is at this offset from the most significant bit position.
341
    int m_offset{0};
342
343
public:
344
0
    explicit BitStreamWriter(OStream& ostream) : m_ostream(ostream) {}
345
346
    ~BitStreamWriter()
347
0
    {
348
0
        Flush();
349
0
    }
350
351
    /** Write the nbits least significant bits of a 64-bit int to the output
352
     * stream. Data is buffered until it completes an octet.
353
     */
354
0
    void Write(uint64_t data, int nbits) {
355
0
        if (nbits < 0 || nbits > 64) {
356
0
            throw std::out_of_range("nbits must be between 0 and 64");
357
0
        }
358
359
0
        while (nbits > 0) {
360
0
            int bits = std::min(8 - m_offset, nbits);
361
0
            m_buffer |= (data << (64 - nbits)) >> (64 - 8 + m_offset);
362
0
            m_offset += bits;
363
0
            nbits -= bits;
364
365
0
            if (m_offset == 8) {
366
0
                Flush();
367
0
            }
368
0
        }
369
0
    }
370
371
    /** Flush any unwritten bits to the output stream, padding with 0's to the
372
     * next byte boundary.
373
     */
374
0
    void Flush() {
375
0
        if (m_offset == 0) {
376
0
            return;
377
0
        }
378
379
0
        m_ostream << m_buffer;
380
0
        m_buffer = 0;
381
0
        m_offset = 0;
382
0
    }
383
};
384
385
/** Non-refcounted RAII wrapper for FILE*
386
 *
387
 * Will automatically close the file when it goes out of scope if not null.
388
 * If you're returning the file pointer, return file.release().
389
 * If you need to close the file early, use file.fclose() instead of fclose(file).
390
 */
391
class AutoFile
392
{
393
protected:
394
    std::FILE* m_file;
395
    std::vector<std::byte> m_xor;
396
    std::optional<int64_t> m_position;
397
398
public:
399
    explicit AutoFile(std::FILE* file, std::vector<std::byte> data_xor={});
400
401
20.1M
    ~AutoFile() { fclose(); }
402
403
    // Disallow copies
404
    AutoFile(const AutoFile&) = delete;
405
    AutoFile& operator=(const AutoFile&) = delete;
406
407
0
    bool feof() const { return std::feof(m_file); }
408
409
    int fclose()
410
20.1M
    {
411
20.1M
        if (auto rel{release()}) return std::fclose(rel);
412
0
        return 0;
413
20.1M
    }
414
415
    /** Get wrapped FILE* with transfer of ownership.
416
     * @note This will invalidate the AutoFile object, and makes it the responsibility of the caller
417
     * of this function to clean up the returned FILE*.
418
     */
419
    std::FILE* release()
420
20.1M
    {
421
20.1M
        std::FILE* ret{m_file};
422
20.1M
        m_file = nullptr;
423
20.1M
        return ret;
424
20.1M
    }
425
426
    /** Return true if the wrapped FILE* is nullptr, false otherwise.
427
     */
428
40.2M
    bool IsNull() const { return m_file == nullptr; }
429
430
    /** Continue with a different XOR key */
431
0
    void SetXor(std::vector<std::byte> data_xor) { m_xor = data_xor; }
432
433
    /** Implementation detail, only used internally. */
434
    std::size_t detail_fread(std::span<std::byte> dst);
435
436
    /** Wrapper around fseek(). Will throw if seeking is not possible. */
437
    void seek(int64_t offset, int origin);
438
439
    /** Find position within the file. Will throw if unknown. */
440
    int64_t tell();
441
442
    /** Wrapper around FileCommit(). */
443
    bool Commit();
444
445
    /** Wrapper around TruncateFile(). */
446
    bool Truncate(unsigned size);
447
448
    //! Write a mutable buffer more efficiently than write(), obfuscating the buffer in-place.
449
    void write_buffer(std::span<std::byte> src);
450
451
    //
452
    // Stream subset
453
    //
454
    void read(std::span<std::byte> dst);
455
    void ignore(size_t nSize);
456
    void write(std::span<const std::byte> src);
457
458
    template <typename T>
459
    AutoFile& operator<<(const T& obj)
460
49.9k
    {
461
49.9k
        ::Serialize(*this, obj);
462
49.9k
        return *this;
463
49.9k
    }
Unexecuted instantiation: _ZN8AutoFilelsIbEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIaEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIhEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIsEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsItEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIiEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIjEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIxEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIyEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__16vectorIhNS1_9allocatorIhEEEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__14spanIhLm18446744073709551615EEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsIN4node16SnapshotMetadataEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__15arrayIhLm5EEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__15arrayIhLm4EEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI7uint256EERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__14spanIKhLm32EEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI22transaction_identifierILb0EEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI4CoinEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__14spanIKhLm18446744073709551615EEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__14spanIKcLm18446744073709551615EEEEERS_RKT_
_ZN8AutoFilelsINSt3__15arrayISt4byteLm8EEEEERS_RKT_
Line
Count
Source
460
49.9k
    {
461
49.9k
        ::Serialize(*this, obj);
462
49.9k
        return *this;
463
49.9k
    }
Unexecuted instantiation: _ZN8AutoFilelsINSt3__16vectorISt4byteNS1_9allocatorIS3_EEEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsI13ParamsWrapperI20TransactionSerParamsK12CTransactionEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__13mapI7uint256xNS1_4lessIS3_EENS1_9allocatorINS1_4pairIKS3_xEEEEEEEERS_RKT_
Unexecuted instantiation: _ZN8AutoFilelsINSt3__13setI7uint256NS1_4lessIS3_EENS1_9allocatorIS3_EEEEEERS_RKT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilelsI7WrapperIN12_GLOBAL__N_122EncodedDoubleFormatterERKdEEERS_RKT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilelsI7WrapperI15VectorFormatterIN12_GLOBAL__N_122EncodedDoubleFormatterEERKNSt3__16vectorIdNS6_9allocatorIdEEEEEEERS_RKT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilelsI7WrapperI15VectorFormatterIS2_IN12_GLOBAL__N_122EncodedDoubleFormatterEEERKNSt3__16vectorINS8_IdNS7_9allocatorIdEEEENS9_ISB_EEEEEEERS_RKT_
464
465
    template <typename T>
466
    AutoFile& operator>>(T&& obj)
467
101k
    {
468
101k
        ::Unserialize(*this, obj);
469
101k
        return *this;
470
101k
    }
Unexecuted instantiation: _ZN8AutoFilersIRbEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRaEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRhEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRsEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRtEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRiEERS_OT_
_ZN8AutoFilersIRjEERS_OT_
Line
Count
Source
467
50.8k
    {
468
50.8k
        ::Unserialize(*this, obj);
469
50.8k
        return *this;
470
50.8k
    }
Unexecuted instantiation: _ZN8AutoFilersIRxEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRyEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__16vectorIhNS1_9allocatorIhEEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN4node16SnapshotMetadataEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__15arrayIhLm5EEEEERS_OT_
_ZN8AutoFilersIRNSt3__15arrayIhLm4EEEEERS_OT_
Line
Count
Source
467
50.8k
    {
468
50.8k
        ::Unserialize(*this, obj);
469
50.8k
        return *this;
470
50.8k
    }
Unexecuted instantiation: _ZN8AutoFilersIR7uint256EERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet8MetaPageEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__15arrayISt4byteLm20EEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRA368_cEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRA12_cEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRA20_hEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRA16_hEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet10PageHeaderEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet11RecordsPageEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet12RecordHeaderEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet10DataRecordEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet14OverflowRecordEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet12InternalPageEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet14InternalRecordEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRN6wallet12OverflowPageEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersI7WrapperI19CustomUintFormatterILi1ELb0EERN11AddrManImpl6FormatEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIR12CBlockHeaderEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersI13ParamsWrapperI20TransactionSerParamsNSt3__110shared_ptrIK12CTransactionEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__15arrayISt4byteLm8EEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__16vectorISt4byteNS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__13mapI7uint256xNS1_4lessIS3_EENS1_9allocatorINS1_4pairIKS3_xEEEEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRNSt3__13setI7uint256NS1_4lessIS3_EENS1_9allocatorIS3_EEEEEERS_OT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilersI7WrapperIN12_GLOBAL__N_122EncodedDoubleFormatterERdEEERS_OT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilersI7WrapperI15VectorFormatterIN12_GLOBAL__N_122EncodedDoubleFormatterEERNSt3__16vectorIdNS6_9allocatorIdEEEEEEERS_OT_
Unexecuted instantiation: fees.cpp:_ZN8AutoFilersI7WrapperI15VectorFormatterIS2_IN12_GLOBAL__N_122EncodedDoubleFormatterEEERNSt3__16vectorINS8_IdNS7_9allocatorIdEEEENS9_ISB_EEEEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIR22transaction_identifierILb0EEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIR4CoinEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersINSt3__14spanIhLm18446744073709551615EEEEERS_OT_
Unexecuted instantiation: _ZN8AutoFilersIRSt4byteEERS_OT_
471
};
472
473
using DataBuffer = std::vector<std::byte>;
474
475
/** Wrapper around an AutoFile& that implements a ring buffer to
476
 *  deserialize from. It guarantees the ability to rewind a given number of bytes.
477
 *
478
 *  Will automatically close the file when it goes out of scope if not null.
479
 *  If you need to close the file early, use file.fclose() instead of fclose(file).
480
 */
481
class BufferedFile
482
{
483
private:
484
    AutoFile& m_src;
485
    uint64_t nSrcPos{0};  //!< how many bytes have been read from source
486
    uint64_t m_read_pos{0}; //!< how many bytes have been read from this
487
    uint64_t nReadLimit;  //!< up to which position we're allowed to read
488
    uint64_t nRewind;     //!< how many bytes we guarantee to rewind
489
    DataBuffer vchBuf;
490
491
    //! read data from the source to fill the buffer
492
0
    bool Fill() {
493
0
        unsigned int pos = nSrcPos % vchBuf.size();
494
0
        unsigned int readNow = vchBuf.size() - pos;
495
0
        unsigned int nAvail = vchBuf.size() - (nSrcPos - m_read_pos) - nRewind;
496
0
        if (nAvail < readNow)
497
0
            readNow = nAvail;
498
0
        if (readNow == 0)
499
0
            return false;
500
0
        size_t nBytes{m_src.detail_fread(std::span{vchBuf}.subspan(pos, readNow))};
501
0
        if (nBytes == 0) {
502
0
            throw std::ios_base::failure{m_src.feof() ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed"};
503
0
        }
504
0
        nSrcPos += nBytes;
505
0
        return true;
506
0
    }
507
508
    //! Advance the stream's read pointer (m_read_pos) by up to 'length' bytes,
509
    //! filling the buffer from the file so that at least one byte is available.
510
    //! Return a pointer to the available buffer data and the number of bytes
511
    //! (which may be less than the requested length) that may be accessed
512
    //! beginning at that pointer.
513
    std::pair<std::byte*, size_t> AdvanceStream(size_t length)
514
0
    {
515
0
        assert(m_read_pos <= nSrcPos);
516
0
        if (m_read_pos + length > nReadLimit) {
517
0
            throw std::ios_base::failure("Attempt to position past buffer limit");
518
0
        }
519
        // If there are no bytes available, read from the file.
520
0
        if (m_read_pos == nSrcPos && length > 0) Fill();
521
522
0
        size_t buffer_offset{static_cast<size_t>(m_read_pos % vchBuf.size())};
523
0
        size_t buffer_available{static_cast<size_t>(vchBuf.size() - buffer_offset)};
524
0
        size_t bytes_until_source_pos{static_cast<size_t>(nSrcPos - m_read_pos)};
525
0
        size_t advance{std::min({length, buffer_available, bytes_until_source_pos})};
526
0
        m_read_pos += advance;
527
0
        return std::make_pair(&vchBuf[buffer_offset], advance);
528
0
    }
529
530
public:
531
    BufferedFile(AutoFile& file LIFETIMEBOUND, uint64_t nBufSize, uint64_t nRewindIn)
532
0
        : m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
533
0
    {
534
0
        if (nRewindIn >= nBufSize)
535
0
            throw std::ios_base::failure("Rewind limit must be less than buffer size");
536
0
    }
537
538
    //! check whether we're at the end of the source file
539
0
    bool eof() const {
540
0
        return m_read_pos == nSrcPos && m_src.feof();
541
0
    }
542
543
    //! read a number of bytes
544
    void read(std::span<std::byte> dst)
545
0
    {
546
0
        while (dst.size() > 0) {
547
0
            auto [buffer_pointer, length]{AdvanceStream(dst.size())};
548
0
            memcpy(dst.data(), buffer_pointer, length);
549
0
            dst = dst.subspan(length);
550
0
        }
551
0
    }
552
553
    //! Move the read position ahead in the stream to the given position.
554
    //! Use SetPos() to back up in the stream, not SkipTo().
555
    void SkipTo(const uint64_t file_pos)
556
0
    {
557
0
        assert(file_pos >= m_read_pos);
558
0
        while (m_read_pos < file_pos) AdvanceStream(file_pos - m_read_pos);
559
0
    }
560
561
    //! return the current reading position
562
0
    uint64_t GetPos() const {
563
0
        return m_read_pos;
564
0
    }
565
566
    //! rewind to a given reading position
567
0
    bool SetPos(uint64_t nPos) {
568
0
        size_t bufsize = vchBuf.size();
569
0
        if (nPos + bufsize < nSrcPos) {
570
            // rewinding too far, rewind as far as possible
571
0
            m_read_pos = nSrcPos - bufsize;
572
0
            return false;
573
0
        }
574
0
        if (nPos > nSrcPos) {
575
            // can't go this far forward, go as far as possible
576
0
            m_read_pos = nSrcPos;
577
0
            return false;
578
0
        }
579
0
        m_read_pos = nPos;
580
0
        return true;
581
0
    }
582
583
    //! prevent reading beyond a certain position
584
    //! no argument removes the limit
585
0
    bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) {
586
0
        if (nPos < m_read_pos)
587
0
            return false;
588
0
        nReadLimit = nPos;
589
0
        return true;
590
0
    }
591
592
    template<typename T>
593
0
    BufferedFile& operator>>(T&& obj) {
594
0
        ::Unserialize(*this, obj);
595
0
        return (*this);
596
0
    }
Unexecuted instantiation: _ZN12BufferedFilersIRbEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRaEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRhEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRsEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRtEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRiEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRjEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRxEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRyEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRNSt3__16vectorIhNS1_9allocatorIhEEEEEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIRNSt3__15arrayIhLm4EEEEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersIR12CBlockHeaderEERS_OT_
Unexecuted instantiation: _ZN12BufferedFilersI13ParamsWrapperI20TransactionSerParams6CBlockEEERS_OT_
597
598
    //! search for a given byte in the stream, and remain positioned on it
599
    void FindByte(std::byte byte)
600
0
    {
601
        // For best performance, avoid mod operation within the loop.
602
0
        size_t buf_offset{size_t(m_read_pos % uint64_t(vchBuf.size()))};
603
0
        while (true) {
604
0
            if (m_read_pos == nSrcPos) {
605
                // No more bytes available; read from the file into the buffer,
606
                // setting nSrcPos to one beyond the end of the new data.
607
                // Throws exception if end-of-file reached.
608
0
                Fill();
609
0
            }
610
0
            const size_t len{std::min<size_t>(vchBuf.size() - buf_offset, nSrcPos - m_read_pos)};
611
0
            const auto it_start{vchBuf.begin() + buf_offset};
612
0
            const auto it_find{std::find(it_start, it_start + len, byte)};
613
0
            const size_t inc{size_t(std::distance(it_start, it_find))};
614
0
            m_read_pos += inc;
615
0
            if (inc < len) break;
616
0
            buf_offset += inc;
617
0
            if (buf_offset >= vchBuf.size()) buf_offset = 0;
618
0
        }
619
0
    }
620
};
621
622
/**
623
 * Wrapper that buffers reads from an underlying stream.
624
 * Requires underlying stream to support read() and detail_fread() calls
625
 * to support fixed-size and variable-sized reads, respectively.
626
 */
627
template <typename S>
628
class BufferedReader
629
{
630
    S& m_src;
631
    DataBuffer m_buf;
632
    size_t m_buf_pos;
633
634
public:
635
    //! Requires stream ownership to prevent leaving the stream at an unexpected position after buffered reads.
636
    explicit BufferedReader(S&& stream LIFETIMEBOUND, size_t size = 1 << 16)
637
        requires std::is_rvalue_reference_v<S&&>
638
55
        : m_src{stream}, m_buf(size), m_buf_pos{size} {}
639
640
    void read(std::span<std::byte> dst)
641
110
    {
642
110
        if (const auto available{std::min(dst.size(), m_buf.size() - m_buf_pos)}) {
643
55
            std::copy_n(m_buf.begin() + m_buf_pos, available, dst.begin());
644
55
            m_buf_pos += available;
645
55
            dst = dst.subspan(available);
646
55
        }
647
110
        if (dst.size()) {
648
55
            assert(m_buf_pos == m_buf.size());
649
55
            m_src.read(dst);
650
651
55
            m_buf_pos = 0;
652
55
            m_buf.resize(m_src.detail_fread(m_buf));
653
55
        }
654
110
    }
655
656
    template <typename T>
657
    BufferedReader& operator>>(T&& obj)
658
55
    {
659
55
        Unserialize(*this, obj);
660
55
        return *this;
661
55
    }
662
};
663
664
/**
665
 * Wrapper that buffers writes to an underlying stream.
666
 * Requires underlying stream to support write_buffer() method
667
 * for efficient buffer flushing and obfuscation.
668
 */
669
template <typename S>
670
class BufferedWriter
671
{
672
    S& m_dst;
673
    DataBuffer m_buf;
674
    size_t m_buf_pos{0};
675
676
public:
677
20.0M
    explicit BufferedWriter(S& stream LIFETIMEBOUND, size_t size = 1 << 16) : m_dst{stream}, m_buf(size) {}
678
679
20.0M
    ~BufferedWriter() { flush(); }
680
681
    void flush()
682
30.0M
    {
683
30.0M
        if (m_buf_pos) 
m_dst.write_buffer(std::span{m_buf}.first(m_buf_pos))20.0M
;
684
30.0M
        m_buf_pos = 0;
685
30.0M
    }
686
687
    void write(std::span<const std::byte> src)
688
330M
    {
689
661M
        while (const auto available{std::min(src.size(), m_buf.size() - m_buf_pos)}) {
690
330M
            std::copy_n(src.begin(), available, m_buf.begin() + m_buf_pos);
691
330M
            m_buf_pos += available;
692
330M
            if (m_buf_pos == m_buf.size()) 
flush()0
;
693
330M
            src = src.subspan(available);
694
330M
        }
695
330M
    }
696
697
    template <typename T>
698
    BufferedWriter& operator<<(const T& obj)
699
80.0M
    {
700
80.0M
        Serialize(*this, obj);
701
80.0M
        return *this;
702
80.0M
    }
_ZN14BufferedWriterI8AutoFileElsINSt3__15arrayIhLm4EEEEERS1_RKT_
Line
Count
Source
699
20.0M
    {
700
20.0M
        Serialize(*this, obj);
701
20.0M
        return *this;
702
20.0M
    }
_ZN14BufferedWriterI8AutoFileElsIjEERS1_RKT_
Line
Count
Source
699
20.0M
    {
700
20.0M
        Serialize(*this, obj);
701
20.0M
        return *this;
702
20.0M
    }
_ZN14BufferedWriterI8AutoFileElsI10CBlockUndoEERS1_RKT_
Line
Count
Source
699
9.99M
    {
700
9.99M
        Serialize(*this, obj);
701
9.99M
        return *this;
702
9.99M
    }
Unexecuted instantiation: _ZN14BufferedWriterI8AutoFileElsI7WrapperI15VarIntFormatterIL10VarIntMode0EERyEEERS1_RKT_
Unexecuted instantiation: _ZN14BufferedWriterI8AutoFileElsINSt3__14spanIhLm18446744073709551615EEEEERS1_RKT_
Unexecuted instantiation: _ZN14BufferedWriterI8AutoFileElsI7WrapperI15VarIntFormatterIL10VarIntMode0EERjEEERS1_RKT_
Unexecuted instantiation: _ZN14BufferedWriterI8AutoFileElsINSt3__14spanIKhLm18446744073709551615EEEEERS1_RKT_
_ZN14BufferedWriterI8AutoFileElsI7uint256EERS1_RKT_
Line
Count
Source
699
9.99M
    {
700
9.99M
        Serialize(*this, obj);
701
9.99M
        return *this;
702
9.99M
    }
_ZN14BufferedWriterI8AutoFileElsINSt3__14spanIKhLm32EEEEERS1_RKT_
Line
Count
Source
699
9.99M
    {
700
9.99M
        Serialize(*this, obj);
701
9.99M
        return *this;
702
9.99M
    }
_ZN14BufferedWriterI8AutoFileElsI13ParamsWrapperI20TransactionSerParamsK6CBlockEEERS1_RKT_
Line
Count
Source
699
10.0M
    {
700
10.0M
        Serialize(*this, obj);
701
10.0M
        return *this;
702
10.0M
    }
703
};
704
705
#endif // BITCOIN_STREAMS_H