Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | |||||
* where T is const during serialization, and non-const during deserialization, | * where T is const during serialization, and non-const during deserialization, | ||||
* which maintains const correctness. | * which maintains const correctness. | ||||
*/ | */ | ||||
template <typename Formatter, typename T> | template <typename Formatter, typename T> | ||||
static inline Wrapper<Formatter, T &> Using(T &&t) { | static inline Wrapper<Formatter, T &> Using(T &&t) { | ||||
return Wrapper<Formatter, T &>(t); | return Wrapper<Formatter, T &>(t); | ||||
} | } | ||||
#define VARINT(obj, ...) Using<VarIntFormatter<__VA_ARGS__>>(obj) | #define VARINT_MODE(obj, mode) Using<VarIntFormatter<mode>>(obj) | ||||
#define VARINT(obj) Using<VarIntFormatter<VarIntMode::DEFAULT>>(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)) | ||||
/** | /** | ||||
* Serialization wrapper class for integers in VarInt format. | * Serialization wrapper class for integers in VarInt format. | ||||
*/ | */ | ||||
template <VarIntMode Mode = VarIntMode::DEFAULT> struct VarIntFormatter { | template <VarIntMode Mode> struct VarIntFormatter { | ||||
template <typename Stream, typename I> void Ser(Stream &s, I v) { | template <typename Stream, typename I> void Ser(Stream &s, I v) { | ||||
WriteVarInt<Stream, Mode, typename std::remove_cv<I>::type>(s, v); | WriteVarInt<Stream, Mode, typename std::remove_cv<I>::type>(s, v); | ||||
} | } | ||||
template <typename Stream, typename I> void Unser(Stream &s, I &v) { | template <typename Stream, typename I> void Unser(Stream &s, I &v) { | ||||
v = ReadVarInt<Stream, Mode, typename std::remove_cv<I>::type>(s); | v = ReadVarInt<Stream, Mode, typename std::remove_cv<I>::type>(s); | ||||
} | } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 550 Lines • Show Last 20 Lines |