Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 375 Lines • ▼ Show 20 Lines | while (true) { | ||||
} | } | ||||
if (n == std::numeric_limits<I>::max()) { | if (n == std::numeric_limits<I>::max()) { | ||||
throw std::ios_base::failure("ReadVarInt(): size too large"); | throw std::ios_base::failure("ReadVarInt(): size too large"); | ||||
} | } | ||||
n++; | n++; | ||||
} | } | ||||
} | } | ||||
#define FLATDATA(obj) \ | #define FLATDATA(obj) CFlatData((char *)&(obj), (char *)&(obj) + sizeof(obj)) | ||||
REF(CFlatData((char *)&(obj), (char *)&(obj) + sizeof(obj))) | #define VARINT(obj) WrapVarInt(REF(obj)) | ||||
#define VARINT(obj) REF(WrapVarInt(REF(obj))) | #define COMPACTSIZE(obj) CCompactSize(REF(obj)) | ||||
#define COMPACTSIZE(obj) REF(CCompactSize(REF(obj))) | #define LIMITED_STRING(obj, n) LimitedString<n>(REF(obj)) | ||||
#define LIMITED_STRING(obj, n) REF(LimitedString<n>(REF(obj))) | |||||
/** | /** | ||||
* Wrapper for serializing arrays and POD. | * Wrapper for serializing arrays and POD. | ||||
*/ | */ | ||||
class CFlatData { | class CFlatData { | ||||
protected: | protected: | ||||
char *pbegin; | char *pbegin; | ||||
char *pend; | char *pend; | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | |||||
* function. | * function. | ||||
*/ | */ | ||||
template <typename Stream, typename T> | template <typename Stream, typename T> | ||||
inline void Serialize(Stream &os, const T &a) { | inline void Serialize(Stream &os, const T &a) { | ||||
a.Serialize(os); | a.Serialize(os); | ||||
} | } | ||||
template <typename Stream, typename T> | template <typename Stream, typename T> | ||||
inline void Unserialize(Stream &is, T &a) { | inline void Unserialize(Stream &is, T &&a) { | ||||
a.Unserialize(is); | a.Unserialize(is); | ||||
} | } | ||||
/** | /** | ||||
* string | * string | ||||
*/ | */ | ||||
template <typename Stream, typename C> | template <typename Stream, typename C> | ||||
void Serialize(Stream &os, const std::basic_string<C> &str) { | void Serialize(Stream &os, const std::basic_string<C> &str) { | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | public: | ||||
int GetVersion() const { return nVersion; } | int GetVersion() const { return nVersion; } | ||||
int GetType() const { return nType; } | int GetType() const { return nType; } | ||||
}; | }; | ||||
template <typename Stream> void SerializeMany(Stream &s) {} | template <typename Stream> void SerializeMany(Stream &s) {} | ||||
template <typename Stream, typename Arg, typename... Args> | template <typename Stream, typename Arg, typename... Args> | ||||
void SerializeMany(Stream &s, Arg &&arg, Args &&... args) { | void SerializeMany(Stream &s, const Arg &arg, const Args &... args) { | ||||
::Serialize(s, std::forward<Arg>(arg)); | ::Serialize(s, arg); | ||||
::SerializeMany(s, std::forward<Args>(args)...); | ::SerializeMany(s, args...); | ||||
} | } | ||||
template <typename Stream> inline void UnserializeMany(Stream &s) {} | template <typename Stream> inline void UnserializeMany(Stream &s) {} | ||||
template <typename Stream, typename Arg, typename... Args> | template <typename Stream, typename Arg, typename... Args> | ||||
inline void UnserializeMany(Stream &s, Arg &arg, Args &... args) { | inline void UnserializeMany(Stream &s, Arg &&arg, Args &&... args) { | ||||
::Unserialize(s, arg); | ::Unserialize(s, arg); | ||||
::UnserializeMany(s, args...); | ::UnserializeMany(s, args...); | ||||
} | } | ||||
template <typename Stream, typename... Args> | template <typename Stream, typename... Args> | ||||
inline void SerReadWriteMany(Stream &s, CSerActionSerialize ser_action, | inline void SerReadWriteMany(Stream &s, CSerActionSerialize ser_action, | ||||
Args &&... args) { | const Args &... args) { | ||||
::SerializeMany(s, std::forward<Args>(args)...); | ::SerializeMany(s, args...); | ||||
} | } | ||||
template <typename Stream, typename... Args> | template <typename Stream, typename... Args> | ||||
inline void SerReadWriteMany(Stream &s, CSerActionUnserialize ser_action, | inline void SerReadWriteMany(Stream &s, CSerActionUnserialize ser_action, | ||||
Args &... args) { | Args &&... args) { | ||||
::UnserializeMany(s, args...); | ::UnserializeMany(s, args...); | ||||
} | } | ||||
template <typename I> inline void WriteVarInt(CSizeComputer &s, I n) { | template <typename I> inline void WriteVarInt(CSizeComputer &s, I n) { | ||||
s.seek(GetSizeOfVarInt<I>(n)); | s.seek(GetSizeOfVarInt<I>(n)); | ||||
} | } | ||||
inline void WriteCompactSize(CSizeComputer &s, uint64_t nSize) { | inline void WriteCompactSize(CSizeComputer &s, uint64_t nSize) { | ||||
Show All 14 Lines |