Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Used to acquire a non-const pointer "this" to generate bodies of const | * Used to acquire a non-const pointer "this" to generate bodies of const | ||||
* serialization operations from a template | * serialization operations from a template | ||||
*/ | */ | ||||
template <typename T> inline T *NCONST_PTR(const T *val) { | template <typename T> inline T *NCONST_PTR(const T *val) { | ||||
return const_cast<T *>(val); | return const_cast<T *>(val); | ||||
} | } | ||||
/* | /** | ||||
* Lowest-level serialization and conversion. | * Lowest-level serialization and conversion. | ||||
* @note Sizes of these types are verified in the tests | * @note Sizes of these types are verified in the tests | ||||
*/ | */ | ||||
template <typename Stream> inline void ser_writedata8(Stream &s, uint8_t obj) { | template <typename Stream> inline void ser_writedata8(Stream &s, uint8_t obj) { | ||||
s.write((char *)&obj, 1); | s.write((char *)&obj, 1); | ||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
inline void ser_writedata16(Stream &s, uint16_t obj) { | inline void ser_writedata16(Stream &s, uint16_t obj) { | ||||
▲ Show 20 Lines • Show All 428 Lines • ▼ Show 20 Lines | template <typename I> CVarInt<I> WrapVarInt(I &n) { | ||||
return CVarInt<I>(n); | return CVarInt<I>(n); | ||||
} | } | ||||
/** | /** | ||||
* Forward declarations | * Forward declarations | ||||
*/ | */ | ||||
/** | /** | ||||
* 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); | ||||
template <typename Stream, typename C> | template <typename Stream, typename C> | ||||
void Unserialize(Stream &is, std::basic_string<C> &str); | void Unserialize(Stream &is, std::basic_string<C> &str); | ||||
/** | /** | ||||
* prevector | * prevector | ||||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | 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) { | ||||
s.seek(GetSizeOfCompactSize(nSize)); | s.seek(GetSizeOfCompactSize(nSize)); | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
size_t GetSerializeSize(const T &t, int nType, int nVersion = 0) { | size_t GetSerializeSize(const T &t, int nType, int nVersion) { | ||||
return (CSizeComputer(nType, nVersion) << t).size(); | return (CSizeComputer(nType, nVersion) << t).size(); | ||||
} | } | ||||
template <typename S, typename T> | template <typename S, typename T> | ||||
size_t GetSerializeSize(const S &s, const T &t) { | size_t GetSerializeSize(const S &s, const T &t) { | ||||
return (CSizeComputer(s.GetType(), s.GetVersion()) << t).size(); | return (CSizeComputer(s.GetType(), s.GetVersion()) << t).size(); | ||||
} | } | ||||
#endif // BITCOIN_SERIALIZE_H | #endif // BITCOIN_SERIALIZE_H |