3 * - By John Hodge (thePowersGang)
6 * - Generic (de)serialisation code
8 #ifndef _SERIALISATION_H_
9 #define _SERIALISATION_H_
19 class CDeserialiseException:
20 public ::std::exception
26 ::std::vector<uint8_t> m_vect;
30 CDeserialiser(::std::vector<uint8_t>())
32 CDeserialiser(const ::std::vector<uint8_t>& vect);
33 CDeserialiser(::std::vector<uint8_t>&& vect);
34 CDeserialiser(const CDeserialiser& x) { *this = x; };
35 CDeserialiser& operator=(const CDeserialiser& x);
36 bool IsConsumed() const;
42 const ::std::vector<uint8_t> ReadBuffer();
43 const ::std::string ReadString();
45 void RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range);
50 ::std::vector<uint8_t> m_data;
53 void WriteU8(::uint8_t val);
54 void WriteU16(::uint16_t val);
55 void WriteS16(::int16_t val);
56 void WriteU32(::uint32_t val);
57 void WriteU64(::uint64_t val);
58 void WriteBuffer(size_t n, const void* val);
59 void WriteString(const char* val, size_t n);
60 void WriteString(const char* val) {
61 WriteString(val, ::std::char_traits<char>::length(val));
63 void WriteString(const ::std::string& val) {
64 WriteString(val.data(), val.size());
66 void WriteSub(const CSerialiser& val);
68 const ::std::vector<uint8_t>& Compact();