diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2020-01-08 09:05:44 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2020-01-13 08:24:44 -0800 |
commit | 2f1b2f4ed044fe005e5a6c1b55e95822e83c16df (patch) | |
tree | 07b73b5085a12693a15fe4e156116057f9b72831 /src/serialize.h | |
parent | ca62563df341786d1d1809a037d8b592924e78c4 (diff) |
Convert VARINT to the formatter/Using approach
Diffstat (limited to 'src/serialize.h')
-rw-r--r-- | src/serialize.h | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/serialize.h b/src/serialize.h index fd8626007a..56c324c527 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -468,26 +468,22 @@ public: template<typename Formatter, typename T> static inline Wrapper<Formatter, T&> Using(T&& t) { return Wrapper<Formatter, T&>(t); } -#define VARINT(obj, ...) WrapVarInt<__VA_ARGS__>(REF(obj)) +#define VARINT(obj, ...) Using<VarIntFormatter<__VA_ARGS__>>(obj) #define COMPACTSIZE(obj) CCompactSize(REF(obj)) #define LIMITED_STRING(obj,n) LimitedString< n >(REF(obj)) -template<VarIntMode Mode, typename I> -class CVarInt +/** Serialization wrapper class for integers in VarInt format. */ +template<VarIntMode Mode=VarIntMode::DEFAULT> +struct VarIntFormatter { -protected: - I &n; -public: - explicit CVarInt(I& nIn) : n(nIn) { } - - template<typename Stream> - void Serialize(Stream &s) const { - WriteVarInt<Stream,Mode,I>(s, n); + template<typename Stream, typename I> void Ser(Stream &s, I v) + { + WriteVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s, v); } - template<typename Stream> - void Unserialize(Stream& s) { - n = ReadVarInt<Stream,Mode,I>(s); + template<typename Stream, typename I> void Unser(Stream& s, I& v) + { + v = ReadVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s); } }; @@ -572,9 +568,6 @@ public: } }; -template<VarIntMode Mode=VarIntMode::DEFAULT, typename I> -CVarInt<Mode, I> WrapVarInt(I& n) { return CVarInt<Mode, I>{n}; } - template<typename I> BigEndian<I> WrapBigEndian(I& n) { return BigEndian<I>(n); } |