Skip to content

Commit

Permalink
Convert VARINT to the formatter/Using approach
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and furszy committed Jul 3, 2021
1 parent 39c58a1 commit bbfc55c
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,27 +496,22 @@ class Wrapper
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:
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);
}
};

Expand Down Expand Up @@ -602,9 +597,6 @@ class LimitedString
}
};

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); }

Expand Down

0 comments on commit bbfc55c

Please sign in to comment.