mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
packet-macro.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <boost/preprocessor.hpp>
3
#include <boost/preprocessor/seq.hpp>
4
#include <boost/preprocessor/seq/for_each.hpp>
18
#define MAL_PACKET_WEAVER_DECLARE_PACKET(PacketName, Subsystem, ID, TTL) \
19
class PacketName final : public mal_packet_weaver::DerivedPacket<PacketName> \
20
{ \
21
public: \
22
static constexpr char const *const static_packet_name = #PacketName; \
23
const char* packet_name() const final { return static_packet_name; } \
24
static constexpr mal_packet_weaver::UniquePacketID static_unique_id = \
25
mal_packet_weaver::CreatePacketID(Subsystem, ID); \
26
static constexpr float time_to_live = TTL; \
27
static mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> registration; \
28
}; \
29
inline mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> PacketName::registration;
30
35
#define MAL_PACKET_WEAVER_DECLARE_PAYLOAD_MEMBER(r, _, elem) BOOST_PP_TUPLE_ELEM(0, elem) BOOST_PP_TUPLE_ELEM(1, elem);
36
41
#define MAL_PACKET_WEAVER_DECLARE_PAYLOAD_MEMBERS(seq) \
42
BOOST_PP_SEQ_FOR_EACH(MAL_PACKET_WEAVER_DECLARE_PAYLOAD_MEMBER, _, seq)
43
48
#define MAL_PACKET_WEAVER_DECLARE_BASE_CLASS_INHERITANCE(r, _, elem) \
49
public \
50
elem,
51
56
#define MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_INHERITANCE(seq) \
57
BOOST_PP_SEQ_FOR_EACH(MAL_PACKET_WEAVER_DECLARE_BASE_CLASS_INHERITANCE, _, seq)
58
63
#define MAL_PACKET_WEAVER_DECLARE_BASE_CLASS_SERIALIZATION(r, _, elem) \
64
ar(CEREAL_NVP(cereal::base_class<elem>(this)));
65
70
#define MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_SERIALIZATION(seq) \
71
BOOST_PP_SEQ_FOR_EACH(MAL_PACKET_WEAVER_DECLARE_BASE_CLASS_SERIALIZATION, _, seq)
72
77
#define MAL_PACKET_WEAVER_SERIALIZE_MEMBER(r, ar, elem) ar(CEREAL_NVP(BOOST_PP_TUPLE_ELEM(1, elem)));
78
83
#define MAL_PACKET_WEAVER_SERIALIZE_MEMBERS(ar, seq) BOOST_PP_SEQ_FOR_EACH(MAL_PACKET_WEAVER_SERIALIZE_MEMBER, ar, seq)
84
89
#define MAL_PACKET_WEAVER_VA_ARGS_COUNT(...) \
90
MAL_PACKET_WEAVER_VA_ARGS_COUNT_IMPL(__VA_ARGS__, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, \
91
46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, \
92
27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, \
93
7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0)
94
99
#define MAL_PACKET_WEAVER_VA_ARGS_COUNT_IMPL( \
100
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, \
101
_25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, \
102
_48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, N, ...) \
103
N
104
109
#define MAL_PACKET_WEAVER_NON_EMPTY_SIZE(...) MAL_PACKET_WEAVER_VA_ARGS_COUNT(__VA_ARGS__)
110
121
#define MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_BODY_WITH_PAYLOAD(PacketName, Subsystem, ID, TTL, PACKET_BODY, ...) \
122
class PacketName final : public mal_packet_weaver::DerivedPacket<PacketName> \
123
{ \
124
public: \
125
static constexpr char const *const static_packet_name = #PacketName; \
126
const char* packet_name() const final { return static_packet_name; } \
127
static constexpr mal_packet_weaver::UniquePacketID static_unique_id = \
128
mal_packet_weaver::CreatePacketID(Subsystem, ID); \
129
static constexpr float time_to_live = TTL; \
130
\
131
MAL_PACKET_WEAVER_DECLARE_PAYLOAD_MEMBERS(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
132
\
133
PACKET_BODY \
134
private: \
135
friend class cereal::access; \
136
template <class Archive> \
137
void serialize(Archive &ar) \
138
{ \
139
MAL_PACKET_WEAVER_SERIALIZE_MEMBERS(ar, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
140
} \
141
static mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> registration; \
142
}; \
143
inline mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> PacketName::registration;
144
154
#define MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_BODY_WITHOUT_PAYLOAD(PacketName, Subsystem, ID, TTL, PACKET_BODY) \
155
class PacketName final : public mal_packet_weaver::DerivedPacket<PacketName> \
156
{ \
157
public: \
158
static constexpr char const *const static_packet_name = #PacketName; \
159
const char* packet_name() const final { return static_packet_name; } \
160
static constexpr mal_packet_weaver::UniquePacketID static_unique_id = \
161
mal_packet_weaver::CreatePacketID(Subsystem, ID); \
162
static constexpr float time_to_live = TTL; \
163
\
164
PACKET_BODY \
165
private: \
166
static mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> registration; \
167
}; \
168
inline mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> PacketName::registration;
181
#define MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_PAYLOAD(PacketName, Subsystem, ID, TTL, ...) \
182
MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_BODY_WITH_PAYLOAD(PacketName, Subsystem, ID, TTL,
/* nothing */
, __VA_ARGS__)
183
194
#define MAL_PACKET_WEAVER_DECLARE_PACKET_WITHOUT_PAYLOAD(PacketName, Subsystem, ID, TTL) \
195
MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_BODY_WITHOUT_PAYLOAD(PacketName, Subsystem, ID, TTL,
/* nothing */
)
196
208
#define MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_BODY_WITHOUT_PAYLOAD(PacketName, BasePackets, Subsystem, ID, \
209
TTL, PACKET_BODY) \
210
class PacketName final : MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_INHERITANCE(BOOST_PP_TUPLE_TO_SEQ( \
211
BasePackets)) public mal_packet_weaver::DerivedPacket<PacketName> \
212
{ \
213
public: \
214
static constexpr char const *const static_packet_name = #PacketName; \
215
const char* packet_name() const final { return static_packet_name; } \
216
static constexpr mal_packet_weaver::UniquePacketID static_unique_id = \
217
mal_packet_weaver::CreatePacketID(Subsystem, ID); \
218
static constexpr float time_to_live = TTL; \
219
PACKET_BODY \
220
private: \
221
friend class cereal::access; \
222
template <class Archive> \
223
void serialize(Archive &ar) \
224
{ \
225
MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_SERIALIZATION(BOOST_PP_TUPLE_TO_SEQ(BasePackets)) \
226
} \
227
static mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> registration; \
228
}; \
229
inline mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> PacketName::registration;
230
244
#define MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_BODY_WITH_PAYLOAD(PacketName, BasePackets, Subsystem, ID, TTL, \
245
PACKET_BODY, ...) \
246
class PacketName final : MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_INHERITANCE(BOOST_PP_TUPLE_TO_SEQ( \
247
BasePackets)) public mal_packet_weaver::DerivedPacket<PacketName> \
248
{ \
249
public: \
250
static constexpr char const *const static_packet_name = #PacketName; \
251
const char* packet_name() const final { return static_packet_name; } \
252
static constexpr mal_packet_weaver::UniquePacketID static_unique_id = \
253
mal_packet_weaver::CreatePacketID(Subsystem, ID); \
254
static constexpr float time_to_live = TTL; \
255
MAL_PACKET_WEAVER_DECLARE_PAYLOAD_MEMBERS(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
256
PACKET_BODY \
257
private: \
258
friend class cereal::access; \
259
template <class Archive> \
260
void serialize(Archive &ar) \
261
{ \
262
MAL_PACKET_WEAVER_DECLARE_BASE_CLASSES_SERIALIZATION(BOOST_PP_TUPLE_TO_SEQ(BasePackets)) \
263
MAL_PACKET_WEAVER_SERIALIZE_MEMBERS(ar, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
264
} \
265
static mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> registration; \
266
}; \
267
inline mal_packet_weaver::PacketTypeRegistrationHelper<PacketName> PacketName::registration;
268
280
#define MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_PAYLOAD(PacketName, BasePackets, Subsystem, ID, TTL, ...) \
281
MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_BODY_WITH_PAYLOAD(PacketName, BasePackets, Subsystem, ID, TTL, \
282
/* nothing */
, __VA_ARGS__)
283
293
#define MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITHOUT_PAYLOAD(PacketName, BasePackets, Subsystem, ID, TTL) \
294
MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_BODY_WITHOUT_PAYLOAD(PacketName, BasePackets, Subsystem, ID, TTL, \
295
/* nothing */
)
296
310
#define MAL_PACKET_WEAVER_DECLARE_EMPTY_REQUEST_AND_RESPONSE_WITH_PAYLOAD(PacketName, Subsystem, ID1, ID2, TTL1, TTL2, \
311
...) \
312
MAL_PACKET_WEAVER_DECLARE_PACKET(PacketName##Request, Subsystem, ID1, TTL1) \
313
MAL_PACKET_WEAVER_DECLARE_PACKET_WITH_PAYLOAD(PacketName##Response, Subsystem, ID2, TTL2, __VA_ARGS__)
314
328
#define MAL_PACKET_WEAVER_DECLARE_EMPTY_REQUEST_AND_RESPONSE_WITHOUT_PAYLOAD(PacketName, Subsystem, ID1, ID2, TTL1, \
329
TTL2, ...) \
330
MAL_PACKET_WEAVER_DECLARE_PACKET(PacketName##Request, Subsystem, ID1, TTL1) \
331
MAL_PACKET_WEAVER_DECLARE_PACKET_WITHOUT_PAYLOAD(PacketName##Response, Subsystem, ID2, TTL2)
332
345
#define MAL_PACKET_WEAVER_DECLARE_EMPTY_REQUEST_AND_DERIVED_RESPONSE_WITH_PAYLOAD(PacketName, BasePackets, Subsystem, \
346
ID1, ID2, TTL1, TTL2, ...) \
347
MAL_PACKET_WEAVER_DECLARE_PACKET(PacketName##Request, Subsystem, ID1, TTL1) \
348
MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITH_PAYLOAD(PacketName##Response, BasePackets, Subsystem, ID2, TTL2, \
349
__VA_ARGS__)
364
#define MAL_PACKET_WEAVER_DECLARE_EMPTY_REQUEST_AND_DERIVED_RESPONSE_WITHOUT_PAYLOAD( \
365
PacketName, BasePackets, Subsystem, ID1, ID2, TTL1, TTL2, ...) \
366
MAL_PACKET_WEAVER_DECLARE_PACKET(PacketName##Request, Subsystem, ID1, TTL1) \
367
MAL_PACKET_WEAVER_DECLARE_DERIVED_PACKET_WITHOUT_PAYLOAD(PacketName##Response, BasePackets, Subsystem, ID2, TTL2)
mal-packet-weaver
mal-packet-weaver
packet-impl
packet-macro.hpp
Generated on Sun Jul 14 2024 00:02:52 for mal-packet-weaver by
1.11.0