24#include NMT_CREATE_HEADER_NAME
29#undef START_NMT_CLASS_DERIVED
32#undef NMT_FIELD_SECRET
40#ifdef NMT_CREATE_HEADER_NAME
42#ifndef ARRAY_STRUCT_PREFIX
43#define ARRAY_STRUCT_PREFIX(_nm) S_##_nm
48#ifndef NMT_CREATOR_IMPLEMENT
52#define NMT_CREATOR_PASS_CLASSDEF
56#define START_NMT_CLASS(_nm, _tp) \
57 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp)
67#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
68CNetMessage *Deserialize##_nm(const u8 *, size_t); \
69class _nm: public _base \
72 _nm(NetMessageType type): _base(type) {}\
76 CStr ToStringRaw() const;\
78 _nm(): _base(_tp) {} \
79 virtual size_t GetSerializedLength() const; \
80 virtual u8 *Serialize(u8 *buffer) const; \
81 virtual const u8 *Deserialize(const u8 *pos, const u8 *end); \
82 virtual CStr ToString() const; \
83 inline operator CStr () const \
84 { return ToString(); }
96#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
107#define NMT_FIELD(_tp, _nm) \
114#define NMT_FIELD_SECRET(_tp, _nm) \
117#define NMT_START_ARRAY(_nm) \
118 struct ARRAY_STRUCT_PREFIX(_nm); \
119 std::vector <ARRAY_STRUCT_PREFIX(_nm)> _nm; \
120 struct ARRAY_STRUCT_PREFIX(_nm) {
122#define NMT_END_ARRAY() \
125#define END_NMT_CLASS() };
128#undef NMT_CREATOR_PASS_CLASSDEF
136#define NMT_CREATOR_PASS_GETLENGTH
140#define START_NMT_CLASS(_nm, _tp) \
141 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp)
142#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
143size_t _nm::GetSerializedLength() const \
145 size_t ret=_base::GetSerializedLength(); \
146 const _nm *thiz=this;\
149#define NMT_START_ARRAY(_nm) \
150 std::vector <ARRAY_STRUCT_PREFIX(_nm)>::const_iterator it=_nm.begin(); \
151 while (it != _nm.end()) \
153 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\
156#define NMT_END_ARRAY() \
160#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
163#define NMT_FIELD(_tp, _nm) \
164 ret += thiz->_nm.GetSerializedLength();
166#define NMT_FIELD_SECRET(_tp, _nm) \
167 ret += thiz->_nm.GetSerializedLength();
169#define END_NMT_CLASS() \
174#undef NMT_CREATOR_PASS_GETLENGTH
179#define NMT_CREATOR_PASS_SERIALIZE
184#define START_NMT_CLASS(_nm, _tp) \
185 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp)
186#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
187u8 *_nm::Serialize(u8 *buffer) const \
190 u8 *pos=_base::Serialize(buffer); \
191 const _nm *thiz=this;\
194#define NMT_START_ARRAY(_nm) \
195 std::vector <ARRAY_STRUCT_PREFIX(_nm)>::const_iterator it=_nm.begin(); \
196 while (it != _nm.end()) \
198 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\
201#define NMT_END_ARRAY() \
205#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
206 Serialize_int_##_netsz(pos, thiz->_nm); \
208#define NMT_FIELD(_tp, _nm) \
209 pos=thiz->_nm.Serialize(pos);
211#define NMT_FIELD_SECRET(_tp, _nm) \
212 pos=thiz->_nm.Serialize(pos);
214#define END_NMT_CLASS() \
220#undef NMT_CREATOR_PASS_SERIALIZE
225#define NMT_CREATOR_PASS_DESERIALIZE
230#define BAIL_DESERIALIZER return NULL
232#define START_NMT_CLASS(_nm, _tp) \
233 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp)
234#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
235const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \
237 pos=_base::Deserialize(pos, end); \
238 if (pos == NULL) BAIL_DESERIALIZER;\
244#define NMT_START_ARRAY(_nm) \
247 ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\
250#define NMT_END_ARRAY() \
253#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
254 if (pos+_netsz > end) BAIL_DESERIALIZER; \
255 Deserialize_int_##_netsz(pos, thiz->_nm); \
258#define NMT_FIELD(_tp, _nm) \
259 if ((pos=thiz->_nm.Deserialize(pos, end)) == NULL) BAIL_DESERIALIZER;
261#define NMT_FIELD_SECRET(_tp, _nm) \
262 if ((pos=thiz->_nm.Deserialize(pos, end)) == NULL) BAIL_DESERIALIZER;
264#define END_NMT_CLASS() \
270#undef BAIL_DESERIALIZER
272#undef NMT_CREATOR_PASS_DESERIALIZE
280#define START_NMT_CLASS(_nm, _tp) \
281CStr _nm::ToString() const \
283 CStr ret=#_nm " { "; \
284 return ret + ToStringRaw() + " }"; \
286CStr _nm::ToStringRaw() const \
289 const _nm *thiz=this;\
292#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
293CStr _nm::ToString() const \
295 CStr ret=#_nm " { "; \
296 return ret + ToStringRaw() + " }"; \
298CStr _nm::ToStringRaw() const \
300 CStr ret=_base::ToStringRaw() + ", "; \
301 const _nm *thiz=this;\
304#define NMT_START_ARRAY(_nm) \
306 std::vector < ARRAY_STRUCT_PREFIX(_nm) >::const_iterator it=_nm.begin(); \
307 while (it != _nm.end()) \
310 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\
313#define NMT_END_ARRAY() \
315 ret=ret.substr(0, ret.length()-2)+" }, "; \
317 ret=ret.substr(0, ret.length()-2)+" }, ";
319#define NMT_FIELD_INT(_nm, _hosttp, _netsz) \
321 ret += NetMessageStringConvert(thiz->_nm); \
324#define NMT_FIELD(_tp, _nm) \
326 ret += NetMessageStringConvert(thiz->_nm); \
329#define NMT_FIELD_SECRET(_tp, _nm) \
330 ret += #_nm ": [secret], ";
332#define END_NMT_CLASS() \
333 return ret.substr(0, ret.length()-2); \
342#undef NMT_CREATE_HEADER_NAME
343#undef NMT_CREATOR_IMPLEMENT