SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.hpp
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #ifndef MPRPC_TYPES_a732d5de_HPP__
9 #define MPRPC_TYPES_a732d5de_HPP__
10 
11 #include <msgpack/rpc/client.h>
12 #include <msgpack/rpc/server.h>
13 #include <stdexcept>
14 
15 namespace StickWorld {
16 
17 
18 struct ChatMessage {
19 
21  :
22  source_id(0),
23  timestamp(0)
24  {
25  }
26 
27  int64_t source_id;
28  int64_t timestamp;
29  std::string message;
30 
31  template <typename Packer>
32  void msgpack_pack(Packer& _Pk) const {
33  _Pk.pack_array(3);
34  _Pk.pack(source_id);
35  _Pk.pack(timestamp);
36  _Pk.pack(message);
37  }
38 
39  void msgpack_unpack(msgpack::object _Obj) {
40  if(_Obj.type != msgpack::type::ARRAY) {
41  throw msgpack::type_error();
42  }
43  const size_t _Length = _Obj.via.array.size;
44  msgpack::object* const _Array = _Obj.via.array.ptr;
45 
46  if(_Length < 3) {
47  throw msgpack::type_error();
48  }
49 
50 
51  _Array[0].convert(&source_id);
52 
53 
54  _Array[1].convert(&timestamp);
55 
56 
57  _Array[2].convert(&message);
58 
59  }
60 };
61 
62 
63 
64 
65 } // namespace StickWorld
66 #endif
std::string message
Definition: types.hpp:29
ChatMessage()
Definition: types.hpp:20
Definition: types.hpp:18
void msgpack_pack(Packer &_Pk) const
Definition: types.hpp:32
void msgpack_unpack(msgpack::object _Obj)
Definition: types.hpp:39
int64_t timestamp
Definition: types.hpp:28
int64_t source_id
Definition: types.hpp:27