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 const size_t m_length;
27 const uint8_t* m_data;
30 CDeserialiser(size_t Length, const uint8_t *Buffer);
31 bool IsConsumed() const;
35 const ::std::vector<uint8_t> ReadBuffer();
36 const ::std::string ReadString();
38 void RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range);
43 ::std::vector<uint8_t> m_data;
46 void WriteU8(::uint8_t val);
47 void WriteU16(::uint16_t val);
48 void WriteS16(::int16_t val);
49 void WriteBuffer(size_t n, const void* val);
50 void WriteString(const char* val, size_t n);
51 void WriteString(const char* val) {
52 WriteString(val, ::std::char_traits<char>::length(val));
54 void WriteString(const ::std::string& val) {
55 WriteString(val.data(), val.size());
57 void WriteSub(const CSerialiser& val);
59 const ::std::vector<uint8_t>& Compact();