@@ -468,26 +468,22 @@ class Wrapper
468
468
template <typename Formatter, typename T>
469
469
static inline Wrapper<Formatter, T&> Using (T&& t) { return Wrapper<Formatter, T&>(t); }
470
470
471
- #define VARINT (obj, ...) WrapVarInt< __VA_ARGS__>(REF( obj) )
471
+ #define VARINT (obj, ...) Using<VarIntFormatter< __VA_ARGS__>>( obj)
472
472
#define COMPACTSIZE (obj ) CCompactSize(REF(obj))
473
473
#define LIMITED_STRING (obj,n ) LimitedString< n >(REF(obj))
474
474
475
- template <VarIntMode Mode, typename I>
476
- class CVarInt
475
+ /* * Serialization wrapper class for integers in VarInt format. */
476
+ template <VarIntMode Mode=VarIntMode::DEFAULT>
477
+ struct VarIntFormatter
477
478
{
478
- protected:
479
- I &n;
480
- public:
481
- explicit CVarInt (I& nIn) : n(nIn) { }
482
-
483
- template <typename Stream>
484
- void Serialize (Stream &s) const {
485
- WriteVarInt<Stream,Mode,I>(s, n);
479
+ template <typename Stream, typename I> void Ser (Stream &s, I v)
480
+ {
481
+ WriteVarInt<Stream,Mode,typename std::remove_cv<I>::type>(s, v);
486
482
}
487
483
488
- template <typename Stream>
489
- void Unserialize (Stream& s) {
490
- n = ReadVarInt<Stream,Mode,I >(s);
484
+ template <typename Stream, typename I> void Unser (Stream& s, I& v)
485
+ {
486
+ v = ReadVarInt<Stream,Mode,typename std::remove_cv<I>::type >(s);
491
487
}
492
488
};
493
489
@@ -572,9 +568,6 @@ class LimitedString
572
568
}
573
569
};
574
570
575
- template <VarIntMode Mode=VarIntMode::DEFAULT, typename I>
576
- CVarInt<Mode, I> WrapVarInt (I& n) { return CVarInt<Mode, I>{n}; }
577
-
578
571
template <typename I>
579
572
BigEndian<I> WrapBigEndian (I& n) { return BigEndian<I>(n); }
580
573
0 commit comments