mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
Convert VARINT to the formatter/Using approach
This commit is contained in:
parent
ca62563df3
commit
2f1b2f4ed0
@ -468,26 +468,22 @@ public:
|
|||||||
template<typename Formatter, typename T>
|
template<typename Formatter, typename T>
|
||||||
static inline Wrapper<Formatter, T&> Using(T&& t) { return Wrapper<Formatter, T&>(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 COMPACTSIZE(obj) CCompactSize(REF(obj))
|
||||||
#define LIMITED_STRING(obj,n) LimitedString< n >(REF(obj))
|
#define LIMITED_STRING(obj,n) LimitedString< n >(REF(obj))
|
||||||
|
|
||||||
template<VarIntMode Mode, typename I>
|
/** Serialization wrapper class for integers in VarInt format. */
|
||||||
class CVarInt
|
template<VarIntMode Mode=VarIntMode::DEFAULT>
|
||||||
|
struct VarIntFormatter
|
||||||
{
|
{
|
||||||
protected:
|
template<typename Stream, typename I> void Ser(Stream &s, I v)
|
||||||
I &n;
|
{
|
||||||
public:
|
WriteVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s, v);
|
||||||
explicit CVarInt(I& nIn) : n(nIn) { }
|
|
||||||
|
|
||||||
template<typename Stream>
|
|
||||||
void Serialize(Stream &s) const {
|
|
||||||
WriteVarInt<Stream,Mode,I>(s, n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream, typename I> void Unser(Stream& s, I& v)
|
||||||
void Unserialize(Stream& s) {
|
{
|
||||||
n = ReadVarInt<Stream,Mode,I>(s);
|
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>
|
template<typename I>
|
||||||
BigEndian<I> WrapBigEndian(I& n) { return BigEndian<I>(n); }
|
BigEndian<I> WrapBigEndian(I& n) { return BigEndian<I>(n); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user