mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-15 20:29:59 +01:00
Add DifferenceFormatter
This commit is contained in:
parent
56dd9f04c7
commit
10633398f2
1 changed files with 22 additions and 0 deletions
|
@ -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 {
|
class BlockTransactionsRequest {
|
||||||
public:
|
public:
|
||||||
// A BlockTransactionsRequest message
|
// A BlockTransactionsRequest message
|
||||||
|
|
Loading…
Add table
Reference in a new issue