diff options
author | Matt Corallo <git@bluematt.me> | 2016-05-18 13:11:42 -0700 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2016-06-19 01:34:57 -0700 |
commit | 5249daca5a8c4ebdc6c9a3090af0e1bdddcfba1b (patch) | |
tree | e96db6dfe756393dde1cd4fde99c50b89ad295f5 | |
parent | cbda71cf04ef6f2abe6eaa56c3140a6f5cff4feb (diff) |
Add COMPACTSIZE wrapper similar to VARINT for serialization
-rw-r--r-- | src/serialize.h | 23 |
1 files changed, 23 insertions, 0 deletions
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<typename Stream> + void Serialize(Stream &s, int, int) const { + WriteCompactSize<Stream>(s, n); + } + + template<typename Stream> + void Unserialize(Stream& s, int, int) { + n = ReadCompactSize<Stream>(s); + } +}; + template<size_t Limit> class LimitedString { |