From 2f1b2f4ed044fe005e5a6c1b55e95822e83c16df Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 8 Jan 2020 09:05:44 -0800 Subject: [PATCH] Convert VARINT to the formatter/Using approach --- src/serialize.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/serialize.h b/src/serialize.h index fd8626007a0..56c324c5277 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -468,26 +468,22 @@ public: template static inline Wrapper Using(T&& t) { return Wrapper(t); } -#define VARINT(obj, ...) WrapVarInt<__VA_ARGS__>(REF(obj)) +#define VARINT(obj, ...) Using>(obj) #define COMPACTSIZE(obj) CCompactSize(REF(obj)) #define LIMITED_STRING(obj,n) LimitedString< n >(REF(obj)) -template -class CVarInt +/** Serialization wrapper class for integers in VarInt format. */ +template +struct VarIntFormatter { -protected: - I &n; -public: - explicit CVarInt(I& nIn) : n(nIn) { } - - template - void Serialize(Stream &s) const { - WriteVarInt(s, n); + template void Ser(Stream &s, I v) + { + WriteVarInt::type>(s, v); } - template - void Unserialize(Stream& s) { - n = ReadVarInt(s); + template void Unser(Stream& s, I& v) + { + v = ReadVarInt::type>(s); } }; @@ -572,9 +568,6 @@ public: } }; -template -CVarInt WrapVarInt(I& n) { return CVarInt{n}; } - template BigEndian WrapBigEndian(I& n) { return BigEndian(n); }