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_START_ARRAY 39 #ifdef NMT_CREATE_HEADER_NAME 41 #ifndef ARRAY_STRUCT_PREFIX 42 #define ARRAY_STRUCT_PREFIX(_nm) S_##_nm 47 #ifndef NMT_CREATOR_IMPLEMENT 51 #define NMT_CREATOR_PASS_CLASSDEF 55 #define START_NMT_CLASS(_nm, _tp) \ 56 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) 66 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 67 CNetMessage *Deserialize##_nm(const u8 *, size_t); \ 68 class _nm: public _base \ 71 _nm(NetMessageType type): _base(type) {}\ 75 CStr ToStringRaw() const;\ 77 _nm(): _base(_tp) {} \ 78 virtual size_t GetSerializedLength() const; \ 79 virtual u8 *Serialize(u8 *buffer) const; \ 80 virtual const u8 *Deserialize(const u8 *pos, const u8 *end); \ 81 virtual CStr ToString() const; \ 82 inline operator CStr () const \ 83 { return ToString(); } 95 #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ 106 #define NMT_FIELD(_tp, _nm) \ 109 #define NMT_START_ARRAY(_nm) \ 110 struct ARRAY_STRUCT_PREFIX(_nm); \ 111 std::vector <ARRAY_STRUCT_PREFIX(_nm)> _nm; \ 112 struct ARRAY_STRUCT_PREFIX(_nm) { 114 #define NMT_END_ARRAY() \ 117 #define END_NMT_CLASS() }; 120 #undef NMT_CREATOR_PASS_CLASSDEF 122 #else // NMT_CREATOR_IMPLEMENT 128 #define NMT_CREATOR_PASS_GETLENGTH 132 #define START_NMT_CLASS(_nm, _tp) \ 133 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) 134 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 135 size_t _nm::GetSerializedLength() const \ 137 size_t ret=_base::GetSerializedLength(); \ 138 const _nm *thiz=this;\ 139 UNUSED2(thiz); // preempt any "unused" warning 141 #define NMT_START_ARRAY(_nm) \ 142 std::vector <ARRAY_STRUCT_PREFIX(_nm)>::const_iterator it=_nm.begin(); \ 143 while (it != _nm.end()) \ 145 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ 146 UNUSED2(thiz); // preempt any "unused" warning 148 #define NMT_END_ARRAY() \ 152 #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ 155 #define NMT_FIELD(_tp, _nm) \ 156 ret += thiz->_nm.GetSerializedLength(); 158 #define END_NMT_CLASS() \ 163 #undef NMT_CREATOR_PASS_GETLENGTH 168 #define NMT_CREATOR_PASS_SERIALIZE 173 #define START_NMT_CLASS(_nm, _tp) \ 174 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) 175 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 176 u8 *_nm::Serialize(u8 *buffer) const \ 179 u8 *pos=_base::Serialize(buffer); \ 180 const _nm *thiz=this;\ 181 UNUSED2(thiz); // preempt any "unused" warning 183 #define NMT_START_ARRAY(_nm) \ 184 std::vector <ARRAY_STRUCT_PREFIX(_nm)>::const_iterator it=_nm.begin(); \ 185 while (it != _nm.end()) \ 187 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ 188 UNUSED2(thiz); // preempt any "unused" warning 190 #define NMT_END_ARRAY() \ 194 #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ 195 Serialize_int_##_netsz(pos, thiz->_nm); \ 197 #define NMT_FIELD(_tp, _nm) \ 198 pos=thiz->_nm.Serialize(pos); 200 #define END_NMT_CLASS() \ 206 #undef NMT_CREATOR_PASS_SERIALIZE 211 #define NMT_CREATOR_PASS_DESERIALIZE 216 #define BAIL_DESERIALIZER return NULL 218 #define START_NMT_CLASS(_nm, _tp) \ 219 START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp) 220 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 221 const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ 223 pos=_base::Deserialize(pos, end); \ 226 UNUSED2(thiz); // preempt any "unused" warning 229 #define NMT_START_ARRAY(_nm) \ 232 ARRAY_STRUCT_PREFIX(_nm) *thiz=&*_nm.insert(_nm.end(), ARRAY_STRUCT_PREFIX(_nm)());\ 233 UNUSED2(thiz); // preempt any "unused" warning 235 #define NMT_END_ARRAY() \ 238 #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ 239 if (pos+_netsz > end) BAIL_DESERIALIZER; \ 240 Deserialize_int_##_netsz(pos, thiz->_nm); \ 243 #define NMT_FIELD(_tp, _nm) \ 244 if ((pos=thiz->_nm.Deserialize(pos, end)) == NULL) BAIL_DESERIALIZER; 246 #define END_NMT_CLASS() \ 252 #undef BAIL_DESERIALIZER 254 #undef NMT_CREATOR_PASS_DESERIALIZE 262 #define START_NMT_CLASS(_nm, _tp) \ 263 CStr _nm::ToString() const \ 265 CStr ret=#_nm " { "; \ 266 return ret + ToStringRaw() + " }"; \ 268 CStr _nm::ToStringRaw() const \ 271 const _nm *thiz=this;\ 272 UNUSED2(thiz); // preempt any "unused" warning 274 #define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \ 275 CStr _nm::ToString() const \ 277 CStr ret=#_nm " { "; \ 278 return ret + ToStringRaw() + " }"; \ 280 CStr _nm::ToStringRaw() const \ 282 CStr ret=_base::ToStringRaw() + ", "; \ 283 const _nm *thiz=this;\ 284 UNUSED2(thiz); // preempt any "unused" warning 286 #define NMT_START_ARRAY(_nm) \ 288 std::vector < ARRAY_STRUCT_PREFIX(_nm) >::const_iterator it=_nm.begin(); \ 289 while (it != _nm.end()) \ 292 const ARRAY_STRUCT_PREFIX(_nm) *thiz=&*it;\ 293 UNUSED2(thiz); // preempt any "unused" warning 295 #define NMT_END_ARRAY() \ 297 ret=ret.substr(0, ret.length()-2)+" }, "; \ 299 ret=ret.substr(0, ret.length()-2)+" }, "; 301 #define NMT_FIELD_INT(_nm, _hosttp, _netsz) \ 303 ret += NetMessageStringConvert(thiz->_nm); \ 306 #define NMT_FIELD(_tp, _nm) \ 308 ret += NetMessageStringConvert(thiz->_nm); \ 311 #define END_NMT_CLASS() \ 312 return ret.substr(0, ret.length()-2); \ 317 #endif // #ifdef NMT_CREATOR_IMPLEMENT 321 #undef NMT_CREATE_HEADER_NAME 322 #undef NMT_CREATOR_IMPLEMENT 325 #endif // #ifdef NMT_CREATE_HEADER_NAME 326 #endif // #ifndef CREATING_NMT