Go to the documentation of this file. 24 #include NMT_CREATE_HEADER_NAME 28 #undef START_NMT_CLASS 29 #undef START_NMT_CLASS_DERIVED 32 #undef NMT_FIELD_SECRET 33 #undef NMT_START_ARRAY 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) \ 68 CNetMessage *Deserialize##_nm(const u8 *, size_t); \ 69 class _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 130 #else // NMT_CREATOR_IMPLEMENT 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) \ 143 size_t _nm::GetSerializedLength() const \ 145 size_t ret=_base::GetSerializedLength(); \ 146 const _nm *thiz=this;\ 147 UNUSED2(thiz); // preempt any "unused" warning 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;\ 154 UNUSED2(thiz); // preempt any "unused" warning 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) \ 187 u8 *_nm::Serialize(u8 *buffer) const \ 190 u8 *pos=_base::Serialize(buffer); \ 191 const _nm *thiz=this;\ 192 UNUSED2(thiz); // preempt any "unused" warning 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;\ 199 UNUSED2(thiz); // preempt any "unused" warning 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) \ 235 const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ 237 pos=_base::Deserialize(pos, end); \ 238 if (pos == NULL) BAIL_DESERIALIZER;\ 241 UNUSED2(thiz); // preempt any "unused" warning 244 #define NMT_START_ARRAY(_nm) \ 247 ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\ 248 UNUSED2(thiz); // preempt any "unused" warning 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) \ 281 CStr _nm::ToString() const \ 283 CStr ret=#_nm " { "; \ 284 return ret + ToStringRaw() + " }"; \ 286 CStr _nm::ToStringRaw() const \ 289 const _nm *thiz=this;\ 290 UNUSED2(thiz); // preempt any "unused" warning 292 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 293 CStr _nm::ToString() const \ 295 CStr ret=#_nm " { "; \ 296 return ret + ToStringRaw() + " }"; \ 298 CStr _nm::ToStringRaw() const \ 300 CStr ret=_base::ToStringRaw() + ", "; \ 301 const _nm *thiz=this;\ 302 UNUSED2(thiz); // preempt any "unused" warning 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;\ 311 UNUSED2(thiz); // preempt any "unused" warning 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); \ 338 #endif // #ifdef NMT_CREATOR_IMPLEMENT 342 #undef NMT_CREATE_HEADER_NAME 343 #undef NMT_CREATOR_IMPLEMENT 346 #endif // #ifdef NMT_CREATE_HEADER_NAME 347 #endif // #ifndef CREATING_NMT