@@ -16,6 +16,8 @@ namespace ecsact {
16
16
* @returns serialized action or component bytes
17
17
*/
18
18
template <typename T>
19
+ requires (!std::is_same_v<std::remove_cvref_t <T>, ecsact_component> &&
20
+ !std::is_same_v<std::remove_cvref_t <T>, ecsact_action>)
19
21
ECSACT_ALWAYS_INLINE auto serialize ( //
20
22
const T& component_or_action
21
23
) -> std::vector<std::byte> {
@@ -55,71 +57,20 @@ ECSACT_ALWAYS_INLINE auto serialize( //
55
57
* fn are passed in to work around various linking configurations.
56
58
* @returns serialized action bytes
57
59
*/
58
- ECSACT_ALWAYS_INLINE auto serialize (
59
- const ecsact_component& component,
60
- decltype (ecsact_serialize_component_size) size_fn,
61
- decltype(ecsact_serialize_component) serialize_fn
60
+ ECSACT_ALWAYS_INLINE auto serialize ( //
61
+ const ecsact_component& component
62
62
) -> std::vector<std::byte> {
63
63
std::vector<std::byte> out_component;
64
- out_component.resize (size_fn (component.component_id ));
64
+ out_component.resize (ecsact_serialize_component_size (component.component_id ));
65
65
66
- serialize_fn (
66
+ ecsact_serialize_component (
67
67
component.component_id ,
68
68
component.component_data ,
69
69
reinterpret_cast <uint8_t *>(out_component.data ())
70
70
);
71
71
return out_component;
72
72
}
73
73
74
- /* *
75
- * Serializes an ecsact_component when the type is unknown.
76
- * @returns serialized action bytes
77
- */
78
- ECSACT_ALWAYS_INLINE auto serialize ( //
79
- const ecsact_component& component
80
- ) -> std::vector<std::byte> {
81
- return serialize (
82
- component,
83
- ecsact_serialize_component_size,
84
- ecsact_serialize_component
85
- );
86
- }
87
-
88
- /* *
89
- * Serializes an ecsact_action when the type is unknown. Size and serialize
90
- * fn are passed in to work around various linking configurations.
91
- * @returns serialized component bytes
92
- */
93
- ECSACT_ALWAYS_INLINE auto serialize (
94
- const ecsact_action& action,
95
- decltype (ecsact_serialize_action_size) size_fn,
96
- decltype(ecsact_serialize_action) serialize_fn
97
- ) -> std::vector<std::byte> {
98
- std::vector<std::byte> out_action;
99
- out_action.resize (size_fn (action.action_id ));
100
-
101
- serialize_fn (
102
- action.action_id ,
103
- action.action_data ,
104
- reinterpret_cast <uint8_t *>(out_action.data ())
105
- );
106
- return out_action;
107
- }
108
-
109
- /* *
110
- * Serializes an ecsact_action when the type is unknown.
111
- * @returns serialized component bytes
112
- */
113
- ECSACT_ALWAYS_INLINE auto serialize ( //
114
- const ecsact_action& action
115
- ) -> std::vector<std::byte> {
116
- return serialize (
117
- action,
118
- ecsact_serialize_action_size,
119
- ecsact_serialize_action
120
- );
121
- }
122
-
123
74
/* *
124
75
* Calls `ecsact_deserialize_action` or `ecsact_deserialize_component` based on
125
76
* the type of @tp T.
@@ -198,14 +149,13 @@ ECSACT_ALWAYS_INLINE auto deserialize(
198
149
* @returns an ecsact_action
199
150
*/
200
151
ECSACT_ALWAYS_INLINE auto deserialize (
201
- const ecsact_action_id& id,
202
- std::vector<std::byte>& serialized_action,
203
- decltype (ecsact_deserialize_action) deserialize_fn
152
+ const ecsact_action_id& id,
153
+ std::vector<std::byte>& serialized_action
204
154
) -> std::vector<std::byte> {
205
155
std::vector<std::byte> action_data;
206
156
action_data.resize (serialized_action.size ());
207
157
208
- deserialize_fn (
158
+ ecsact_deserialize_action (
209
159
id,
210
160
reinterpret_cast <uint8_t *>(serialized_action.data ()),
211
161
action_data.data ()
@@ -218,42 +168,18 @@ ECSACT_ALWAYS_INLINE auto deserialize(
218
168
* @returns an ecsact_action
219
169
*/
220
170
ECSACT_ALWAYS_INLINE auto deserialize (
221
- const ecsact_action_id& id,
222
- std::vector<std::byte>& serialized_action
223
- ) -> std::vector<std::byte> {
224
- return deserialize (id, serialized_action, &ecsact_deserialize_action);
225
- }
226
-
227
- /* *
228
- * Deserializes an ecsact_component when the type is unknown.
229
- * @returns an ecsact_action
230
- */
231
- ECSACT_ALWAYS_INLINE auto deserialize (
232
- const ecsact_component_id& id,
233
- std::vector<std::byte>& serialized_component,
234
- decltype (ecsact_deserialize_component) deserialize_fn
171
+ const ecsact_component_id& id,
172
+ std::vector<std::byte>& serialized_component
235
173
) -> std::vector<std::byte> {
236
174
std::vector<std::byte> component_data;
237
175
component_data.resize (serialized_component.size ());
238
176
239
- deserialize_fn (
177
+ ecsact_deserialize_component (
240
178
id,
241
179
reinterpret_cast <uint8_t *>(serialized_component.data ()),
242
180
component_data.data ()
243
181
);
244
182
return component_data;
245
183
}
246
184
247
- /* *
248
- * Deserializes an ecsact_component when the type is unknown. The deserialize
249
- * function is passed in to work around various linker configurations.
250
- * @returns an ecsact_component_id
251
- */
252
- ECSACT_ALWAYS_INLINE auto deserialize (
253
- const ecsact_component_id& id,
254
- std::vector<std::byte>& serialized_component
255
- ) -> std::vector<std::byte> {
256
- return deserialize (id, serialized_component, ecsact_deserialize_component);
257
- }
258
-
259
185
} // namespace ecsact
0 commit comments