/root/bitcoin/src/streams.h
Line | Count | Source |
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/check.h> |
13 | | #include <util/log.h> |
14 | | #include <util/obfuscation.h> |
15 | | #include <util/overflow.h> |
16 | | #include <util/syserror.h> |
17 | | |
18 | | #include <algorithm> |
19 | | #include <cassert> |
20 | | #include <cstddef> |
21 | | #include <cstdint> |
22 | | #include <cstdio> |
23 | | #include <cstring> |
24 | | #include <ios> |
25 | | #include <limits> |
26 | | #include <optional> |
27 | | #include <string> |
28 | | #include <vector> |
29 | | |
30 | | /* Minimal stream for overwriting and/or appending to an existing byte vector |
31 | | * |
32 | | * The referenced vector will grow as necessary |
33 | | */ |
34 | | class VectorWriter |
35 | | { |
36 | | public: |
37 | | /* |
38 | | * @param[in] vchDataIn Referenced byte vector to overwrite/append |
39 | | * @param[in] nPosIn Starting position. Vector index where writes should start. The vector will initially |
40 | | * grow as necessary to max(nPosIn, vec.size()). So to append, use vec.size(). |
41 | | */ |
42 | 472k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn) : vchData{vchDataIn}, nPos{nPosIn} |
43 | 472k | { |
44 | 472k | if(nPos > vchData.size()) |
45 | 0 | vchData.resize(nPos); |
46 | 472k | } |
47 | | /* |
48 | | * (other params same as above) |
49 | | * @param[in] args A list of items to serialize starting at nPosIn. |
50 | | */ |
51 | | template <typename... Args> |
52 | 449k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} |
53 | 449k | { |
54 | 449k | ::SerializeMany(*this, std::forward<Args>(args)...); |
55 | 449k | } VectorWriter::VectorWriter<CBlockHeaderAndShortTxIDs&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, CBlockHeaderAndShortTxIDs&) Line | Count | Source | 52 | 19.3k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 19.3k | { | 54 | 19.3k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 19.3k | } |
VectorWriter::VectorWriter<BlockTransactions&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, BlockTransactions&) Line | Count | Source | 52 | 5.43k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 5.43k | { | 54 | 5.43k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 5.43k | } |
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 | 52 | 36.5k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 36.5k | { | 54 | 36.5k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 36.5k | } |
VectorWriter::VectorWriter<bool&, unsigned long&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, bool&, unsigned long&) Line | Count | Source | 52 | 11.1k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 11.1k | { | 54 | 11.1k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 11.1k | } |
VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CTransaction const>>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, ParamsWrapper<TransactionSerParams, CTransaction const>&&) Line | Count | Source | 52 | 109k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 109k | { | 54 | 109k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 109k | } |
Unexecuted instantiation: VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CBlockHeaderAndShortTxIDs>>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, ParamsWrapper<TransactionSerParams, CBlockHeaderAndShortTxIDs>&&) Unexecuted instantiation: VectorWriter::VectorWriter<ParamsWrapper<TransactionSerParams, CBlock>>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, ParamsWrapper<TransactionSerParams, CBlock>&&) Unexecuted instantiation: VectorWriter::VectorWriter<std::span<std::byte, 18446744073709551615ul>>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, std::span<std::byte, 18446744073709551615ul>&&) Unexecuted instantiation: VectorWriter::VectorWriter<PartiallySignedTransaction const&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, PartiallySignedTransaction const&) Unexecuted instantiation: VectorWriter::VectorWriter<PartiallySignedTransaction&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, PartiallySignedTransaction&) 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 | 52 | 5.74k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 5.74k | { | 54 | 5.74k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 5.74k | } |
VectorWriter::VectorWriter<CMessageHeader&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, CMessageHeader&) Line | Count | Source | 52 | 233k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 233k | { | 54 | 233k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 233k | } |
VectorWriter::VectorWriter<bool, unsigned long const&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, bool&&, unsigned long const&) Line | Count | Source | 52 | 3.88k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 3.88k | { | 54 | 3.88k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 3.88k | } |
VectorWriter::VectorWriter<CBlockHeaderAndShortTxIDs const&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, CBlockHeaderAndShortTxIDs const&) Line | Count | Source | 52 | 83 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 83 | { | 54 | 83 | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 83 | } |
VectorWriter::VectorWriter<std::vector<CInv, std::allocator<CInv>>&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, std::vector<CInv, std::allocator<CInv>>&) Line | Count | Source | 52 | 8.14k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 8.14k | { | 54 | 8.14k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 8.14k | } |
Unexecuted instantiation: VectorWriter::VectorWriter<std::span<std::byte const, 18446744073709551615ul>>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, std::span<std::byte const, 18446744073709551615ul>&&) 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&) VectorWriter::VectorWriter<int const&, unsigned long&, long&, 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&, bool&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, int const&, unsigned long&, long&, 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&, bool&) Line | Count | Source | 52 | 5.68k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 5.68k | { | 54 | 5.68k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 5.68k | } |
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&) VectorWriter::VectorWriter<std::array<std::byte, 168ul> const&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, std::array<std::byte, 168ul> const&) Line | Count | Source | 52 | 488 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 488 | { | 54 | 488 | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 488 | } |
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<CBlockLocator const&, uint256>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, CBlockLocator const&, uint256&&) Line | Count | Source | 52 | 380 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 380 | { | 54 | 380 | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 380 | } |
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>>&&) VectorWriter::VectorWriter<BlockTransactionsRequest&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, BlockTransactionsRequest&) Line | Count | Source | 52 | 197 | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 197 | { | 54 | 197 | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 197 | } |
VectorWriter::VectorWriter<unsigned long&>(std::vector<unsigned char, std::allocator<unsigned char>>&, unsigned long, unsigned long&) Line | Count | Source | 52 | 3.79k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 3.79k | { | 54 | 3.79k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 3.79k | } |
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 | 52 | 5.38k | VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn} | 53 | 5.38k | { | 54 | 5.38k | ::SerializeMany(*this, std::forward<Args>(args)...); | 55 | 5.38k | } |
|
56 | | void write(std::span<const std::byte> src) |
57 | 3.91M | { |
58 | 3.91M | assert(nPos <= vchData.size()); |
59 | 3.91M | size_t nOverwrite = std::min(src.size(), vchData.size() - nPos); |
60 | 3.91M | if (nOverwrite) { |
61 | 0 | memcpy(vchData.data() + nPos, src.data(), nOverwrite); |
62 | 0 | } |
63 | 3.91M | if (nOverwrite < src.size()) { |
64 | 3.91M | vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.data() + src.size())); |
65 | 3.91M | } |
66 | 3.91M | nPos += src.size(); |
67 | 3.91M | } |
68 | | template <typename T> |
69 | | VectorWriter& operator<<(const T& obj) |
70 | 68.6k | { |
71 | 68.6k | ::Serialize(*this, obj); |
72 | 68.6k | return (*this); |
73 | 68.6k | } 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&) VectorWriter& VectorWriter::operator<<<std::span<unsigned char const, 32ul>>(std::span<unsigned char const, 32ul> const&) Line | Count | Source | 70 | 68.6k | { | 71 | 68.6k | ::Serialize(*this, obj); | 72 | 68.6k | return (*this); | 73 | 68.6k | } |
Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<std::set<uint256, std::less<uint256>, std::allocator<uint256>>>(std::set<uint256, std::less<uint256>, std::allocator<uint256>> const&) 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::span<unsigned char const, 18446744073709551615ul>>(std::span<unsigned char const, 18446744073709551615ul> 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<<<unsigned char [5]>(unsigned char const (&) [5]) Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<PSBTInput>(PSBTInput const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<CScript>(CScript const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<PSBTOutput>(PSBTOutput const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<uint256>(uint256 const&) Unexecuted instantiation: VectorWriter& VectorWriter::operator<<<int>(int const&) |
74 | | |
75 | | private: |
76 | | std::vector<unsigned char>& vchData; |
77 | | size_t nPos; |
78 | | }; |
79 | | |
80 | | /** Minimal stream for reading from an existing byte array by std::span. |
81 | | */ |
82 | | class SpanReader |
83 | | { |
84 | | private: |
85 | | std::span<const std::byte> m_data; |
86 | | |
87 | | public: |
88 | | /** |
89 | | * @param[in] data Referenced byte vector to overwrite/append |
90 | | */ |
91 | 0 | explicit SpanReader(std::span<const unsigned char> data) : m_data{std::as_bytes(data)} {} |
92 | 961 | explicit SpanReader(std::span<const std::byte> data) : m_data{data} {} |
93 | | |
94 | | template<typename T> |
95 | | SpanReader& operator>>(T&& obj) |
96 | 961 | { |
97 | 961 | ::Unserialize(*this, obj); |
98 | 961 | return (*this); |
99 | 961 | } SpanReader& SpanReader::operator>><ParamsWrapper<TransactionSerParams, CBlock>>(ParamsWrapper<TransactionSerParams, CBlock>&&) Line | Count | Source | 96 | 961 | { | 97 | 961 | ::Unserialize(*this, obj); | 98 | 961 | return (*this); | 99 | 961 | } |
Unexecuted instantiation: SpanReader& SpanReader::operator>><CBlockHeader&>(CBlockHeader&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CBlockLocator&>(CBlockLocator&) Unexecuted instantiation: SpanReader& SpanReader::operator>><kernel::CBlockFileInfo&>(kernel::CBlockFileInfo&) Unexecuted instantiation: SpanReader& SpanReader::operator>><BlockFilter&>(BlockFilter&) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: SpanReader& SpanReader::operator>><uint256&>(uint256&) 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>><COutPoint&>(COutPoint&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<TransactionSerParams, CMutableTransaction>>(ParamsWrapper<TransactionSerParams, CMutableTransaction>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CDiskBlockIndex&>(CDiskBlockIndex&) 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 int&>>(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned 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>><Coin&>(Coin&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<CAddress::SerParams, AddrInfo>>(ParamsWrapper<CAddress::SerParams, AddrInfo>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CBlockHeaderAndShortTxIDs&>(CBlockHeaderAndShortTxIDs&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CFeeRate&>(CFeeRate&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CMerkleBlock&>(CMerkleBlock&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CPartialMerkleTree&>(CPartialMerkleTree&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CPubKey&>(CPubKey&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CScript&>(CScript&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CTxIn&>(CTxIn&) Unexecuted instantiation: SpanReader& SpanReader::operator>><FlatFilePos&>(FlatFilePos&) Unexecuted instantiation: SpanReader& SpanReader::operator>><KeyOriginInfo&>(KeyOriginInfo&) Unexecuted instantiation: SpanReader& SpanReader::operator>><PartiallySignedTransaction&>(PartiallySignedTransaction&) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned char (&) [5]>(unsigned char (&) [5]) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned char (&) [4]>(unsigned char (&) [4]) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned int&>(unsigned int&) Unexecuted instantiation: SpanReader& SpanReader::operator>><PSBTInput&>(PSBTInput&) Unexecuted instantiation: SpanReader& SpanReader::operator>><XOnlyPubKey&>(XOnlyPubKey&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::set<uint256, std::less<uint256>, std::allocator<uint256>>&>(std::set<uint256, std::less<uint256>, std::allocator<uint256>>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::span<std::byte, 33ul>>(std::span<std::byte, 33ul>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><PSBTOutput&>(PSBTOutput&) Unexecuted instantiation: SpanReader& SpanReader::operator>><PrefilledTransaction&>(PrefilledTransaction&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<TransactionSerParams, CBlock>&>(ParamsWrapper<TransactionSerParams, CBlock>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CTxUndo&>(CTxUndo&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CBlockUndo&>(CBlockUndo&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<CNetAddr::SerParams, CNetAddr>>(ParamsWrapper<CNetAddr::SerParams, CNetAddr>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<CNetAddr::SerParams, CService>>(ParamsWrapper<CNetAddr::SerParams, CService>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CMessageHeader&>(CMessageHeader&) Unexecuted instantiation: SpanReader& SpanReader::operator>><ParamsWrapper<CAddress::SerParams, CAddress>>(ParamsWrapper<CAddress::SerParams, CAddress>&&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CInv&>(CInv&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CBloomFilter&>(CBloomFilter&) Unexecuted instantiation: SpanReader& SpanReader::operator>><Wrapper<TxOutCompression, CTxOut&>&>(Wrapper<TxOutCompression, CTxOut&>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><BlockTransactions&>(BlockTransactions&) Unexecuted instantiation: SpanReader& SpanReader::operator>><BlockTransactionsRequest&>(BlockTransactionsRequest&) Unexecuted instantiation: SpanReader& SpanReader::operator>><node::SnapshotMetadata&>(node::SnapshotMetadata&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::array<unsigned char, 5ul>&>(std::array<unsigned char, 5ul>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><unsigned short&>(unsigned short&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::array<unsigned char, 4ul>&>(std::array<unsigned char, 4ul>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><uint160&>(uint160&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<CBlockHeader, std::allocator<CBlockHeader>>&>(std::vector<CBlockHeader, std::allocator<CBlockHeader>>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CTxOut&>(CTxOut&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<CTxIn, std::allocator<CTxIn>>&>(std::vector<CTxIn, std::allocator<CTxIn>>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<CTxOut, std::allocator<CTxOut>>&>(std::vector<CTxOut, std::allocator<CTxOut>>&) 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>>>>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><Obfuscation&>(Obfuscation&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<std::byte, std::allocator<std::byte>>&>(std::vector<std::byte, std::allocator<std::byte>>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><int&>(int&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::pair<unsigned char, uint256>&>(std::pair<unsigned char, uint256>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::vector<uint256, std::allocator<uint256>>&>(std::vector<uint256, std::allocator<uint256>>&) Unexecuted instantiation: txdb.cpp:SpanReader& SpanReader::operator>><(anonymous namespace)::CoinEntry&>((anonymous namespace)::CoinEntry&) Unexecuted instantiation: SpanReader& SpanReader::operator>><index_util::DBHeightKey&>(index_util::DBHeightKey&) Unexecuted instantiation: blockfilterindex.cpp:SpanReader& SpanReader::operator>><(anonymous namespace)::DBVal&>((anonymous namespace)::DBVal&) Unexecuted instantiation: blockfilterindex.cpp:SpanReader& SpanReader::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: coinstatsindex.cpp:SpanReader& SpanReader::operator>><(anonymous namespace)::DBVal&>((anonymous namespace)::DBVal&) Unexecuted instantiation: SpanReader& SpanReader::operator>><MuHash3072&>(MuHash3072&) Unexecuted instantiation: coinstatsindex.cpp:SpanReader& SpanReader::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><CDiskTxPos&>(CDiskTxPos&) Unexecuted instantiation: SpanReader& SpanReader::operator>><std::pair<unsigned long, unsigned long>&>(std::pair<unsigned long, unsigned long>&) Unexecuted instantiation: SpanReader& SpanReader::operator>><DBKey&>(DBKey&) |
100 | | |
101 | 0 | size_t size() const { return m_data.size(); } |
102 | 0 | bool empty() const { return m_data.empty(); } |
103 | | |
104 | | void read(std::span<std::byte> dst) |
105 | 18.9k | { |
106 | 18.9k | if (dst.size() == 0) { |
107 | 0 | return; |
108 | 0 | } |
109 | | |
110 | | // Read from the beginning of the buffer |
111 | 18.9k | if (dst.size() > m_data.size()) { |
112 | 0 | throw std::ios_base::failure("SpanReader::read(): end of data"); |
113 | 0 | } |
114 | 18.9k | memcpy(dst.data(), m_data.data(), dst.size()); |
115 | 18.9k | m_data = m_data.subspan(dst.size()); |
116 | 18.9k | } |
117 | | |
118 | | void ignore(size_t n) |
119 | 0 | { |
120 | 0 | if (n > m_data.size()) { |
121 | 0 | throw std::ios_base::failure("SpanReader::ignore(): end of data"); |
122 | 0 | } |
123 | 0 | m_data = m_data.subspan(n); |
124 | 0 | } |
125 | | }; |
126 | | |
127 | | /** Minimal stream for writing to an existing span of bytes. |
128 | | */ |
129 | | class SpanWriter |
130 | | { |
131 | | private: |
132 | | std::span<std::byte> m_dest; |
133 | | |
134 | | public: |
135 | 0 | explicit SpanWriter(std::span<std::byte> dest) : m_dest{dest} {} |
136 | | template <typename... Args> |
137 | | SpanWriter(std::span<std::byte> dest, Args&&... args) : SpanWriter{dest} |
138 | | { |
139 | | ::SerializeMany(*this, std::forward<Args>(args)...); |
140 | | } |
141 | | |
142 | | void write(std::span<const std::byte> src) |
143 | 0 | { |
144 | 0 | if (src.size() > m_dest.size()) { |
145 | 0 | throw std::ios_base::failure("SpanWriter::write(): exceeded buffer size"); |
146 | 0 | } |
147 | 0 | memcpy(m_dest.data(), src.data(), src.size()); |
148 | 0 | m_dest = m_dest.subspan(src.size()); |
149 | 0 | } |
150 | | |
151 | | template<typename T> |
152 | | SpanWriter& operator<<(const T& obj) |
153 | | { |
154 | | ::Serialize(*this, obj); |
155 | | return *this; |
156 | | } |
157 | | }; |
158 | | |
159 | | /** Double ended buffer combining vector and stream-like interfaces. |
160 | | * |
161 | | * >> and << read and write unformatted data using the above serialization templates. |
162 | | * Fills with data in linear time; some stringstream implementations take N^2 time. |
163 | | */ |
164 | | class DataStream |
165 | | { |
166 | | protected: |
167 | | using vector_type = SerializeData; |
168 | | vector_type vch; |
169 | | vector_type::size_type m_read_pos{0}; |
170 | | |
171 | | public: |
172 | | typedef vector_type::allocator_type allocator_type; |
173 | | typedef vector_type::size_type size_type; |
174 | | typedef vector_type::difference_type difference_type; |
175 | | typedef vector_type::reference reference; |
176 | | typedef vector_type::const_reference const_reference; |
177 | | typedef vector_type::value_type value_type; |
178 | | typedef vector_type::iterator iterator; |
179 | | typedef vector_type::const_iterator const_iterator; |
180 | | typedef vector_type::reverse_iterator reverse_iterator; |
181 | | |
182 | 821k | explicit DataStream() = default; |
183 | 0 | explicit DataStream(std::span<const uint8_t> sp) : DataStream{std::as_bytes(sp)} {} |
184 | 0 | explicit DataStream(std::span<const value_type> sp) : vch(sp.data(), sp.data() + sp.size()) {} |
185 | | |
186 | | std::string str() const |
187 | 0 | { |
188 | 0 | return std::string{UCharCast(data()), UCharCast(data() + size())}; |
189 | 0 | } |
190 | | |
191 | | // |
192 | | // Vector subset |
193 | | // |
194 | 0 | const_iterator begin() const { return vch.begin() + m_read_pos; } |
195 | 75.7k | iterator begin() { return vch.begin() + m_read_pos; } |
196 | 0 | const_iterator end() const { return vch.end(); } |
197 | 37.8k | iterator end() { return vch.end(); } |
198 | 955k | size_type size() const { return vch.size() - m_read_pos; } |
199 | 18.9k | bool empty() const { return vch.size() == m_read_pos; } |
200 | 385k | void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); } |
201 | 766k | void reserve(size_type n) { vch.reserve(n + m_read_pos); } |
202 | 0 | const_reference operator[](size_type pos) const { return vch[pos + m_read_pos]; } |
203 | 380k | reference operator[](size_type pos) { return vch[pos + m_read_pos]; } |
204 | 765k | void clear() { vch.clear(); m_read_pos = 0; } |
205 | 766k | value_type* data() { return vch.data() + m_read_pos; } |
206 | 0 | const value_type* data() const { return vch.data() + m_read_pos; } |
207 | | |
208 | | // |
209 | | // Stream subset |
210 | | // |
211 | | void read(std::span<value_type> dst) |
212 | 3.41M | { |
213 | 3.41M | if (dst.size() == 0) return0 ; |
214 | | |
215 | | // Read from the beginning of the buffer |
216 | 3.41M | auto next_read_pos{CheckedAdd(m_read_pos, dst.size())}; |
217 | 3.41M | if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) { |
218 | 0 | throw std::ios_base::failure("DataStream::read(): end of data"); |
219 | 0 | } |
220 | 3.41M | memcpy(dst.data(), &vch[m_read_pos], dst.size()); |
221 | 3.41M | if (next_read_pos.value() == vch.size()) { |
222 | | // If fully consumed, reset to empty state. |
223 | 368k | clear(); |
224 | 368k | return; |
225 | 368k | } |
226 | 3.04M | m_read_pos = next_read_pos.value(); |
227 | 3.04M | } |
228 | | |
229 | | void ignore(size_t num_ignore) |
230 | 10.3k | { |
231 | | // Ignore from the beginning of the buffer |
232 | 10.3k | auto next_read_pos{CheckedAdd(m_read_pos, num_ignore)}; |
233 | 10.3k | if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) { |
234 | 0 | throw std::ios_base::failure("DataStream::ignore(): end of data"); |
235 | 0 | } |
236 | 10.3k | if (next_read_pos.value() == vch.size()) { |
237 | | // If all bytes are ignored, reset to empty state. |
238 | 0 | clear(); |
239 | 0 | return; |
240 | 0 | } |
241 | 10.3k | m_read_pos = next_read_pos.value(); |
242 | 10.3k | } |
243 | | |
244 | | void write(std::span<const value_type> src) |
245 | 2.56M | { |
246 | | // Write to the end of the buffer |
247 | 2.56M | vch.insert(vch.end(), src.begin(), src.end()); |
248 | 2.56M | } |
249 | | |
250 | | template<typename T> |
251 | | DataStream& operator<<(const T& obj) |
252 | 1.68M | { |
253 | 1.68M | ::Serialize(*this, obj); |
254 | 1.68M | return (*this); |
255 | 1.68M | } Unexecuted instantiation: DataStream& DataStream::operator<<<AddrMan>(AddrMan const&) Unexecuted instantiation: DataStream& DataStream::operator<<<AddrManDeterministic>(AddrManDeterministic const&) Unexecuted instantiation: DataStream& DataStream::operator<<<BlockFilter>(BlockFilter const&) DataStream& DataStream::operator<<<unsigned char>(unsigned char const&) Line | Count | Source | 252 | 11.1k | { | 253 | 11.1k | ::Serialize(*this, obj); | 254 | 11.1k | return (*this); | 255 | 11.1k | } |
Unexecuted instantiation: DataStream& DataStream::operator<<<uint256>(uint256 const&) DataStream& DataStream::operator<<<std::span<unsigned char const, 32ul>>(std::span<unsigned char const, 32ul> const&) Line | Count | Source | 252 | 829k | { | 253 | 829k | ::Serialize(*this, obj); | 254 | 829k | return (*this); | 255 | 829k | } |
DataStream& DataStream::operator<<<std::vector<unsigned char, std::allocator<unsigned char>>>(std::vector<unsigned char, std::allocator<unsigned char>> const&) Line | Count | Source | 252 | 5.61k | { | 253 | 5.61k | ::Serialize(*this, obj); | 254 | 5.61k | return (*this); | 255 | 5.61k | } |
Unexecuted instantiation: DataStream& DataStream::operator<<<kernel::CBlockFileInfo>(kernel::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<<<std::span<unsigned char const, 18446744073709551615ul>>(std::span<unsigned char const, 18446744073709551615ul> 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 | 252 | 37.8k | { | 253 | 37.8k | ::Serialize(*this, obj); | 254 | 37.8k | return (*this); | 255 | 37.8k | } |
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<<<std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul> 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 | 252 | 37.8k | { | 253 | 37.8k | ::Serialize(*this, obj); | 254 | 37.8k | return (*this); | 255 | 37.8k | } |
Unexecuted instantiation: DataStream& DataStream::operator<<<uint160>(uint160 const&) Unexecuted instantiation: DataStream& DataStream::operator<<<std::span<unsigned char const, 20ul>>(std::span<unsigned char const, 20ul> 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&) 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&) Line | Count | Source | 252 | 2.77k | { | 253 | 2.77k | ::Serialize(*this, obj); | 254 | 2.77k | return (*this); | 255 | 2.77k | } |
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<<<ParamsWrapper<TransactionSerParams, CTransaction const>>(ParamsWrapper<TransactionSerParams, CTransaction const> const&) Unexecuted instantiation: DataStream& DataStream::operator<<<std::span<std::byte const, 18446744073709551615ul>>(std::span<std::byte const, 18446744073709551615ul> 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<<<ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> const>>(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const> const> 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>>, 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>>, 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&) DataStream& DataStream::operator<<<Obfuscation>(Obfuscation const&) Line | Count | Source | 252 | 925 | { | 253 | 925 | ::Serialize(*this, obj); | 254 | 925 | return (*this); | 255 | 925 | } |
DataStream& DataStream::operator<<<std::vector<std::byte, std::allocator<std::byte>>>(std::vector<std::byte, std::allocator<std::byte>> const&) Line | Count | Source | 252 | 925 | { | 253 | 925 | ::Serialize(*this, obj); | 254 | 925 | return (*this); | 255 | 925 | } |
Unexecuted instantiation: DataStream& DataStream::operator<<<CTxOut>(CTxOut const&) DataStream& DataStream::operator<<<std::pair<unsigned char, int>>(std::pair<unsigned char, int> const&) Line | Count | Source | 252 | 1.85k | { | 253 | 1.85k | ::Serialize(*this, obj); | 254 | 1.85k | return (*this); | 255 | 1.85k | } |
DataStream& DataStream::operator<<<std::pair<unsigned char, uint256>>(std::pair<unsigned char, uint256> const&) Line | Count | Source | 252 | 1.85k | { | 253 | 1.85k | ::Serialize(*this, obj); | 254 | 1.85k | return (*this); | 255 | 1.85k | } |
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&) Line | Count | Source | 252 | 925 | { | 253 | 925 | ::Serialize(*this, obj); | 254 | 925 | return (*this); | 255 | 925 | } |
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&) txdb.cpp:DataStream& DataStream::operator<<<(anonymous namespace)::CoinEntry>((anonymous namespace)::CoinEntry const&) Line | Count | Source | 252 | 752k | { | 253 | 752k | ::Serialize(*this, obj); | 254 | 752k | return (*this); | 255 | 752k | } |
Unexecuted instantiation: DataStream& DataStream::operator<<<std::vector<uint256, std::allocator<uint256>>>(std::vector<uint256, std::allocator<uint256>> const&) Unexecuted instantiation: DataStream& DataStream::operator<<<index_util::DBHeightKey>(index_util::DBHeightKey const&) Unexecuted instantiation: DataStream& DataStream::operator<<<index_util::DBHashKey>(index_util::DBHashKey const&) Unexecuted instantiation: blockfilterindex.cpp:DataStream& DataStream::operator<<<std::pair<uint256, (anonymous namespace)::DBVal>>(std::pair<uint256, (anonymous namespace)::DBVal> const&) Unexecuted instantiation: blockfilterindex.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: coinstatsindex.cpp:DataStream& DataStream::operator<<<(anonymous namespace)::DBVal>((anonymous namespace)::DBVal const&) Unexecuted instantiation: DataStream& DataStream::operator<<<MuHash3072>(MuHash3072 const&) Unexecuted instantiation: DataStream& DataStream::operator<<<CDiskTxPos>(CDiskTxPos const&) Unexecuted instantiation: DataStream& DataStream::operator<<<char [12]>(char const (&) [12]) Unexecuted instantiation: DataStream& DataStream::operator<<<std::pair<unsigned long, unsigned long>>(std::pair<unsigned long, unsigned long> const&) Unexecuted instantiation: DataStream& DataStream::operator<<<DBKey>(DBKey const&) Unexecuted instantiation: DataStream& DataStream::operator<<<char [1]>(char const (&) [1]) Unexecuted instantiation: DataStream& DataStream::operator<<<std::pair<unsigned char, unsigned long>>(std::pair<unsigned char, unsigned long> const&) |
256 | | |
257 | | template <typename T> |
258 | | DataStream& operator>>(T&& obj) |
259 | 412k | { |
260 | 412k | ::Unserialize(*this, obj); |
261 | 412k | return (*this); |
262 | 412k | } Unexecuted instantiation: DataStream& DataStream::operator>><AddrManDeterministic&>(AddrManDeterministic&) Unexecuted instantiation: DataStream& DataStream::operator>><CFeeRate&>(CFeeRate&) Unexecuted instantiation: DataStream& DataStream::operator>><COutPoint&>(COutPoint&) Unexecuted instantiation: DataStream& DataStream::operator>><CPubKey&>(CPubKey&) Unexecuted instantiation: DataStream& DataStream::operator>><std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul>&&) 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>><ParamsWrapper<CNetAddr::SerParams, CNetAddr>>(ParamsWrapper<CNetAddr::SerParams, CNetAddr>&&) DataStream& DataStream::operator>><ParamsWrapper<CNetAddr::SerParams, CService>>(ParamsWrapper<CNetAddr::SerParams, CService>&&) Line | Count | Source | 259 | 5.63k | { | 260 | 5.63k | ::Unserialize(*this, obj); | 261 | 5.63k | return (*this); | 262 | 5.63k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, CAddress>>(ParamsWrapper<CAddress::SerParams, CAddress>&&) Unexecuted instantiation: DataStream& DataStream::operator>><uint160&>(uint160&) Unexecuted instantiation: DataStream& DataStream::operator>><uint256&>(uint256&) Unexecuted instantiation: DataStream& DataStream::operator>><BlockTransactionsRequest&>(BlockTransactionsRequest&) DataStream& DataStream::operator>><unsigned long&>(unsigned long&) Line | Count | Source | 259 | 12.1k | { | 260 | 12.1k | ::Unserialize(*this, obj); | 261 | 12.1k | return (*this); | 262 | 12.1k | } |
DataStream& DataStream::operator>><long&>(long&) Line | Count | Source | 259 | 5.63k | { | 260 | 5.63k | ::Unserialize(*this, obj); | 261 | 5.63k | return (*this); | 262 | 5.63k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><unsigned int&>(unsigned int&) DataStream& DataStream::operator>><int&>(int&) Line | Count | Source | 259 | 10.3k | { | 260 | 10.3k | ::Unserialize(*this, obj); | 261 | 10.3k | return (*this); | 262 | 10.3k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><unsigned short&>(unsigned short&) Unexecuted instantiation: DataStream& DataStream::operator>><short&>(short&) Unexecuted instantiation: DataStream& DataStream::operator>><unsigned char&>(unsigned char&) Unexecuted instantiation: DataStream& DataStream::operator>><signed char&>(signed char&) DataStream& DataStream::operator>><bool&>(bool&) Line | Count | Source | 259 | 12.1k | { | 260 | 12.1k | ::Unserialize(*this, obj); | 261 | 12.1k | return (*this); | 262 | 12.1k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><unsigned char (&) [4]>(unsigned char (&) [4]) 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>>&) DataStream& DataStream::operator>><ParamsWrapper<CAddress::SerParams, CNetAddr>>(ParamsWrapper<CAddress::SerParams, CNetAddr>&&) Line | Count | Source | 259 | 5.61k | { | 260 | 5.61k | ::Unserialize(*this, obj); | 261 | 5.61k | return (*this); | 262 | 5.61k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><CScript&>(CScript&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CKeyMetadata&>(wallet::CKeyMetadata&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::WalletDescriptor&>(wallet::WalletDescriptor&) Unexecuted instantiation: DataStream& DataStream::operator>><transaction_identifier<false>&>(transaction_identifier<false>&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CWalletTx&>(wallet::CWalletTx&) DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const>>>(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const>>&&) Line | Count | Source | 259 | 104k | { | 260 | 104k | ::Unserialize(*this, obj); | 261 | 104k | return (*this); | 262 | 104k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<uint256, std::allocator<uint256>>&>(std::vector<uint256, std::allocator<uint256>>&) 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>><CBlockLocator&>(CBlockLocator&) 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>><std::vector<unsigned char, std::allocator<unsigned char>>&>(std::vector<unsigned char, std::allocator<unsigned char>>&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CMasterKey&>(wallet::CMasterKey&) Unexecuted instantiation: DataStream& DataStream::operator>><wallet::CHDChain&>(wallet::CHDChain&) Unexecuted instantiation: DataStream& DataStream::operator>><ParamsWrapper<TransactionSerParams, CBlock>>(ParamsWrapper<TransactionSerParams, CBlock>&&) Unexecuted instantiation: DataStream& DataStream::operator>><Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>>(Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>&&) DataStream& DataStream::operator>><CMessageHeader&>(CMessageHeader&) Line | Count | Source | 259 | 191k | { | 260 | 191k | ::Unserialize(*this, obj); | 261 | 191k | return (*this); | 262 | 191k | } |
DataStream& DataStream::operator>><Wrapper<CustomUintFormatter<8, false>, ServiceFlags&>>(Wrapper<CustomUintFormatter<8, false>, ServiceFlags&>&&) Line | Count | Source | 259 | 5.63k | { | 260 | 5.63k | ::Unserialize(*this, obj); | 261 | 5.63k | return (*this); | 262 | 5.63k | } |
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 | 259 | 4.73k | { | 260 | 4.73k | ::Unserialize(*this, obj); | 261 | 4.73k | return (*this); | 262 | 4.73k | } |
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>>&) DataStream& DataStream::operator>><CBlockHeaderAndShortTxIDs&>(CBlockHeaderAndShortTxIDs&) Line | Count | Source | 259 | 18.2k | { | 260 | 18.2k | ::Unserialize(*this, obj); | 261 | 18.2k | return (*this); | 262 | 18.2k | } |
DataStream& DataStream::operator>><BlockTransactions&>(BlockTransactions&) Line | Count | Source | 259 | 3.89k | { | 260 | 3.89k | ::Unserialize(*this, obj); | 261 | 3.89k | return (*this); | 262 | 3.89k | } |
DataStream& DataStream::operator>><CBlockHeader&>(CBlockHeader&) Line | Count | Source | 259 | 32.0k | { | 260 | 32.0k | ::Unserialize(*this, obj); | 261 | 32.0k | return (*this); | 262 | 32.0k | } |
Unexecuted instantiation: DataStream& DataStream::operator>><CBloomFilter&>(CBloomFilter&) Unexecuted instantiation: DataStream& DataStream::operator>><CDiskBlockIndex&>(CDiskBlockIndex&) Unexecuted instantiation: DataStream& DataStream::operator>><std::vector<COutPoint, std::allocator<COutPoint>>&>(std::vector<COutPoint, std::allocator<COutPoint>>&) 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: blockfilterindex.cpp:DataStream& DataStream::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) Unexecuted instantiation: coinstatsindex.cpp:DataStream& DataStream::operator>><std::pair<uint256, (anonymous namespace)::DBVal>&>(std::pair<uint256, (anonymous namespace)::DBVal>&) |
263 | | |
264 | | /** Compute total memory usage of this object (own memory + any dynamic memory). */ |
265 | | size_t GetMemoryUsage() const noexcept; |
266 | | }; |
267 | | |
268 | | template <typename IStream> |
269 | | class BitStreamReader |
270 | | { |
271 | | private: |
272 | | IStream& m_istream; |
273 | | |
274 | | /// Buffered byte read in from the input stream. A new byte is read into the |
275 | | /// buffer when m_offset reaches 8. |
276 | | uint8_t m_buffer{0}; |
277 | | |
278 | | /// Number of high order bits in m_buffer already returned by previous |
279 | | /// Read() calls. The next bit to be returned is at this offset from the |
280 | | /// most significant bit position. |
281 | | int m_offset{8}; |
282 | | |
283 | | public: |
284 | 0 | explicit BitStreamReader(IStream& istream) : m_istream(istream) {} |
285 | | |
286 | | /** Read the specified number of bits from the stream. The data is returned |
287 | | * in the nbits least significant bits of a 64-bit uint. |
288 | | */ |
289 | 0 | uint64_t Read(int nbits) { |
290 | 0 | if (nbits < 0 || nbits > 64) { |
291 | 0 | throw std::out_of_range("nbits must be between 0 and 64"); |
292 | 0 | } |
293 | | |
294 | 0 | uint64_t data = 0; |
295 | 0 | while (nbits > 0) { |
296 | 0 | if (m_offset == 8) { |
297 | 0 | m_istream >> m_buffer; |
298 | 0 | m_offset = 0; |
299 | 0 | } |
300 | |
|
301 | 0 | int bits = std::min(8 - m_offset, nbits); |
302 | 0 | data <<= bits; |
303 | 0 | data |= static_cast<uint8_t>(m_buffer << m_offset) >> (8 - bits); |
304 | 0 | m_offset += bits; |
305 | 0 | nbits -= bits; |
306 | 0 | } |
307 | 0 | return data; |
308 | 0 | } |
309 | | }; |
310 | | |
311 | | template <typename OStream> |
312 | | class BitStreamWriter |
313 | | { |
314 | | private: |
315 | | OStream& m_ostream; |
316 | | |
317 | | /// Buffered byte waiting to be written to the output stream. The byte is |
318 | | /// written buffer when m_offset reaches 8 or Flush() is called. |
319 | | uint8_t m_buffer{0}; |
320 | | |
321 | | /// Number of high order bits in m_buffer already written by previous |
322 | | /// Write() calls and not yet flushed to the stream. The next bit to be |
323 | | /// written to is at this offset from the most significant bit position. |
324 | | int m_offset{0}; |
325 | | |
326 | | public: |
327 | 0 | explicit BitStreamWriter(OStream& ostream) : m_ostream(ostream) {} |
328 | | |
329 | | ~BitStreamWriter() |
330 | 0 | { |
331 | 0 | Flush(); |
332 | 0 | } |
333 | | |
334 | | /** Write the nbits least significant bits of a 64-bit int to the output |
335 | | * stream. Data is buffered until it completes an octet. |
336 | | */ |
337 | 0 | void Write(uint64_t data, int nbits) { |
338 | 0 | if (nbits < 0 || nbits > 64) { |
339 | 0 | throw std::out_of_range("nbits must be between 0 and 64"); |
340 | 0 | } |
341 | | |
342 | 0 | while (nbits > 0) { |
343 | 0 | int bits = std::min(8 - m_offset, nbits); |
344 | 0 | m_buffer |= (data << (64 - nbits)) >> (64 - 8 + m_offset); |
345 | 0 | m_offset += bits; |
346 | 0 | nbits -= bits; |
347 | |
|
348 | 0 | if (m_offset == 8) { |
349 | 0 | Flush(); |
350 | 0 | } |
351 | 0 | } |
352 | 0 | } |
353 | | |
354 | | /** Flush any unwritten bits to the output stream, padding with 0's to the |
355 | | * next byte boundary. |
356 | | */ |
357 | 0 | void Flush() { |
358 | 0 | if (m_offset == 0) { |
359 | 0 | return; |
360 | 0 | } |
361 | | |
362 | 0 | m_ostream << m_buffer; |
363 | 0 | m_buffer = 0; |
364 | 0 | m_offset = 0; |
365 | 0 | } |
366 | | }; |
367 | | |
368 | | /** Non-refcounted RAII wrapper for FILE* |
369 | | * |
370 | | * Will automatically close the file when it goes out of scope if not null. |
371 | | * If you're returning the file pointer, return file.release(). |
372 | | * If you need to close the file early, use autofile.fclose() instead of fclose(underlying_FILE). |
373 | | * |
374 | | * @note If the file has been written to, then the caller must close it |
375 | | * explicitly with the `fclose()` method, check if it returns an error and treat |
376 | | * such an error as if the `write()` method failed. The OS's `fclose(3)` may |
377 | | * fail to flush to disk data that has been previously written, rendering the |
378 | | * file corrupt. |
379 | | */ |
380 | | class AutoFile |
381 | | { |
382 | | protected: |
383 | | std::FILE* m_file; |
384 | | Obfuscation m_obfuscation; |
385 | | std::optional<int64_t> m_position; |
386 | | bool m_was_written{false}; |
387 | | |
388 | | public: |
389 | | explicit AutoFile(std::FILE* file, const Obfuscation& obfuscation = {}); |
390 | | |
391 | | ~AutoFile() |
392 | 374k | { |
393 | 374k | if (m_was_written) { |
394 | | // Callers that wrote to the file must have closed it explicitly |
395 | | // with the fclose() method and checked that the close succeeded. |
396 | | // This is because here in the destructor we have no way to signal |
397 | | // errors from fclose() which, after write, could mean the file is |
398 | | // corrupted and must be handled properly at the call site. |
399 | | // Destructors in C++ cannot signal an error to the callers because |
400 | | // they do not return a value and are not allowed to throw exceptions. |
401 | 373k | Assume(IsNull()); Line | Count | Source | 128 | 373k | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
402 | 373k | } |
403 | | |
404 | 374k | if (fclose() != 0) { |
405 | 0 | LogError("Failed to close file: %s", SysErrorString(errno));Line | Count | Source | 105 | 0 | #define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__) Line | Count | Source | 97 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(SourceLocation{__func__}, category, level, should_ratelimit, __VA_ARGS__) |
|
|
406 | 0 | } |
407 | 374k | } |
408 | | |
409 | | // Disallow copies |
410 | | AutoFile(const AutoFile&) = delete; |
411 | | AutoFile& operator=(const AutoFile&) = delete; |
412 | | |
413 | 0 | bool feof() const { return std::feof(m_file); } |
414 | | |
415 | | [[nodiscard]] int fclose() |
416 | 747k | { |
417 | 747k | if (auto rel{release()}) return std::fclose(rel)374k ; |
418 | 373k | return 0; |
419 | 747k | } |
420 | | |
421 | | /** Get wrapped FILE* with transfer of ownership. |
422 | | * @note This will invalidate the AutoFile object, and makes it the responsibility of the caller |
423 | | * of this function to clean up the returned FILE*. |
424 | | */ |
425 | | std::FILE* release() |
426 | 747k | { |
427 | 747k | std::FILE* ret{m_file}; |
428 | 747k | m_file = nullptr; |
429 | 747k | return ret; |
430 | 747k | } |
431 | | |
432 | | /** Return true if the wrapped FILE* is nullptr, false otherwise. |
433 | | */ |
434 | 1.12M | bool IsNull() const { return m_file == nullptr; } |
435 | | |
436 | | /** Continue with a different XOR key */ |
437 | 0 | void SetObfuscation(const Obfuscation& obfuscation) { m_obfuscation = obfuscation; } |
438 | | |
439 | | /** Implementation detail, only used internally. */ |
440 | | std::size_t detail_fread(std::span<std::byte> dst); |
441 | | |
442 | | /** Wrapper around fseek(). Will throw if seeking is not possible. */ |
443 | | void seek(int64_t offset, int origin); |
444 | | |
445 | | /** Find position within the file. Will throw if unknown. */ |
446 | | int64_t tell(); |
447 | | |
448 | | /** Return the size of the file. Will throw if unknown. */ |
449 | | int64_t size(); |
450 | | |
451 | | /** Wrapper around FileCommit(). */ |
452 | | bool Commit(); |
453 | | |
454 | | /** Wrapper around TruncateFile(). */ |
455 | | bool Truncate(unsigned size); |
456 | | |
457 | | //! Write a mutable buffer more efficiently than write(), obfuscating the buffer in-place. |
458 | | void write_buffer(std::span<std::byte> src); |
459 | | |
460 | | // |
461 | | // Stream subset |
462 | | // |
463 | | void read(std::span<std::byte> dst); |
464 | | void ignore(size_t nSize); |
465 | | void write(std::span<const std::byte> src); |
466 | | |
467 | | template <typename T> |
468 | | AutoFile& operator<<(const T& obj) |
469 | 0 | { |
470 | 0 | ::Serialize(*this, obj); |
471 | 0 | return *this; |
472 | 0 | } 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<<<std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul> 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<<<std::span<unsigned char const, 32ul>>(std::span<unsigned char const, 32ul> 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<<<std::span<unsigned char const, 18446744073709551615ul>>(std::span<unsigned char const, 18446744073709551615ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<<<std::span<char const, 18446744073709551615ul>>(std::span<char const, 18446744073709551615ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<<<std::array<std::byte, 8ul>>(std::array<std::byte, 8ul> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<<<Obfuscation>(Obfuscation 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<transaction_identifier<false>, long, std::less<transaction_identifier<false>>, std::allocator<std::pair<transaction_identifier<false> const, long>>>>(std::map<transaction_identifier<false>, long, std::less<transaction_identifier<false>>, std::allocator<std::pair<transaction_identifier<false> const, long>>> const&) Unexecuted instantiation: AutoFile& AutoFile::operator<<<std::set<transaction_identifier<false>, std::less<transaction_identifier<false>>, std::allocator<transaction_identifier<false>>>>(std::set<transaction_identifier<false>, std::less<transaction_identifier<false>>, std::allocator<transaction_identifier<false>>> const&) Unexecuted instantiation: block_policy_estimator.cpp:AutoFile& AutoFile::operator<<<Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double const&>>(Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double const&> const&) Unexecuted instantiation: block_policy_estimator.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: block_policy_estimator.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&) |
473 | | |
474 | | template <typename T> |
475 | | AutoFile& operator>>(T&& obj) |
476 | 2.84k | { |
477 | 2.84k | ::Unserialize(*this, obj); |
478 | 2.84k | return *this; |
479 | 2.84k | } 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&) AutoFile& AutoFile::operator>><unsigned int&>(unsigned int&) Line | Count | Source | 476 | 961 | { | 477 | 961 | ::Unserialize(*this, obj); | 478 | 961 | return *this; | 479 | 961 | } |
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>&) AutoFile& AutoFile::operator>><std::array<unsigned char, 4ul>&>(std::array<unsigned char, 4ul>&) Line | Count | Source | 476 | 961 | { | 477 | 961 | ::Unserialize(*this, obj); | 478 | 961 | return *this; | 479 | 961 | } |
Unexecuted instantiation: AutoFile& AutoFile::operator>><uint256&>(uint256&) 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&) Unexecuted instantiation: AutoFile& AutoFile::operator>><Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>>(Wrapper<CustomUintFormatter<1, false>, AddrManImpl::Format&>&&) AutoFile& AutoFile::operator>><std::array<std::byte, 8ul>&>(std::array<std::byte, 8ul>&) Line | Count | Source | 476 | 925 | { | 477 | 925 | ::Unserialize(*this, obj); | 478 | 925 | return *this; | 479 | 925 | } |
Unexecuted instantiation: AutoFile& AutoFile::operator>><Obfuscation&>(Obfuscation&) 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>><ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const>>>(ParamsWrapper<TransactionSerParams, std::shared_ptr<CTransaction const>>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::map<transaction_identifier<false>, long, std::less<transaction_identifier<false>>, std::allocator<std::pair<transaction_identifier<false> const, long>>>&>(std::map<transaction_identifier<false>, long, std::less<transaction_identifier<false>>, std::allocator<std::pair<transaction_identifier<false> const, long>>>&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::set<transaction_identifier<false>, std::less<transaction_identifier<false>>, std::allocator<transaction_identifier<false>>>&>(std::set<transaction_identifier<false>, std::less<transaction_identifier<false>>, std::allocator<transaction_identifier<false>>>&) Unexecuted instantiation: block_policy_estimator.cpp:AutoFile& AutoFile::operator>><Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double&>>(Wrapper<(anonymous namespace)::EncodedDoubleFormatter, double&>&&) Unexecuted instantiation: block_policy_estimator.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: block_policy_estimator.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>><std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul>&&) Unexecuted instantiation: AutoFile& AutoFile::operator>><std::byte&>(std::byte&) Unexecuted instantiation: AutoFile& AutoFile::operator>><CBlockHeader&>(CBlockHeader&) |
480 | | }; |
481 | | |
482 | | using DataBuffer = std::vector<std::byte>; |
483 | | |
484 | | /** Wrapper around an AutoFile& that implements a ring buffer to |
485 | | * deserialize from. It guarantees the ability to rewind a given number of bytes. |
486 | | * |
487 | | * Will automatically close the file when it goes out of scope if not null. |
488 | | * If you need to close the file early, use file.fclose() instead of fclose(file). |
489 | | */ |
490 | | class BufferedFile |
491 | | { |
492 | | private: |
493 | | AutoFile& m_src; |
494 | | uint64_t nSrcPos{0}; //!< how many bytes have been read from source |
495 | | uint64_t m_read_pos{0}; //!< how many bytes have been read from this |
496 | | uint64_t nReadLimit; //!< up to which position we're allowed to read |
497 | | uint64_t nRewind; //!< how many bytes we guarantee to rewind |
498 | | DataBuffer vchBuf; |
499 | | |
500 | | //! read data from the source to fill the buffer |
501 | 0 | bool Fill() { |
502 | 0 | unsigned int pos = nSrcPos % vchBuf.size(); |
503 | 0 | unsigned int readNow = vchBuf.size() - pos; |
504 | 0 | unsigned int nAvail = vchBuf.size() - (nSrcPos - m_read_pos) - nRewind; |
505 | 0 | if (nAvail < readNow) |
506 | 0 | readNow = nAvail; |
507 | 0 | if (readNow == 0) |
508 | 0 | return false; |
509 | 0 | size_t nBytes{m_src.detail_fread(std::span{vchBuf}.subspan(pos, readNow))}; |
510 | 0 | if (nBytes == 0) { |
511 | 0 | throw std::ios_base::failure{m_src.feof() ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed"}; |
512 | 0 | } |
513 | 0 | nSrcPos += nBytes; |
514 | 0 | return true; |
515 | 0 | } |
516 | | |
517 | | //! Advance the stream's read pointer (m_read_pos) by up to 'length' bytes, |
518 | | //! filling the buffer from the file so that at least one byte is available. |
519 | | //! Return a pointer to the available buffer data and the number of bytes |
520 | | //! (which may be less than the requested length) that may be accessed |
521 | | //! beginning at that pointer. |
522 | | std::pair<std::byte*, size_t> AdvanceStream(size_t length) |
523 | 0 | { |
524 | 0 | assert(m_read_pos <= nSrcPos); |
525 | 0 | if (m_read_pos + length > nReadLimit) { |
526 | 0 | throw std::ios_base::failure("Attempt to position past buffer limit"); |
527 | 0 | } |
528 | | // If there are no bytes available, read from the file. |
529 | 0 | if (m_read_pos == nSrcPos && length > 0) Fill(); |
530 | |
|
531 | 0 | size_t buffer_offset{static_cast<size_t>(m_read_pos % vchBuf.size())}; |
532 | 0 | size_t buffer_available{static_cast<size_t>(vchBuf.size() - buffer_offset)}; |
533 | 0 | size_t bytes_until_source_pos{static_cast<size_t>(nSrcPos - m_read_pos)}; |
534 | 0 | size_t advance{std::min({length, buffer_available, bytes_until_source_pos})}; |
535 | 0 | m_read_pos += advance; |
536 | 0 | return std::make_pair(&vchBuf[buffer_offset], advance); |
537 | 0 | } |
538 | | |
539 | | public: |
540 | | BufferedFile(AutoFile& file LIFETIMEBOUND, uint64_t nBufSize, uint64_t nRewindIn) |
541 | 0 | : m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0}) |
542 | 0 | { |
543 | 0 | if (nRewindIn >= nBufSize) |
544 | 0 | throw std::ios_base::failure("Rewind limit must be less than buffer size"); |
545 | 0 | } |
546 | | |
547 | | //! check whether we're at the end of the source file |
548 | 0 | bool eof() const { |
549 | 0 | return m_read_pos == nSrcPos && m_src.feof(); |
550 | 0 | } |
551 | | |
552 | | //! read a number of bytes |
553 | | void read(std::span<std::byte> dst) |
554 | 0 | { |
555 | 0 | while (dst.size() > 0) { |
556 | 0 | auto [buffer_pointer, length]{AdvanceStream(dst.size())}; |
557 | 0 | memcpy(dst.data(), buffer_pointer, length); |
558 | 0 | dst = dst.subspan(length); |
559 | 0 | } |
560 | 0 | } |
561 | | |
562 | | //! Move the read position ahead in the stream to the given position. |
563 | | //! Use SetPos() to back up in the stream, not SkipTo(). |
564 | | void SkipTo(const uint64_t file_pos) |
565 | 0 | { |
566 | 0 | assert(file_pos >= m_read_pos); |
567 | 0 | while (m_read_pos < file_pos) AdvanceStream(file_pos - m_read_pos); |
568 | 0 | } |
569 | | |
570 | | //! return the current reading position |
571 | 0 | uint64_t GetPos() const { |
572 | 0 | return m_read_pos; |
573 | 0 | } |
574 | | |
575 | | //! rewind to a given reading position |
576 | 0 | bool SetPos(uint64_t nPos) { |
577 | 0 | size_t bufsize = vchBuf.size(); |
578 | 0 | if (nPos + bufsize < nSrcPos) { |
579 | | // rewinding too far, rewind as far as possible |
580 | 0 | m_read_pos = nSrcPos - bufsize; |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | if (nPos > nSrcPos) { |
584 | | // can't go this far forward, go as far as possible |
585 | 0 | m_read_pos = nSrcPos; |
586 | 0 | return false; |
587 | 0 | } |
588 | 0 | m_read_pos = nPos; |
589 | 0 | return true; |
590 | 0 | } |
591 | | |
592 | | //! prevent reading beyond a certain position |
593 | | //! no argument removes the limit |
594 | 0 | bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) { |
595 | 0 | if (nPos < m_read_pos) |
596 | 0 | return false; |
597 | 0 | nReadLimit = nPos; |
598 | 0 | return true; |
599 | 0 | } |
600 | | |
601 | | template<typename T> |
602 | 0 | BufferedFile& operator>>(T&& obj) { |
603 | 0 | ::Unserialize(*this, obj); |
604 | 0 | return (*this); |
605 | 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>&&) |
606 | | |
607 | | //! search for a given byte in the stream, and remain positioned on it |
608 | | void FindByte(std::byte byte) |
609 | 0 | { |
610 | | // For best performance, avoid mod operation within the loop. |
611 | 0 | size_t buf_offset{size_t(m_read_pos % uint64_t(vchBuf.size()))}; |
612 | 0 | while (true) { |
613 | 0 | if (m_read_pos == nSrcPos) { |
614 | | // No more bytes available; read from the file into the buffer, |
615 | | // setting nSrcPos to one beyond the end of the new data. |
616 | | // Throws exception if end-of-file reached. |
617 | 0 | Fill(); |
618 | 0 | } |
619 | 0 | const size_t len{std::min<size_t>(vchBuf.size() - buf_offset, nSrcPos - m_read_pos)}; |
620 | 0 | const auto it_start{vchBuf.begin() + buf_offset}; |
621 | 0 | const auto it_find{std::find(it_start, it_start + len, byte)}; |
622 | 0 | const size_t inc{size_t(std::distance(it_start, it_find))}; |
623 | 0 | m_read_pos += inc; |
624 | 0 | if (inc < len) break; |
625 | 0 | buf_offset += inc; |
626 | 0 | if (buf_offset >= vchBuf.size()) buf_offset = 0; |
627 | 0 | } |
628 | 0 | } |
629 | | }; |
630 | | |
631 | | /** |
632 | | * Wrapper that buffers reads from an underlying stream. |
633 | | * Requires underlying stream to support read() and detail_fread() calls |
634 | | * to support fixed-size and variable-sized reads, respectively. |
635 | | */ |
636 | | template <typename S> |
637 | | class BufferedReader |
638 | | { |
639 | | S& m_src; |
640 | | DataBuffer m_buf; |
641 | | size_t m_buf_pos; |
642 | | |
643 | | public: |
644 | | //! Requires stream ownership to prevent leaving the stream at an unexpected position after buffered reads. |
645 | | explicit BufferedReader(S&& stream LIFETIMEBOUND, size_t size = 1 << 16) |
646 | | requires std::is_rvalue_reference_v<S&&> |
647 | 0 | : m_src{stream}, m_buf(size), m_buf_pos{size} {} |
648 | | |
649 | | void read(std::span<std::byte> dst) |
650 | 0 | { |
651 | 0 | if (const auto available{std::min(dst.size(), m_buf.size() - m_buf_pos)}) { |
652 | 0 | std::copy_n(m_buf.begin() + m_buf_pos, available, dst.begin()); |
653 | 0 | m_buf_pos += available; |
654 | 0 | dst = dst.subspan(available); |
655 | 0 | } |
656 | 0 | if (dst.size()) { |
657 | 0 | assert(m_buf_pos == m_buf.size()); |
658 | 0 | m_src.read(dst); |
659 | |
|
660 | 0 | m_buf_pos = 0; |
661 | 0 | m_buf.resize(m_src.detail_fread(m_buf)); |
662 | 0 | } |
663 | 0 | } |
664 | | |
665 | | template <typename T> |
666 | | BufferedReader& operator>>(T&& obj) |
667 | 0 | { |
668 | 0 | Unserialize(*this, obj); |
669 | 0 | return *this; |
670 | 0 | } |
671 | | }; |
672 | | |
673 | | /** |
674 | | * Wrapper that buffers writes to an underlying stream. |
675 | | * Requires underlying stream to support write_buffer() method |
676 | | * for efficient buffer flushing and obfuscation. |
677 | | */ |
678 | | template <typename S> |
679 | | class BufferedWriter |
680 | | { |
681 | | S& m_dst; |
682 | | DataBuffer m_buf; |
683 | | size_t m_buf_pos{0}; |
684 | | |
685 | | public: |
686 | 373k | explicit BufferedWriter(S& stream LIFETIMEBOUND, size_t size = 1 << 16) : m_dst{stream}, m_buf(size) {} |
687 | | |
688 | 373k | ~BufferedWriter() { flush(); } |
689 | | |
690 | | void flush() |
691 | 373k | { |
692 | 373k | if (m_buf_pos) m_dst.write_buffer(std::span{m_buf}.first(m_buf_pos)); |
693 | 373k | m_buf_pos = 0; |
694 | 373k | } |
695 | | |
696 | | void write(std::span<const std::byte> src) |
697 | 6.17M | { |
698 | 12.3M | while (const auto available{std::min(src.size(), m_buf.size() - m_buf_pos)}) { |
699 | 6.17M | std::copy_n(src.begin(), available, m_buf.begin() + m_buf_pos); |
700 | 6.17M | m_buf_pos += available; |
701 | 6.17M | if (m_buf_pos == m_buf.size()) flush()0 ; |
702 | 6.17M | src = src.subspan(available); |
703 | 6.17M | } |
704 | 6.17M | } |
705 | | |
706 | | template <typename T> |
707 | | BufferedWriter& operator<<(const T& obj) |
708 | 1.49M | { |
709 | 1.49M | Serialize(*this, obj); |
710 | 1.49M | return *this; |
711 | 1.49M | } BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<std::array<unsigned char, 4ul>>(std::array<unsigned char, 4ul> const&) Line | Count | Source | 708 | 373k | { | 709 | 373k | Serialize(*this, obj); | 710 | 373k | return *this; | 711 | 373k | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<unsigned int>(unsigned int const&) Line | Count | Source | 708 | 373k | { | 709 | 373k | Serialize(*this, obj); | 710 | 373k | return *this; | 711 | 373k | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<CBlockUndo>(CBlockUndo const&) Line | Count | Source | 708 | 185k | { | 709 | 185k | Serialize(*this, obj); | 710 | 185k | return *this; | 711 | 185k | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&>>(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned long&> const&) Line | Count | Source | 708 | 247 | { | 709 | 247 | Serialize(*this, obj); | 710 | 247 | return *this; | 711 | 247 | } |
Unexecuted instantiation: BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<std::span<unsigned char, 18446744073709551615ul>>(std::span<unsigned char, 18446744073709551615ul> const&) BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&>>(Wrapper<VarIntFormatter<(VarIntMode)0>, unsigned int&> const&) Line | Count | Source | 708 | 247 | { | 709 | 247 | Serialize(*this, obj); | 710 | 247 | return *this; | 711 | 247 | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<std::span<unsigned char const, 18446744073709551615ul>>(std::span<unsigned char const, 18446744073709551615ul> const&) Line | Count | Source | 708 | 247 | { | 709 | 247 | Serialize(*this, obj); | 710 | 247 | return *this; | 711 | 247 | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<uint256>(uint256 const&) Line | Count | Source | 708 | 185k | { | 709 | 185k | Serialize(*this, obj); | 710 | 185k | return *this; | 711 | 185k | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<std::span<unsigned char const, 32ul>>(std::span<unsigned char const, 32ul> const&) Line | Count | Source | 708 | 185k | { | 709 | 185k | Serialize(*this, obj); | 710 | 185k | return *this; | 711 | 185k | } |
BufferedWriter<AutoFile>& BufferedWriter<AutoFile>::operator<<<ParamsWrapper<TransactionSerParams, CBlock const>>(ParamsWrapper<TransactionSerParams, CBlock const> const&) Line | Count | Source | 708 | 187k | { | 709 | 187k | Serialize(*this, obj); | 710 | 187k | return *this; | 711 | 187k | } |
|
712 | | }; |
713 | | |
714 | | #endif // BITCOIN_STREAMS_H |