From 5249daca5a8c4ebdc6c9a3090af0e1bdddcfba1b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 18 May 2016 13:11:42 -0700 Subject: Add COMPACTSIZE wrapper similar to VARINT for serialization --- src/serialize.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/serialize.h b/src/serialize.h index 5c2db9d332..378ed39074 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -373,6 +373,7 @@ I ReadVarInt(Stream& is) #define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj))) #define VARINT(obj) REF(WrapVarInt(REF(obj))) +#define COMPACTSIZE(obj) REF(CCompactSize(REF(obj))) #define LIMITED_STRING(obj,n) REF(LimitedString< n >(REF(obj))) /** @@ -443,6 +444,28 @@ public: } }; +class CCompactSize +{ +protected: + uint64_t &n; +public: + CCompactSize(uint64_t& nIn) : n(nIn) { } + + unsigned int GetSerializeSize(int, int) const { + return GetSizeOfCompactSize(n); + } + + template + void Serialize(Stream &s, int, int) const { + WriteCompactSize(s, n); + } + + template + void Unserialize(Stream& s, int, int) { + n = ReadCompactSize(s); + } +}; + template class LimitedString { -- cgit v1.2.3