/workdir/bitcoin/src/streams.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2022 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(Span<std::byte> write, Span<const std::byte> key, size_t key_offset = 0) |
29 | 0 | { |
30 | 0 | if (key.size() == 0) { Branch (30:9): [True: 0, False: 0]
|
31 | 0 | return; |
32 | 0 | } |
33 | 0 | key_offset %= key.size(); |
34 | |
|
35 | 0 | for (size_t i = 0, j = key_offset; i != write.size(); i++) { Branch (35:40): [True: 0, False: 0]
|
36 | 0 | 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 | 0 | if (j == key.size()) Branch (42:13): [True: 0, False: 0]
|
43 | 0 | j = 0; |
44 | 0 | } |
45 | 0 | } |
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 | 39.5k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn) : vchData{vchDataIn}, nPos{nPosIn} |
61 | 39.5k | { |
62 | 39.5k | if(nPos > vchData.size()) Branch (62:12): [True: 0, False: 39.5k]
|
63 | 0 | vchData.resize(nPos); |
64 | 39.5k | } |
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 | 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 | } VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, std::vector<CBlock, std::allocator<CBlock> > > >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<TransactionSerParams, std::vector<CBlock, std::allocator<CBlock> > >&&) Line | Count | Source | 70 | 3.25k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 3.25k | { | 72 | 3.25k | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 3.25k | } |
VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CBlockHeaderAndShortTxIDs> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<TransactionSerParams, CBlockHeaderAndShortTxIDs>&&) Line | Count | Source | 70 | 1.68k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 1.68k | { | 72 | 1.68k | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 1.68k | } |
VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CBlock> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<TransactionSerParams, CBlock>&&) Line | Count | Source | 70 | 6.84k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 6.84k | { | 72 | 6.84k | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 6.84k | } |
Unexecuted instantiation: VectorWriter::VectorWriter<Span<std::byte> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, Span<std::byte>&&) VectorWriter::VectorWriter<int&, Wrapper<CustomUintFormatter<8, false>, ServiceFlags&>, long, long, ParamsWrapper<CNetAddr::SerParams, CService>, long, ParamsWrapper<CNetAddr::SerParams, CService>, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, bool&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, int&, Wrapper<CustomUintFormatter<8, false>, ServiceFlags&>&&, long&&, long&&, ParamsWrapper<CNetAddr::SerParams, CService>&&, long&&, ParamsWrapper<CNetAddr::SerParams, CService>&&, unsigned long&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, int&&, bool&) Line | Count | Source | 70 | 870 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 870 | { | 72 | 870 | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 870 | } |
VectorWriter::VectorWriter<CMessageHeader&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, CMessageHeader&) Line | Count | Source | 70 | 17.4k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 17.4k | { | 72 | 17.4k | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 17.4k | } |
VectorWriter::VectorWriter<bool, unsigned long const&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, bool&&, unsigned long const&) Line | Count | Source | 70 | 870 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 870 | { | 72 | 870 | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 870 | } |
Unexecuted instantiation: VectorWriter::VectorWriter<CBlockHeaderAndShortTxIDs const&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, CBlockHeaderAndShortTxIDs const&) Unexecuted instantiation: VectorWriter::VectorWriter<std::vector<CInv, std::allocator<CInv> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, std::vector<CInv, std::allocator<CInv> >&) VectorWriter::VectorWriter<int const&, unsigned long&, long const&, unsigned long&, ParamsWrapper<CNetAddr::SerParams, CService>, unsigned long&, ParamsWrapper<CNetAddr::SerParams, CService>, unsigned long&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int const&, bool const&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, int const&, unsigned long&, long const&, unsigned long&, ParamsWrapper<CNetAddr::SerParams, CService>&&, unsigned long&, ParamsWrapper<CNetAddr::SerParams, CService>&&, unsigned long&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int const&, bool const&) Line | Count | Source | 70 | 870 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 870 | { | 72 | 870 | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 870 | } |
Unexecuted instantiation: VectorWriter::VectorWriter<unsigned int const&, unsigned long const&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned int const&, unsigned long const&) Unexecuted instantiation: VectorWriter::VectorWriter<Span<unsigned char const> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, Span<unsigned char const>&&) VectorWriter::VectorWriter<CBlockLocator const&, uint256>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, CBlockLocator const&, uint256&&) Line | Count | Source | 70 | 2.47k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 2.47k | { | 72 | 2.47k | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 2.47k | } |
Unexecuted instantiation: VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CTransaction const> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<TransactionSerParams, CTransaction const>&&) Unexecuted instantiation: VectorWriter::VectorWriter<Span<unsigned char> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, Span<unsigned char>&&) Unexecuted instantiation: VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CBlock const> >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<TransactionSerParams, CBlock const>&&) Unexecuted instantiation: VectorWriter::VectorWriter<CMerkleBlock&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, CMerkleBlock&) Unexecuted instantiation: VectorWriter::VectorWriter<CBlockHeaderAndShortTxIDs&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, CBlockHeaderAndShortTxIDs&) Unexecuted instantiation: VectorWriter::VectorWriter<BlockTransactions&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, BlockTransactions&) Unexecuted instantiation: VectorWriter::VectorWriter<std::vector<CBlockHeader, std::allocator<CBlockHeader> > >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, std::vector<CBlockHeader, std::allocator<CBlockHeader> >&&) Unexecuted instantiation: VectorWriter::VectorWriter<BlockTransactionsRequest&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, BlockTransactionsRequest&) VectorWriter::VectorWriter<unsigned long&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned long&) Line | Count | Source | 70 | 870 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 870 | { | 72 | 870 | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 870 | } |
Unexecuted instantiation: VectorWriter::VectorWriter<BlockFilter const&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, BlockFilter const&) Unexecuted instantiation: VectorWriter::VectorWriter<unsigned char&, uint256, uint256&, std::vector<uint256, std::allocator<uint256> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned char&, uint256&&, uint256&, std::vector<uint256, std::allocator<uint256> >&) Unexecuted instantiation: VectorWriter::VectorWriter<unsigned char&, uint256, std::vector<uint256, std::allocator<uint256> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned char&, uint256&&, std::vector<uint256, std::allocator<uint256> >&) Unexecuted instantiation: VectorWriter::VectorWriter<ParamsWrapper<CAddress::SerParams, std::vector<CAddress, std::allocator<CAddress> > > >(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, ParamsWrapper<CAddress::SerParams, std::vector<CAddress, std::allocator<CAddress> > >&&) VectorWriter::VectorWriter<long&>(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, long&) Line | Count | Source | 70 | 580 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 71 | 580 | { | 72 | 580 | ::SerializeMany(*this, std::forward<Args>(args)...); | 73 | 580 | } |
|
74 | | void write(Span<const std::byte> src) |
75 | 633k | { |
76 | 633k | assert(nPos <= vchData.size()); |
77 | 633k | size_t nOverwrite = std::min(src.size(), vchData.size() - nPos); |
78 | 633k | if (nOverwrite) { Branch (78:13): [True: 0, False: 633k]
|
79 | 0 | memcpy(vchData.data() + nPos, src.data(), nOverwrite); |
80 | 0 | } |
81 | 633k | if (nOverwrite < src.size()) { Branch (81:13): [True: 633k, False: 0]
|
82 | 633k | vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.end())); |
83 | 633k | } |
84 | 633k | nPos += src.size(); |
85 | 633k | } |
86 | | template <typename T> |
87 | | VectorWriter& operator<<(const T& obj) |
88 | 6.53k | { |
89 | 6.53k | ::Serialize(*this, obj); |
90 | 6.53k | return (*this); |
91 | 6.53k | } Unexecuted instantiation: cluster_linearize.cpp:VectorWriter& VectorWriter::operator<< <Wrapper<(anonymous namespace)::DepGraphFormatter, cluster_linearize::DepGraph<bitset_detail::IntBitSet<unsigned int> > const&> >(Wrapper<(anonymous namespace)::DepGraphFormatter, cluster_linearize::DepGraph<bitset_detail::IntBitSet<unsigned int> > const&> const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <Wrapper<VarIntFormatter<(VarIntMode)1>, int const&> >(Wrapper<VarIntFormatter<(VarIntMode)1>, int const&> const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <unsigned char>(unsigned char const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <std::set<uint256, std::less<uint256>, std::allocator<uint256> > >(std::set<uint256, std::less<uint256>, std::allocator<uint256> > const&) VectorWriter& VectorWriter::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) Line | Count | Source | 88 | 6.53k | { | 89 | 6.53k | ::Serialize(*this, obj); | 90 | 6.53k | return (*this); | 91 | 6.53k | } |
Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <unsigned char [4]>(unsigned char const (&) [4]) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <unsigned int>(unsigned int const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <std::vector<unsigned char, std::allocator<unsigned char> > >(std::vector<unsigned char, std::allocator<unsigned char> > const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <uint256>(uint256 const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<< <int>(int const&) |
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 Span. |
99 | | */ |
100 | | class SpanReader |
101 | | { |
102 | | private: |
103 | | Span<const unsigned char> m_data; |
104 | | |
105 | | public: |
106 | | /** |
107 | | * @param[in] data Referenced byte vector to overwrite/append |
108 | | */ |
109 | 0 | explicit SpanReader(Span<const unsigned char> data) : m_data{data} {} |
110 | | |
111 | | template<typename T> |
112 | | SpanReader& operator>>(T&& obj) |
113 | 0 | { |
114 | 0 | ::Unserialize(*this, obj); |
115 | 0 | return (*this); |
116 | 0 | } Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<unsigned char, std::allocator<unsigned char> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&) Unexecuted instantiation: SpanReader& SpanReader::operator>><XOnlyPubKey&>(XOnlyPubKey&) Unexecuted instantiation: SpanReader& SpanReader::operator>><uint256&>(uint256&) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: cluster_linearize.cpp:SpanReader& SpanReader::operator>><Wrapper<(anonymous namespace)::DepGraphFormatter, cluster_linearize::DepGraph<bitset_detail::IntBitSet<unsigned int> >&> >(Wrapper<(anonymous namespace)::DepGraphFormatter, cluster_linearize::DepGraph<bitset_detail::IntBitSet<unsigned int> >&>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><Wrapper<VarIntFormatter<(VarIntMode)1>, int&> >(Wrapper<VarIntFormatter<(VarIntMode)1>, int&>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned long&>(unsigned long&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<TransactionSerParams, CMutableTransaction> >(ParamsWrapper<TransactionSerParams, CMutableTransaction>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CTxOut&>(CTxOut&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CScript&>(CScript&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&) |
117 | | |
118 | 0 | size_t size() const { return m_data.size(); } |
119 | 0 | bool empty() const { return m_data.empty(); } |
120 | | |
121 | | void read(Span<std::byte> dst) |
122 | 0 | { |
123 | 0 | if (dst.size() == 0) { Branch (123:13): [True: 0, False: 0]
|
124 | 0 | return; |
125 | 0 | } |
126 | | |
127 | | // Read from the beginning of the buffer |
128 | 0 | if (dst.size() > m_data.size()) { Branch (128:13): [True: 0, False: 0]
|
129 | 0 | throw std::ios_base::failure("SpanReader::read(): end of data"); |
130 | 0 | } |
131 | 0 | memcpy(dst.data(), m_data.data(), dst.size()); |
132 | 0 | m_data = m_data.subspan(dst.size()); |
133 | 0 | } |
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 | 5.11k | explicit DataStream() = default; |
165 | 0 | explicit DataStream(Span<const uint8_t> sp) : DataStream{AsBytes(sp)} {} |
166 | 0 | explicit DataStream(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 | 6.75k | iterator begin() { return vch.begin() + m_read_pos; } |
179 | 0 | const_iterator end() const { return vch.end(); } |
180 | 3.37k | iterator end() { return vch.end(); } |
181 | 12.6k | size_type size() const { return vch.size() - m_read_pos; } |
182 | 3.48k | bool empty() const { return vch.size() == m_read_pos; } |
183 | 27.0k | void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); } |
184 | 0 | 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 | 26.1k | reference operator[](size_type pos) { return vch[pos + m_read_pos]; } |
187 | 28.8k | void clear() { vch.clear(); m_read_pos = 0; } |
188 | 0 | 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(Span<value_type> dst) |
219 | 588k | { |
220 | 588k | if (dst.size() == 0) return; Branch (220:13): [True: 0, False: 588k]
|
221 | | |
222 | | // Read from the beginning of the buffer |
223 | 588k | auto next_read_pos{CheckedAdd(m_read_pos, dst.size())}; |
224 | 588k | if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) { Branch (224:13): [True: 0, False: 588k]
Branch (224:43): [True: 0, False: 588k]
|
225 | 0 | throw std::ios_base::failure("DataStream::read(): end of data"); |
226 | 0 | } |
227 | 588k | memcpy(dst.data(), &vch[m_read_pos], dst.size()); |
228 | 588k | if (next_read_pos.value() == vch.size()) { Branch (228:13): [True: 26.1k, False: 562k]
|
229 | 26.1k | m_read_pos = 0; |
230 | 26.1k | vch.clear(); |
231 | 26.1k | return; |
232 | 26.1k | } |
233 | 562k | m_read_pos = next_read_pos.value(); |
234 | 562k | } |
235 | | |
236 | | void ignore(size_t num_ignore) |
237 | 1.74k | { |
238 | | // Ignore from the beginning of the buffer |
239 | 1.74k | auto next_read_pos{CheckedAdd(m_read_pos, num_ignore)}; |
240 | 1.74k | if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) { Branch (240:13): [True: 0, False: 1.74k]
Branch (240:43): [True: 0, False: 1.74k]
|
241 | 0 | throw std::ios_base::failure("DataStream::ignore(): end of data"); |
242 | 0 | } |
243 | 1.74k | if (next_read_pos.value() == vch.size()) { Branch (243:13): [True: 0, False: 1.74k]
|
244 | 0 | m_read_pos = 0; |
245 | 0 | vch.clear(); |
246 | 0 | return; |
247 | 0 | } |
248 | 1.74k | m_read_pos = next_read_pos.value(); |
249 | 1.74k | } |
250 | | |
251 | | void write(Span<const value_type> src) |
252 | 23.6k | { |
253 | | // Write to the end of the buffer |
254 | 23.6k | vch.insert(vch.end(), src.begin(), src.end()); |
255 | 23.6k | } |
256 | | |
257 | | template<typename T> |
258 | | DataStream& operator<<(const T& obj) |
259 | 13.5k | { |
260 | 13.5k | ::Serialize(*this, obj); |
261 | 13.5k | return (*this); |
262 | 13.5k | } Unexecuted instantiation: DataStream& DataStream::operator<< <AddrMan>(AddrMan const&) Unexecuted instantiation: DataStream& DataStream::operator<< <AddrManDeterministic>(AddrManDeterministic const&) Unexecuted instantiation: DataStream& DataStream::operator<< <BlockFilter>(BlockFilter const&) Unexecuted instantiation: DataStream& DataStream::operator<< <unsigned char>(unsigned char const&) Unexecuted instantiation: DataStream& DataStream::operator<< <uint256>(uint256 const&) DataStream& DataStream::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) Line | Count | Source | 259 | 6.75k | { | 260 | 6.75k | ::Serialize(*this, obj); | 261 | 6.75k | return (*this); | 262 | 6.75k | } |
Unexecuted instantiation: DataStream& DataStream::operator<< <std::vector<unsigned char, std::allocator<unsigned char> > >(std::vector<unsigned char, std::allocator<unsigned char> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CBlockFileInfo>(CBlockFileInfo const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CBlockHeaderAndShortTxIDs>(CBlockHeaderAndShortTxIDs const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CFeeRate>(CFeeRate const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CMerkleBlock>(CMerkleBlock const&) Unexecuted instantiation: DataStream& DataStream::operator<< <COutPoint>(COutPoint const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CPartialMerkleTree>(CPartialMerkleTree const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CPubKey>(CPubKey const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CScript>(CScript const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CTxIn>(CTxIn const&) Unexecuted instantiation: DataStream& DataStream::operator<< <FlatFilePos>(FlatFilePos const&) Unexecuted instantiation: DataStream& DataStream::operator<< <KeyOriginInfo>(KeyOriginInfo const&) Unexecuted instantiation: DataStream& DataStream::operator<< <PartiallySignedTransaction>(PartiallySignedTransaction const&) Unexecuted instantiation: DataStream& DataStream::operator<< <unsigned char [5]>(unsigned char const (&) [5]) Unexecuted instantiation: DataStream& DataStream::operator<< <unsigned char [4]>(unsigned char const (&) [4]) Unexecuted instantiation: DataStream& DataStream::operator<< <unsigned int>(unsigned int const&) Unexecuted instantiation: DataStream& DataStream::operator<< <PSBTInput>(PSBTInput const&) Unexecuted instantiation: DataStream& DataStream::operator<< <PSBTOutput>(PSBTOutput const&) Unexecuted instantiation: DataStream& DataStream::operator<< <PrefilledTransaction>(PrefilledTransaction const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<TransactionSerParams, CBlock> >(ParamsWrapper<TransactionSerParams, CBlock> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CBlockLocator>(CBlockLocator const&) DataStream& DataStream::operator<< <CBlockHeader>(CBlockHeader const&) Line | Count | Source | 259 | 3.37k | { | 260 | 3.37k | ::Serialize(*this, obj); | 261 | 3.37k | return (*this); | 262 | 3.37k | } |
Unexecuted instantiation: DataStream& DataStream::operator<< <CTxUndo>(CTxUndo const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Span<unsigned char> >(Span<unsigned char> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CBlockUndo>(CBlockUndo const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Coin>(Coin const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<CNetAddr::SerParams, CNetAddr const> >(ParamsWrapper<CNetAddr::SerParams, CNetAddr const> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<CNetAddr::SerParams, CService const> >(ParamsWrapper<CNetAddr::SerParams, CService const> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CMessageHeader>(CMessageHeader const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<CAddress::SerParams, CAddress const> >(ParamsWrapper<CAddress::SerParams, CAddress const> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CInv>(CInv const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CBloomFilter>(CBloomFilter const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CDiskBlockIndex>(CDiskBlockIndex const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Wrapper<TxOutCompression, CTxOut&> >(Wrapper<TxOutCompression, CTxOut&> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <BlockTransactions>(BlockTransactions const&) Unexecuted instantiation: DataStream& DataStream::operator<< <BlockTransactionsRequest>(BlockTransactionsRequest const&) Unexecuted instantiation: DataStream& DataStream::operator<< <node::SnapshotMetadata>(node::SnapshotMetadata const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::array<unsigned char, 5ul> >(std::array<unsigned char, 5ul> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <unsigned short>(unsigned short const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::array<unsigned char, 4ul> >(std::array<unsigned char, 4ul> const&) DataStream& DataStream::operator<< <unsigned long>(unsigned long const&) Line | Count | Source | 259 | 3.37k | { | 260 | 3.37k | ::Serialize(*this, obj); | 261 | 3.37k | return (*this); | 262 | 3.37k | } |
Unexecuted instantiation: DataStream& DataStream::operator<< <uint160>(uint160 const&) Unexecuted instantiation: DataStream& DataStream::operator<< <long>(long const&) Unexecuted instantiation: DataStream& DataStream::operator<< <int>(int const&) Unexecuted instantiation: DataStream& DataStream::operator<< <short>(short const&) Unexecuted instantiation: DataStream& DataStream::operator<< <signed char>(signed char const&) Unexecuted instantiation: DataStream& DataStream::operator<< <bool>(bool const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::vector<int, std::allocator<int> > >(std::vector<int, std::allocator<int> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <prevector<8u, int, unsigned int, int> >(prevector<8u, int, unsigned int, int> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<TransactionSerParams, CMutableTransaction> >(ParamsWrapper<TransactionSerParams, CMutableTransaction> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Wrapper<LimitedStringFormatter<10ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&> >(Wrapper<LimitedStringFormatter<10ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<unsigned char, uint256> >(std::pair<unsigned char, uint256> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CDiskTxPos>(CDiskTxPos const&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey const&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBHashKey>((anonymous namespace)::DBHashKey const&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBVal>((anonymous namespace)::DBVal const&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator<< <std::pair<uint256, (anonymous namespace)::DBVal> >(std::pair<uint256, (anonymous namespace)::DBVal> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <MuHash3072>(MuHash3072 const&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBHeightKey>((anonymous namespace)::DBHeightKey const&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBHashKey>((anonymous namespace)::DBHashKey const&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::DBVal>((anonymous namespace)::DBVal const&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator<< <std::pair<uint256, (anonymous namespace)::DBVal> >(std::pair<uint256, (anonymous namespace)::DBVal> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <CTxOut>(CTxOut const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<unsigned char, int> >(std::pair<unsigned char, int> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(std::pair<unsigned char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> const> >(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> const> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::vector<CCoin, std::allocator<CCoin> > >(std::vector<CCoin, std::allocator<CCoin> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<TransactionSerParams, CBlock const> >(ParamsWrapper<TransactionSerParams, CBlock const> const&) Unexecuted instantiation: txdb.cpp:DataStream& DataStream::operator<< <(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::vector<uint256, std::allocator<uint256> > >(std::vector<uint256, std::allocator<uint256> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <Span<std::byte const> >(Span<std::byte const> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, transaction_identifier<false> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, transaction_identifier<false> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::CWalletTx>(wallet::CWalletTx const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >(std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CPubKey> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::CKeyMetadata>(wallet::CKeyMetadata const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> >(std::pair<std::vector<unsigned char, secure_allocator<unsigned char> >, uint256> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, uint256> >(std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, uint256> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::CMasterKey>(wallet::CMasterKey const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint160> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint160> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, CScript> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, long> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, long> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::CKeyPool>(wallet::CKeyPool const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<uint256, CPubKey> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::WalletDescriptor>(wallet::WalletDescriptor const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, std::pair<unsigned int, unsigned int> > >(std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, std::pair<unsigned int, unsigned int> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, unsigned int> >(std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, uint256>, unsigned int> const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<transaction_identifier<false>, unsigned int> > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) Unexecuted instantiation: DataStream& DataStream::operator<< <wallet::CHDChain>(wallet::CHDChain const&) Unexecuted instantiation: DataStream& DataStream::operator<< <ParamsWrapper<TransactionSerParams, CTransaction const> >(ParamsWrapper<TransactionSerParams, CTransaction const> const&) |
263 | | |
264 | | template<typename T> |
265 | | DataStream& operator>>(T&& obj) |
266 | 81.1k | { |
267 | 81.1k | ::Unserialize(*this, obj); |
268 | 81.1k | return (*this); |
269 | 81.1k | } Unexecuted instantiation: DataStream& DataStream::operator>><COutPoint&>(COutPoint&) Unexecuted instantiation: DataStream& DataStream::operator>><CPubKey&>(CPubKey&) Unexecuted instantiation: DataStream& DataStream::operator>><Span<unsigned char> >(Span<unsigned char>&&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, CMutableTransaction> >(ParamsWrapper<TransactionSerParams, CMutableTransaction>&&) Unexecuted instantiation: DataStream& DataStream::operator>><PartiallySignedTransaction&>(PartiallySignedTransaction&) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned char (&) [5]>(unsigned char (&) [5]) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<unsigned char, std::allocator<unsigned char> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned char (&) [4]>(unsigned char (&) [4]) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned int&>(unsigned int&) Unexecuted instantiation: DataStream& DataStream::operator>><PSBTInput&>(PSBTInput&) Unexecuted instantiation: DataStream& DataStream::operator>><CScript&>(CScript&) Unexecuted instantiation: DataStream& DataStream::operator>><std::set<uint256, std::less<uint256>, std::allocator<uint256> >&>(std::set<uint256, std::less<uint256>, std::allocator<uint256> >&) Unexecuted instantiation: DataStream& DataStream::operator>><PSBTOutput&>(PSBTOutput&) Unexecuted instantiation: DataStream& DataStream::operator>><AddrManDeterministic&>(AddrManDeterministic&) DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, CBlock> >(ParamsWrapper<TransactionSerParams, CBlock>&&) Line | Count | Source | 266 | 6.84k | { | 267 | 6.84k | ::Unserialize(*this, obj); | 268 | 6.84k | return (*this); | 269 | 6.84k | } |
DataStream& DataStream::operator>><CBlockHeader&>(CBlockHeader&) Line | Count | Source | 266 | 52.1k | { | 267 | 52.1k | ::Unserialize(*this, obj); | 268 | 52.1k | return (*this); | 269 | 52.1k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><CBlockLocator&>(CBlockLocator&) Unexecuted instantiation: DataStream& DataStream::operator>><CBlockFileInfo&>(CBlockFileInfo&) Unexecuted instantiation: DataStream& DataStream::operator>><BlockFilter&>(BlockFilter&) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: DataStream& DataStream::operator>><uint256&>(uint256&) Unexecuted instantiation: DataStream& DataStream::operator>><CDiskBlockIndex&>(CDiskBlockIndex&) Unexecuted instantiation: DataStream& DataStream::operator>><Coin&>(Coin&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&>&&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&>&&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, AddrInfo> >(ParamsWrapper<CAddress::SerParams, AddrInfo>&&) DataStream& DataStream::operator>><CBlockHeaderAndShortTxIDs&>(CBlockHeaderAndShortTxIDs&) Line | Count | Source | 266 | 1.68k | { | 267 | 1.68k | ::Unserialize(*this, obj); | 268 | 1.68k | return (*this); | 269 | 1.68k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><CFeeRate&>(CFeeRate&) Unexecuted instantiation: DataStream& DataStream::operator>><CMerkleBlock&>(CMerkleBlock&) Unexecuted instantiation: DataStream& DataStream::operator>><CPartialMerkleTree&>(CPartialMerkleTree&) Unexecuted instantiation: DataStream& DataStream::operator>><CTxIn&>(CTxIn&) Unexecuted instantiation: DataStream& DataStream::operator>><FlatFilePos&>(FlatFilePos&) Unexecuted instantiation: DataStream& DataStream::operator>><KeyOriginInfo&>(KeyOriginInfo&) Unexecuted instantiation: DataStream& DataStream::operator>><PrefilledTransaction&>(PrefilledTransaction&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, CBlock>&>(ParamsWrapper<TransactionSerParams, CBlock>&) Unexecuted instantiation: DataStream& DataStream::operator>><CTxUndo&>(CTxUndo&) Unexecuted instantiation: DataStream& DataStream::operator>><CBlockUndo&>(CBlockUndo&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CNetAddr::SerParams, CNetAddr> >(ParamsWrapper<CNetAddr::SerParams, CNetAddr>&&) DataStream& DataStream::operator>><ParamsWrapper<CNetAddr::SerParams, CService> >(ParamsWrapper<CNetAddr::SerParams, CService>&&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
DataStream& DataStream::operator>><CMessageHeader&>(CMessageHeader&) Line | Count | Source | 266 | 13.5k | { | 267 | 13.5k | ::Unserialize(*this, obj); | 268 | 13.5k | return (*this); | 269 | 13.5k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, CAddress> >(ParamsWrapper<CAddress::SerParams, CAddress>&&) Unexecuted instantiation: DataStream& DataStream::operator>><CInv&>(CInv&) Unexecuted instantiation: DataStream& DataStream::operator>><CBloomFilter&>(CBloomFilter&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<TxOutCompression, CTxOut&>&>(Wrapper<TxOutCompression, CTxOut&>&) Unexecuted instantiation: DataStream& DataStream::operator>><BlockTransactions&>(BlockTransactions&) Unexecuted instantiation: DataStream& DataStream::operator>><BlockTransactionsRequest&>(BlockTransactionsRequest&) Unexecuted instantiation: DataStream& DataStream::operator>><node::SnapshotMetadata&>(node::SnapshotMetadata&) Unexecuted instantiation: DataStream& DataStream::operator>><std::array<unsigned char, 5ul>&>(std::array<unsigned char, 5ul>&) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned short&>(unsigned short&) Unexecuted instantiation: DataStream& DataStream::operator>><std::array<unsigned char, 4ul>&>(std::array<unsigned char, 4ul>&) DataStream& DataStream::operator>><unsigned long&>(unsigned long&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
Unexecuted instantiation: DataStream& DataStream::operator>><uint160&>(uint160&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<CBlockHeader, std::allocator<CBlockHeader> >&>(std::vector<CBlockHeader, std::allocator<CBlockHeader> >&) DataStream& DataStream::operator>><long&>(long&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
DataStream& DataStream::operator>><int&>(int&) Line | Count | Source | 266 | 1.74k | { | 267 | 1.74k | ::Unserialize(*this, obj); | 268 | 1.74k | return (*this); | 269 | 1.74k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><short&>(short&) Unexecuted instantiation: DataStream& DataStream::operator>><signed char&>(signed char&) DataStream& DataStream::operator>><bool&>(bool&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<CTxIn, std::allocator<CTxIn> >&>(std::vector<CTxIn, std::allocator<CTxIn> >&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<CTxOut, std::allocator<CTxOut> >&>(std::vector<CTxOut, std::allocator<CTxOut> >&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&) Unexecuted instantiation: DataStream& DataStream::operator>><CTxOut&>(CTxOut&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<LimitedStringFormatter<10ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>&>(Wrapper<LimitedStringFormatter<10ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>&) Unexecuted instantiation: DataStream& DataStream::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, CNetAddr> >(ParamsWrapper<CAddress::SerParams, CNetAddr>&&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&> >(Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>&&) Unexecuted instantiation: DataStream& DataStream::operator>><CDiskTxPos&>(CDiskTxPos&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator>><(anonymous namespace)::DBHeightKey&>((anonymous namespace)::DBHeightKey&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator>><(anonymous namespace)::DBVal&>((anonymous namespace)::DBVal&) Unexecuted instantiation: DataStream& DataStream::operator>><MuHash3072&>(MuHash3072&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator>><(anonymous namespace)::DBHeightKey&>((anonymous namespace)::DBHeightKey&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator>><(anonymous namespace)::DBVal&>((anonymous namespace)::DBVal&) DataStream& DataStream::operator>><Wrapper<CustomUintFormatter<8, false>, ServiceFlags&> >(Wrapper<CustomUintFormatter<8, false>, ServiceFlags&>&&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
DataStream& DataStream::operator>><Wrapper<LimitedStringFormatter<256ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&> >(Wrapper<LimitedStringFormatter<256ul>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>&&) Line | Count | Source | 266 | 870 | { | 267 | 870 | ::Unserialize(*this, obj); | 268 | 870 | return (*this); | 269 | 870 | } |
Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, std::vector<CAddress, std::allocator<CAddress> > > >(ParamsWrapper<CAddress::SerParams, std::vector<CAddress, std::allocator<CAddress> > >&&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<CInv, std::allocator<CInv> >&>(std::vector<CInv, std::allocator<CInv> >&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> > >(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> >&&) Unexecuted instantiation: DataStream& DataStream::operator>><std::pair<unsigned char, uint256>&>(std::pair<unsigned char, uint256>&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<COutPoint, std::allocator<COutPoint> >&>(std::vector<COutPoint, std::allocator<COutPoint> >&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<uint256, std::allocator<uint256> >&>(std::vector<uint256, std::allocator<uint256> >&) Unexecuted instantiation: txdb.cpp:DataStream& DataStream::operator>><(anonymous namespace)::CoinEntry&>((anonymous namespace)::CoinEntry&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CKeyMetadata&>(wallet::CKeyMetadata&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CKeyPool&>(wallet::CKeyPool&) Unexecuted instantiation: DataStream& DataStream::operator>><int>(int&&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::WalletDescriptor&>(wallet::WalletDescriptor&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CWalletTx&>(wallet::CWalletTx&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<wallet::CMerkleTx, std::allocator<wallet::CMerkleTx> >&>(std::vector<wallet::CMerkleTx, std::allocator<wallet::CMerkleTx> >&) Unexecuted instantiation: DataStream& DataStream::operator>><std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>(std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) Unexecuted instantiation: DataStream& DataStream::operator>><transaction_identifier<false>&>(transaction_identifier<false>&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<unsigned char, secure_allocator<unsigned char> >&>(std::vector<unsigned char, secure_allocator<unsigned char> >&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CMasterKey&>(wallet::CMasterKey&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CHDChain&>(wallet::CHDChain&) |
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 | 0 | { |
278 | 0 | util::Xor(MakeWritableByteSpan(*this), MakeByteSpan(key)); |
279 | 0 | } |
280 | | }; |
281 | | |
282 | | template <typename IStream> |
283 | | class BitStreamReader |
284 | | { |
285 | | private: |
286 | | IStream& m_istream; |
287 | | |
288 | | /// Buffered byte read in from the input stream. A new byte is read into the |
289 | | /// buffer when m_offset reaches 8. |
290 | | uint8_t m_buffer{0}; |
291 | | |
292 | | /// Number of high order bits in m_buffer already returned by previous |
293 | | /// Read() calls. The next bit to be returned is at this offset from the |
294 | | /// most significant bit position. |
295 | | int m_offset{8}; |
296 | | |
297 | | public: |
298 | 0 | explicit BitStreamReader(IStream& istream) : m_istream(istream) {} |
299 | | |
300 | | /** Read the specified number of bits from the stream. The data is returned |
301 | | * in the nbits least significant bits of a 64-bit uint. |
302 | | */ |
303 | 0 | uint64_t Read(int nbits) { |
304 | 0 | if (nbits < 0 || nbits > 64) { Branch (304:13): [True: 0, False: 0]
Branch (304:26): [True: 0, False: 0]
|
305 | 0 | throw std::out_of_range("nbits must be between 0 and 64"); |
306 | 0 | } |
307 | | |
308 | 0 | uint64_t data = 0; |
309 | 0 | while (nbits > 0) { Branch (309:16): [True: 0, False: 0]
|
310 | 0 | if (m_offset == 8) { Branch (310:17): [True: 0, False: 0]
|
311 | 0 | m_istream >> m_buffer; |
312 | 0 | m_offset = 0; |
313 | 0 | } |
314 | |
|
315 | 0 | int bits = std::min(8 - m_offset, nbits); |
316 | 0 | data <<= bits; |
317 | 0 | data |= static_cast<uint8_t>(m_buffer << m_offset) >> (8 - bits); |
318 | 0 | m_offset += bits; |
319 | 0 | nbits -= bits; |
320 | 0 | } |
321 | 0 | return data; |
322 | 0 | } |
323 | | }; |
324 | | |
325 | | template <typename OStream> |
326 | | class BitStreamWriter |
327 | | { |
328 | | private: |
329 | | OStream& m_ostream; |
330 | | |
331 | | /// Buffered byte waiting to be written to the output stream. The byte is |
332 | | /// written buffer when m_offset reaches 8 or Flush() is called. |
333 | | uint8_t m_buffer{0}; |
334 | | |
335 | | /// Number of high order bits in m_buffer already written by previous |
336 | | /// Write() calls and not yet flushed to the stream. The next bit to be |
337 | | /// written to is at this offset from the most significant bit position. |
338 | | int m_offset{0}; |
339 | | |
340 | | public: |
341 | 0 | explicit BitStreamWriter(OStream& ostream) : m_ostream(ostream) {} |
342 | | |
343 | | ~BitStreamWriter() |
344 | 0 | { |
345 | 0 | Flush(); |
346 | 0 | } |
347 | | |
348 | | /** Write the nbits least significant bits of a 64-bit int to the output |
349 | | * stream. Data is buffered until it completes an octet. |
350 | | */ |
351 | 0 | void Write(uint64_t data, int nbits) { |
352 | 0 | if (nbits < 0 || nbits > 64) { Branch (352:13): [True: 0, False: 0]
Branch (352:26): [True: 0, False: 0]
|
353 | 0 | throw std::out_of_range("nbits must be between 0 and 64"); |
354 | 0 | } |
355 | | |
356 | 0 | while (nbits > 0) { Branch (356:16): [True: 0, False: 0]
|
357 | 0 | int bits = std::min(8 - m_offset, nbits); |
358 | 0 | m_buffer |= (data << (64 - nbits)) >> (64 - 8 + m_offset); |
359 | 0 | m_offset += bits; |
360 | 0 | nbits -= bits; |
361 | |
|
362 | 0 | if (m_offset == 8) { Branch (362:17): [True: 0, False: 0]
|
363 | 0 | Flush(); |
364 | 0 | } |
365 | 0 | } |
366 | 0 | } |
367 | | |
368 | | /** Flush any unwritten bits to the output stream, padding with 0's to the |
369 | | * next byte boundary. |
370 | | */ |
371 | 0 | void Flush() { |
372 | 0 | if (m_offset == 0) { Branch (372:13): [True: 0, False: 0]
|
373 | 0 | return; |
374 | 0 | } |
375 | | |
376 | 0 | m_ostream << m_buffer; |
377 | 0 | m_buffer = 0; |
378 | 0 | m_offset = 0; |
379 | 0 | } |
380 | | }; |
381 | | |
382 | | /** Non-refcounted RAII wrapper for FILE* |
383 | | * |
384 | | * Will automatically close the file when it goes out of scope if not null. |
385 | | * If you're returning the file pointer, return file.release(). |
386 | | * If you need to close the file early, use file.fclose() instead of fclose(file). |
387 | | */ |
388 | | class AutoFile |
389 | | { |
390 | | protected: |
391 | | std::FILE* m_file; |
392 | | std::vector<std::byte> m_xor; |
393 | | |
394 | | public: |
395 | 0 | explicit AutoFile(std::FILE* file, std::vector<std::byte> data_xor={}) : m_file{file}, m_xor{std::move(data_xor)} {} |
396 | | |
397 | 0 | ~AutoFile() { fclose(); } |
398 | | |
399 | | // Disallow copies |
400 | | AutoFile(const AutoFile&) = delete; |
401 | | AutoFile& operator=(const AutoFile&) = delete; |
402 | | |
403 | 0 | bool feof() const { return std::feof(m_file); } |
404 | | |
405 | | int fclose() |
406 | 0 | { |
407 | 0 | if (auto rel{release()}) return std::fclose(rel); Branch (407:18): [True: 0, False: 0]
|
408 | 0 | return 0; |
409 | 0 | } |
410 | | |
411 | | /** Get wrapped FILE* with transfer of ownership. |
412 | | * @note This will invalidate the AutoFile object, and makes it the responsibility of the caller |
413 | | * of this function to clean up the returned FILE*. |
414 | | */ |
415 | | std::FILE* release() |
416 | 0 | { |
417 | 0 | std::FILE* ret{m_file}; |
418 | 0 | m_file = nullptr; |
419 | 0 | return ret; |
420 | 0 | } |
421 | | |
422 | | /** Get wrapped FILE* without transfer of ownership. |
423 | | * @note Ownership of the FILE* will remain with this class. Use this only if the scope of the |
424 | | * AutoFile outlives use of the passed pointer. |
425 | | */ |
426 | 0 | std::FILE* Get() const { return m_file; } |
427 | | |
428 | | /** Return true if the wrapped FILE* is nullptr, false otherwise. |
429 | | */ |
430 | 0 | bool IsNull() const { return m_file == nullptr; } |
431 | | |
432 | | /** Continue with a different XOR key */ |
433 | 0 | void SetXor(std::vector<std::byte> data_xor) { m_xor = data_xor; } |
434 | | |
435 | | /** Implementation detail, only used internally. */ |
436 | | std::size_t detail_fread(Span<std::byte> dst); |
437 | | |
438 | | void seek(int64_t offset, int origin); |
439 | | int64_t tell(); |
440 | | |
441 | | // |
442 | | // Stream subset |
443 | | // |
444 | | void read(Span<std::byte> dst); |
445 | | void ignore(size_t nSize); |
446 | | void write(Span<const std::byte> src); |
447 | | |
448 | | template <typename T> |
449 | | AutoFile& operator<<(const T& obj) |
450 | 0 | { |
451 | 0 | ::Serialize(*this, obj); |
452 | 0 | return *this; |
453 | 0 | } Unexecuted instantiation: AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <bool>(bool const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <signed char>(signed char const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <unsigned char>(unsigned char const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <short>(short const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <unsigned short>(unsigned short const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <int>(int const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <unsigned int>(unsigned int const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <long>(long const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <unsigned long>(unsigned long const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::vector<unsigned char, std::allocator<unsigned char> > >(std::vector<unsigned char, std::allocator<unsigned char> > const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <Span<unsigned char> >(Span<unsigned char> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <node::SnapshotMetadata>(node::SnapshotMetadata const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::array<unsigned char, 5ul> >(std::array<unsigned char, 5ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::array<unsigned char, 4ul> >(std::array<unsigned char, 4ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <uint256>(uint256 const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <transaction_identifier<false> >(transaction_identifier<false> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <Coin>(Coin const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <Span<char const> >(Span<char const> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::array<std::byte, 8ul> >(std::array<std::byte, 8ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <CBlockUndo>(CBlockUndo const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <ParamsWrapper<TransactionSerParams, CBlock const> >(ParamsWrapper<TransactionSerParams, CBlock const> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::vector<std::byte, std::allocator<std::byte> > >(std::vector<std::byte, std::allocator<std::byte> > const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <ParamsWrapper<TransactionSerParams, CTransaction const> >(ParamsWrapper<TransactionSerParams, CTransaction const> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::map<uint256, long, std::less<uint256>, std::allocator<std::pair<uint256 const, long> > > >(std::map<uint256, long, std::less<uint256>, std::allocator<std::pair<uint256 const, long> > > const&) Unexecuted instantiation: AutoFile& AutoFile::operator<< <std::set<uint256, std::less<uint256>, std::allocator<uint256> > >(std::set<uint256, std::less<uint256>, std::allocator<uint256> > const&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator<< <Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double const&> >(Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double const&> const&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator<< <Wrapper<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter>, std::vector<double, std::allocator<double> > const&> >(Wrapper<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter>, std::vector<double, std::allocator<double> > const&> const&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator<< <Wrapper<VectorFormatter<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&> >(Wrapper<VectorFormatter<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&> const&) |
454 | | |
455 | | template <typename T> |
456 | | AutoFile& operator>>(T&& obj) |
457 | 0 | { |
458 | 0 | ::Unserialize(*this, obj); |
459 | 0 | return *this; |
460 | 0 | } Unexecuted instantiation: AutoFile& AutoFile::operator>><bool&>(bool&) Unexecuted instantiation: AutoFile& AutoFile::operator>><signed char&>(signed char&) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: AutoFile& AutoFile::operator>><short&>(short&) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned short&>(unsigned short&) Unexecuted instantiation: AutoFile& AutoFile::operator>><int&>(int&) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned int&>(unsigned int&) Unexecuted instantiation: AutoFile& AutoFile::operator>><long&>(long&) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned long&>(unsigned long&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::vector<unsigned char, std::allocator<unsigned char> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&) Unexecuted instantiation: AutoFile& AutoFile::operator>><node::SnapshotMetadata&>(node::SnapshotMetadata&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::array<unsigned char, 5ul>&>(std::array<unsigned char, 5ul>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::array<unsigned char, 4ul>&>(std::array<unsigned char, 4ul>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><uint256&>(uint256&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&> >(Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><CBlockHeader&>(CBlockHeader&) Unexecuted instantiation: AutoFile& AutoFile::operator>><ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> > >(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> >&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::array<std::byte, 8ul>&>(std::array<std::byte, 8ul>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><ParamsWrapper<TransactionSerParams, CBlock> >(ParamsWrapper<TransactionSerParams, CBlock>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::vector<std::byte, std::allocator<std::byte> >&>(std::vector<std::byte, std::allocator<std::byte> >&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::map<uint256, long, std::less<uint256>, std::allocator<std::pair<uint256 const, long> > >&>(std::map<uint256, long, std::less<uint256>, std::allocator<std::pair<uint256 const, long> > >&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::set<uint256, std::less<uint256>, std::allocator<uint256> >&>(std::set<uint256, std::less<uint256>, std::allocator<uint256> >&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator>><Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double&> >(Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double&>&&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator>><Wrapper<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter>, std::vector<double, std::allocator<double> >&> >(Wrapper<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter>, std::vector<double, std::allocator<double> >&>&&) Unexecuted instantiation: fees.cpp:AutoFile& AutoFile::operator>><Wrapper<VectorFormatter<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&> >(Wrapper<VectorFormatter<VectorFormatter<(anonymous namespace)::EncodedDoubleFormatter> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><transaction_identifier<false>&>(transaction_identifier<false>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Coin&>(Coin&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> >(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Span<unsigned char> >(Span<unsigned char>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::byte&>(std::byte&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::MetaPage&>(wallet::MetaPage&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::array<std::byte, 20ul>&>(std::array<std::byte, 20ul>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><char (&) [368]>(char (&) [368]) Unexecuted instantiation: AutoFile& AutoFile::operator>><char (&) [12]>(char (&) [12]) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned char (&) [20]>(unsigned char (&) [20]) Unexecuted instantiation: AutoFile& AutoFile::operator>><unsigned char (&) [16]>(unsigned char (&) [16]) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::PageHeader&>(wallet::PageHeader&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::RecordsPage&>(wallet::RecordsPage&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::RecordHeader&>(wallet::RecordHeader&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::DataRecord&>(wallet::DataRecord&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::OverflowRecord&>(wallet::OverflowRecord&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::InternalPage&>(wallet::InternalPage&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::InternalRecord&>(wallet::InternalRecord&) Unexecuted instantiation: AutoFile& AutoFile::operator>><wallet::OverflowPage&>(wallet::OverflowPage&) |
461 | | }; |
462 | | |
463 | | /** Wrapper around an AutoFile& that implements a ring buffer to |
464 | | * deserialize from. It guarantees the ability to rewind a given number of bytes. |
465 | | * |
466 | | * Will automatically close the file when it goes out of scope if not null. |
467 | | * If you need to close the file early, use file.fclose() instead of fclose(file). |
468 | | */ |
469 | | class BufferedFile |
470 | | { |
471 | | private: |
472 | | AutoFile& m_src; |
473 | | uint64_t nSrcPos{0}; //!< how many bytes have been read from source |
474 | | uint64_t m_read_pos{0}; //!< how many bytes have been read from this |
475 | | uint64_t nReadLimit; //!< up to which position we're allowed to read |
476 | | uint64_t nRewind; //!< how many bytes we guarantee to rewind |
477 | | std::vector<std::byte> vchBuf; //!< the buffer |
478 | | |
479 | | //! read data from the source to fill the buffer |
480 | 0 | bool Fill() { |
481 | 0 | unsigned int pos = nSrcPos % vchBuf.size(); |
482 | 0 | unsigned int readNow = vchBuf.size() - pos; |
483 | 0 | unsigned int nAvail = vchBuf.size() - (nSrcPos - m_read_pos) - nRewind; |
484 | 0 | if (nAvail < readNow) Branch (484:13): [True: 0, False: 0]
|
485 | 0 | readNow = nAvail; |
486 | 0 | if (readNow == 0) Branch (486:13): [True: 0, False: 0]
|
487 | 0 | return false; |
488 | 0 | size_t nBytes{m_src.detail_fread(Span{vchBuf}.subspan(pos, readNow))}; |
489 | 0 | if (nBytes == 0) { Branch (489:13): [True: 0, False: 0]
|
490 | 0 | throw std::ios_base::failure{m_src.feof() ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed"}; Branch (490:42): [True: 0, False: 0]
|
491 | 0 | } |
492 | 0 | nSrcPos += nBytes; |
493 | 0 | return true; |
494 | 0 | } |
495 | | |
496 | | //! Advance the stream's read pointer (m_read_pos) by up to 'length' bytes, |
497 | | //! filling the buffer from the file so that at least one byte is available. |
498 | | //! Return a pointer to the available buffer data and the number of bytes |
499 | | //! (which may be less than the requested length) that may be accessed |
500 | | //! beginning at that pointer. |
501 | | std::pair<std::byte*, size_t> AdvanceStream(size_t length) |
502 | 0 | { |
503 | 0 | assert(m_read_pos <= nSrcPos); |
504 | 0 | if (m_read_pos + length > nReadLimit) { Branch (504:13): [True: 0, False: 0]
|
505 | 0 | throw std::ios_base::failure("Attempt to position past buffer limit"); |
506 | 0 | } |
507 | | // If there are no bytes available, read from the file. |
508 | 0 | if (m_read_pos == nSrcPos && length > 0) Fill(); Branch (508:13): [True: 0, False: 0]
Branch (508:38): [True: 0, False: 0]
|
509 | |
|
510 | 0 | size_t buffer_offset{static_cast<size_t>(m_read_pos % vchBuf.size())}; |
511 | 0 | size_t buffer_available{static_cast<size_t>(vchBuf.size() - buffer_offset)}; |
512 | 0 | size_t bytes_until_source_pos{static_cast<size_t>(nSrcPos - m_read_pos)}; |
513 | 0 | size_t advance{std::min({length, buffer_available, bytes_until_source_pos})}; |
514 | 0 | m_read_pos += advance; |
515 | 0 | return std::make_pair(&vchBuf[buffer_offset], advance); |
516 | 0 | } |
517 | | |
518 | | public: |
519 | | BufferedFile(AutoFile& file, uint64_t nBufSize, uint64_t nRewindIn) |
520 | 0 | : m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0}) |
521 | 0 | { |
522 | 0 | if (nRewindIn >= nBufSize) Branch (522:13): [True: 0, False: 0]
|
523 | 0 | throw std::ios_base::failure("Rewind limit must be less than buffer size"); |
524 | 0 | } |
525 | | |
526 | | //! check whether we're at the end of the source file |
527 | 0 | bool eof() const { |
528 | 0 | return m_read_pos == nSrcPos && m_src.feof(); Branch (528:16): [True: 0, False: 0]
Branch (528:41): [True: 0, False: 0]
|
529 | 0 | } |
530 | | |
531 | | //! read a number of bytes |
532 | | void read(Span<std::byte> dst) |
533 | 0 | { |
534 | 0 | while (dst.size() > 0) { Branch (534:16): [True: 0, False: 0]
|
535 | 0 | auto [buffer_pointer, length]{AdvanceStream(dst.size())}; |
536 | 0 | memcpy(dst.data(), buffer_pointer, length); |
537 | 0 | dst = dst.subspan(length); |
538 | 0 | } |
539 | 0 | } |
540 | | |
541 | | //! Move the read position ahead in the stream to the given position. |
542 | | //! Use SetPos() to back up in the stream, not SkipTo(). |
543 | | void SkipTo(const uint64_t file_pos) |
544 | 0 | { |
545 | 0 | assert(file_pos >= m_read_pos); |
546 | 0 | while (m_read_pos < file_pos) AdvanceStream(file_pos - m_read_pos); Branch (546:16): [True: 0, False: 0]
|
547 | 0 | } |
548 | | |
549 | | //! return the current reading position |
550 | 0 | uint64_t GetPos() const { |
551 | 0 | return m_read_pos; |
552 | 0 | } |
553 | | |
554 | | //! rewind to a given reading position |
555 | 0 | bool SetPos(uint64_t nPos) { |
556 | 0 | size_t bufsize = vchBuf.size(); |
557 | 0 | if (nPos + bufsize < nSrcPos) { Branch (557:13): [True: 0, False: 0]
|
558 | | // rewinding too far, rewind as far as possible |
559 | 0 | m_read_pos = nSrcPos - bufsize; |
560 | 0 | return false; |
561 | 0 | } |
562 | 0 | if (nPos > nSrcPos) { Branch (562:13): [True: 0, False: 0]
|
563 | | // can't go this far forward, go as far as possible |
564 | 0 | m_read_pos = nSrcPos; |
565 | 0 | return false; |
566 | 0 | } |
567 | 0 | m_read_pos = nPos; |
568 | 0 | return true; |
569 | 0 | } |
570 | | |
571 | | //! prevent reading beyond a certain position |
572 | | //! no argument removes the limit |
573 | 0 | bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) { |
574 | 0 | if (nPos < m_read_pos) Branch (574:13): [True: 0, False: 0]
|
575 | 0 | return false; |
576 | 0 | nReadLimit = nPos; |
577 | 0 | return true; |
578 | 0 | } |
579 | | |
580 | | template<typename T> |
581 | 0 | BufferedFile& operator>>(T&& obj) { |
582 | 0 | ::Unserialize(*this, obj); |
583 | 0 | return (*this); |
584 | 0 | } Unexecuted instantiation: BufferedFile& BufferedFile::operator>><bool&>(bool&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><signed char&>(signed char&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><short&>(short&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><unsigned short&>(unsigned short&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><int&>(int&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><unsigned int&>(unsigned int&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><long&>(long&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><unsigned long&>(unsigned long&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><std::vector<unsigned char, std::allocator<unsigned char> >&>(std::vector<unsigned char, std::allocator<unsigned char> >&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><std::array<unsigned char, 4ul>&>(std::array<unsigned char, 4ul>&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><CBlockHeader&>(CBlockHeader&) Unexecuted instantiation: BufferedFile& BufferedFile::operator>><ParamsWrapper<TransactionSerParams, CBlock> >(ParamsWrapper<TransactionSerParams, CBlock>&&) |
585 | | |
586 | | //! search for a given byte in the stream, and remain positioned on it |
587 | | void FindByte(std::byte byte) |
588 | 0 | { |
589 | | // For best performance, avoid mod operation within the loop. |
590 | 0 | size_t buf_offset{size_t(m_read_pos % uint64_t(vchBuf.size()))}; |
591 | 0 | while (true) { Branch (591:16): [Folded - Ignored]
|
592 | 0 | if (m_read_pos == nSrcPos) { Branch (592:17): [True: 0, False: 0]
|
593 | | // No more bytes available; read from the file into the buffer, |
594 | | // setting nSrcPos to one beyond the end of the new data. |
595 | | // Throws exception if end-of-file reached. |
596 | 0 | Fill(); |
597 | 0 | } |
598 | 0 | const size_t len{std::min<size_t>(vchBuf.size() - buf_offset, nSrcPos - m_read_pos)}; |
599 | 0 | const auto it_start{vchBuf.begin() + buf_offset}; |
600 | 0 | const auto it_find{std::find(it_start, it_start + len, byte)}; |
601 | 0 | const size_t inc{size_t(std::distance(it_start, it_find))}; |
602 | 0 | m_read_pos += inc; |
603 | 0 | if (inc < len) break; Branch (603:17): [True: 0, False: 0]
|
604 | 0 | buf_offset += inc; |
605 | 0 | if (buf_offset >= vchBuf.size()) buf_offset = 0; Branch (605:17): [True: 0, False: 0]
|
606 | 0 | } |
607 | 0 | } |
608 | | }; |
609 | | |
610 | | #endif // BITCOIN_STREAMS_H |