Usermode/AxWin4 - PushData implemented
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Common / include / serialisation.hpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang) 
4  *
5  * serialisation.hpp
6  * - Generic (de)serialisation code
7  */
8 #ifndef _SERIALISATION_H_
9 #define _SERIALISATION_H_
10
11 #include <cstdint>
12 #include <cstddef>
13 #include <exception>
14 #include <string>
15 #include <vector>
16
17 namespace AxWin {
18
19 class CDeserialiseException:
20         public ::std::exception
21 {
22 };
23
24 class CDeserialiser
25 {
26         const size_t    m_length;
27         const uint8_t*  m_data;
28         size_t  m_offset;
29 public:
30         CDeserialiser(size_t Length, const uint8_t *Buffer);
31         bool    IsConsumed() const;
32         ::uint8_t       ReadU8();
33         ::uint16_t      ReadU16();
34         ::int16_t       ReadS16();
35         const ::std::vector<uint8_t>    ReadBuffer();
36         const ::std::string     ReadString();
37 private:
38         void RangeCheck(const char *Method, size_t bytes) throw(::std::out_of_range);
39 };
40
41 class CSerialiser
42 {
43         ::std::vector<uint8_t>  m_data;
44 public:
45         CSerialiser();
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));
53         }
54         void WriteString(const ::std::string& val) {
55                 WriteString(val.data(), val.size());
56         }
57         void WriteSub(const CSerialiser& val);
58         
59         const ::std::vector<uint8_t>& Compact();
60 };
61
62 };
63
64 #endif
65

UCC git Repository :: git.ucc.asn.au