mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-25 11:20:49 +02:00
Add DifferenceFormatter
This commit is contained in:
parent
56dd9f04c7
commit
10633398f2
@ -25,6 +25,28 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DifferenceFormatter
|
||||
{
|
||||
uint64_t m_shift = 0;
|
||||
|
||||
public:
|
||||
template<typename Stream, typename I>
|
||||
void Ser(Stream& s, I v)
|
||||
{
|
||||
if (v < m_shift || v >= std::numeric_limits<uint64_t>::max()) throw std::ios_base::failure("differential value overflow");
|
||||
WriteCompactSize(s, v - m_shift);
|
||||
m_shift = uint64_t(v) + 1;
|
||||
}
|
||||
template<typename Stream, typename I>
|
||||
void Unser(Stream& s, I& v)
|
||||
{
|
||||
uint64_t n = ReadCompactSize(s);
|
||||
m_shift += n;
|
||||
if (m_shift < n || m_shift >= std::numeric_limits<uint64_t>::max() || m_shift < std::numeric_limits<I>::min() || m_shift > std::numeric_limits<I>::max()) throw std::ios_base::failure("differential value overflow");
|
||||
v = I(m_shift++);
|
||||
}
|
||||
};
|
||||
|
||||
class BlockTransactionsRequest {
|
||||
public:
|
||||
// A BlockTransactionsRequest message
|
||||
|
Loading…
x
Reference in New Issue
Block a user