Usermode/AxWin4 - Starting work on client-side library
[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         ::uint8_t       ReadU8();
32         ::uint16_t      ReadU16();
33         ::int16_t       ReadS16();
34         ::std::string   ReadString();
35 };
36
37 class CSerialiser
38 {
39         ::std::vector<uint8_t>  m_data;
40 public:
41         CSerialiser();
42         void WriteU8(::uint8_t val);
43         void WriteU16(::uint16_t val);
44         void WriteS16(::int16_t val);
45         void WriteString(const char* val, size_t n);
46         void WriteString(const char* val) {
47                 WriteString(val, ::std::char_traits<char>::length(val));
48         }
49         void WriteString(const ::std::string& val) {
50                 WriteString(val.data(), val.size());
51         }
52         void WriteSub(const CSerialiser& val);
53 };
54
55 };
56
57 #endif
58

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