Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
}; | }; | ||||
template <typename I> class CVarInt { | template <typename I> class CVarInt { | ||||
protected: | protected: | ||||
I &n; | I &n; | ||||
public: | public: | ||||
CVarInt(I &nIn) : n(nIn) {} | explicit CVarInt(I &nIn) : n(nIn) {} | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
WriteVarInt<Stream, I>(s, n); | WriteVarInt<Stream, I>(s, n); | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
n = ReadVarInt<Stream, I>(s); | n = ReadVarInt<Stream, I>(s); | ||||
} | } | ||||
}; | }; | ||||
class CCompactSize { | class CCompactSize { | ||||
protected: | protected: | ||||
uint64_t &n; | uint64_t &n; | ||||
public: | public: | ||||
CCompactSize(uint64_t &nIn) : n(nIn) {} | explicit CCompactSize(uint64_t &nIn) : n(nIn) {} | ||||
template <typename Stream> void Serialize(Stream &s) const { | template <typename Stream> void Serialize(Stream &s) const { | ||||
WriteCompactSize<Stream>(s, n); | WriteCompactSize<Stream>(s, n); | ||||
} | } | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
n = ReadCompactSize<Stream>(s); | n = ReadCompactSize<Stream>(s); | ||||
} | } | ||||
}; | }; | ||||
template <size_t Limit> class LimitedString { | template <size_t Limit> class LimitedString { | ||||
protected: | protected: | ||||
std::string &string; | std::string &string; | ||||
public: | public: | ||||
LimitedString(std::string &_string) : string(_string) {} | explicit LimitedString(std::string &_string) : string(_string) {} | ||||
template <typename Stream> void Unserialize(Stream &s) { | template <typename Stream> void Unserialize(Stream &s) { | ||||
size_t size = ReadCompactSize(s); | size_t size = ReadCompactSize(s); | ||||
if (size > Limit) { | if (size > Limit) { | ||||
throw std::ios_base::failure("String length limit exceeded"); | throw std::ios_base::failure("String length limit exceeded"); | ||||
} | } | ||||
string.resize(size); | string.resize(size); | ||||
if (size != 0) { | if (size != 0) { | ||||
▲ Show 20 Lines • Show All 464 Lines • Show Last 20 Lines |