diff options
-rw-r--r-- | src/blockencodings.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/blockencodings.h b/src/blockencodings.h index 55ed8989bb..606c11b417 100644 --- a/src/blockencodings.h +++ b/src/blockencodings.h @@ -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 |