GCC Code Coverage Report


Directory: ./
File: Serializable.hpp
Date: 2026-09-03 22:13:07
Exec Total Coverage
Lines: 2 6 33.3%
Functions: 2 6 33.3%
Branches: 0 0 -%

Line Branch Exec Source
1 #ifndef SERIALIZABLE_HPP
2 #define SERIALIZABLE_HPP
3
4 #ifdef BUILD_UT
5 #include <iostream>
6 #endif
7
8 #include <Fw/FPrimeBasicTypes.hpp>
9 #include "Fw/Deprecate.hpp"
10
11 namespace Fw {
12
13 class StringBase; //!< forward declaration for string
14 typedef enum {
15 FW_SERIALIZE_OK, //!< Serialization/Deserialization operation was successful
16 FW_SERIALIZE_FORMAT_ERROR, //!< Data was the wrong format (e.g. wrong packet type)
17 FW_SERIALIZE_NO_ROOM_LEFT, //!< No room left in the buffer to serialize data
18 FW_DESERIALIZE_BUFFER_EMPTY, //!< Deserialization buffer was empty when trying to read more data
19 FW_DESERIALIZE_FORMAT_ERROR, //!< Deserialization data had incorrect values (unexpected data types)
20 FW_DESERIALIZE_SIZE_MISMATCH, //!< Data was left in the buffer, but not enough to deserialize
21 FW_DESERIALIZE_TYPE_MISMATCH, //!< Deserialized type ID didn't match
22 FW_DESERIALIZE_IMMUTABLE, //!< Attempted to deserialize into an immutable buffer
23 FW_DESERIALIZE_INVALID_DATA, //!< Data failed validation
24 FW_SERIALIZE_DISCARDED_EXISTING, //!< Serialization succeeded, but deleted old data
25 } SerializeStatus;
26
27 class SerialBufferBase; //!< forward declaration
28 class LinearBufferBase; //!< forward declaration
29
30 struct Serialization {
31 enum t {
32 INCLUDE_LENGTH, //!< Include length as first token in serialization
33 OMIT_LENGTH //!< Omit length from serialization
34 };
35 };
36
37 enum class Endianness {
38 BIG, //!< Big endian serialization
39 LITTLE //!< Little endian serialization
40 };
41
42 class Serializable {
43 public:
44 // Size type for backwards compatibility
45 using SizeType = FwSizeType;
46
47 public:
48 //! \brief Serialize the contents of this object to a buffer
49 //!
50 //! This method serializes the object's data into the provided buffer.
51 //! The serialization process converts the object's data into a format
52 //! that can be stored or transmitted, and then writes it to the buffer.
53 //!
54 //! \param buffer Reference to the SerialBufferBase where data will be serialized
55 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
56 //! \return SerializeStatus indicating the result of the operation
57 virtual SerializeStatus serializeTo(SerialBufferBase& buffer, Endianness mode = Endianness::BIG) const = 0;
58
59 //! \brief Deserialize the contents of this object from a buffer
60 //!
61 //! This method reads serialized data from the provided buffer and
62 //! reconstructs the object's data from it. The buffer should contain
63 //! data in the format produced by serializeTo().
64 //!
65 //! \param buffer Reference to the SerialBufferBase from which data will be deserialized
66 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
67 //! \return SerializeStatus indicating the result of the operation
68 virtual SerializeStatus deserializeFrom(SerialBufferBase& buffer, Endianness mode = Endianness::BIG) = 0;
69
70 // ----------------------------------------------------------------------
71 // Legacy methods for backward compatibility
72 // ----------------------------------------------------------------------
73
74 DEPRECATED(SerializeStatus serialize(SerialBufferBase& buffer) const,
75 "Use serializeTo(SerialBufferBase& buffer) instead") {
76 return this->serializeTo(buffer);
77 }
78
79 DEPRECATED(SerializeStatus deserialize(SerialBufferBase& buffer),
80 "Use deserializeFrom(SerialBufferBase& buffer) instead") {
81 return this->deserializeFrom(buffer);
82 }
83
84 #if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT
85 //! \brief Generate a human-readable string representation of this object
86 //!
87 //! This method converts the object's data into a textual representation
88 //! that can be used for logging, debugging, or display purposes. The
89 //! exact format of the string may vary depending on the implementation
90 //! of the derived class.
91 //!
92 //! \param text Reference to a StringBase object where the text representation will be stored
93 virtual void toString(StringBase& text) const;
94 #endif
95
96 #ifdef BUILD_UT
97 friend std::ostream& operator<<(std::ostream& os, const Serializable& val);
98 #endif
99
100 protected:
101 //! \brief Default constructor
102 //!
103 //! Initializes a Serializable object with default values.
104 Serializable();
105
106 //! \brief Virtual destructor
107 //!
108 //! Ensures proper cleanup of derived classes.
109 virtual ~Serializable();
110 };
111
112 class SerialBufferBase {
113 public:
114 //! \brief Virtual destructor
115 //!
116 //! Ensures proper cleanup of derived classes.
117 virtual ~SerialBufferBase();
118
119 // Serialization for built-in types
120
121 //! \brief Serialize an 8-bit unsigned integer value
122 //!
123 //! This method serializes a single 8-bit unsigned integer value into the buffer.
124 //! The endianness of the serialization can be controlled via the mode parameter.
125 //!
126 //! NOTE: The 'mode' argument here for endianness has no effect as there is no
127 //! concept of endianness for a U8. It has been left in for compatibility.
128 //!
129 //! \param val The 8-bit unsigned integer value to serialize
130 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
131 //! \return SerializeStatus indicating the result of the operation
132 virtual SerializeStatus serializeFrom(U8 val, Endianness mode = Endianness::BIG) = 0;
133
134 //! \brief Serialize an 8-bit signed integer value
135 //!
136 //! This method serializes a single 8-bit signed integer value into the buffer.
137 //! The endianness of the serialization can be controlled via the mode parameter.
138 //!
139 //! NOTE: The 'mode' argument here for endianness has no effect as there is no
140 //! concept of endianness for an I8. It has been left in for compatibility.
141 //!
142 //! \param val The 8-bit signed integer value to serialize
143 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
144 //! \return SerializeStatus indicating the result of the operation
145 virtual SerializeStatus serializeFrom(I8 val, Endianness mode = Endianness::BIG) = 0;
146
147 #if FW_HAS_16_BIT == 1
148 //! \brief Serialize a 16-bit unsigned integer value
149 //!
150 //! This method serializes a single 16-bit unsigned integer value into the buffer.
151 //! The endianness of the serialization can be controlled via the mode parameter.
152 //!
153 //! \param val The 16-bit unsigned integer value to serialize
154 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
155 //! \return SerializeStatus indicating the result of the operation
156 virtual SerializeStatus serializeFrom(U16 val, Endianness mode = Endianness::BIG) = 0;
157
158 //! \brief Serialize a 16-bit signed integer value
159 //!
160 //! This method serializes a single 16-bit signed integer value into the buffer.
161 //! The endianness of the serialization can be controlled via the mode parameter.
162 //!
163 //! \param val The 16-bit signed integer value to serialize
164 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
165 //! \return SerializeStatus indicating the result of the operation
166 virtual SerializeStatus serializeFrom(I16 val, Endianness mode = Endianness::BIG) = 0;
167 #endif
168 #if FW_HAS_32_BIT == 1
169 //! \brief Serialize a 32-bit unsigned integer value
170 //!
171 //! This method serializes a single 32-bit unsigned integer value into the buffer.
172 //! The endianness of the serialization can be controlled via the mode parameter.
173 //!
174 //! \param val The 32-bit unsigned integer value to serialize
175 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
176 //! \return SerializeStatus indicating the result of the operation
177 virtual SerializeStatus serializeFrom(U32 val, Endianness mode = Endianness::BIG) = 0;
178
179 //! \brief Serialize a 32-bit signed integer value
180 //!
181 //! This method serializes a single 32-bit signed integer value into the buffer.
182 //! The endianness of the serialization can be controlled via the mode parameter.
183 //!
184 //! \param val The 32-bit signed integer value to serialize
185 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
186 //! \return SerializeStatus indicating the result of the operation
187 virtual SerializeStatus serializeFrom(I32 val, Endianness mode = Endianness::BIG) = 0;
188 #endif
189 #if FW_HAS_64_BIT == 1
190 //! \brief Serialize a 64-bit unsigned integer value
191 //!
192 //! This method serializes a single 64-bit unsigned integer value into the buffer.
193 //! The endianness of the serialization can be controlled via the mode parameter.
194 //!
195 //! \param val The 64-bit unsigned integer value to serialize
196 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
197 //! \return SerializeStatus indicating the result of the operation
198 virtual SerializeStatus serializeFrom(U64 val, Endianness mode = Endianness::BIG) = 0;
199
200 //! \brief Serialize a 64-bit signed integer value
201 //!
202 //! This method serializes a single 64-bit signed integer value into the buffer.
203 //! The endianness of the serialization can be controlled via the mode parameter.
204 //!
205 //! \param val The 64-bit signed integer value to serialize
206 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
207 //! \return SerializeStatus indicating the result of the operation
208 virtual SerializeStatus serializeFrom(I64 val, Endianness mode = Endianness::BIG) = 0;
209 #endif
210 //! \brief Serialize a 32-bit floating point value
211 //!
212 //! This method serializes a single 32-bit floating point value into the buffer.
213 //! The endianness of the serialization can be controlled via the mode parameter.
214 //!
215 //! \param val The 32-bit floating point value to serialize
216 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
217 //! \return SerializeStatus indicating the result of the operation
218 virtual SerializeStatus serializeFrom(F32 val, Endianness mode = Endianness::BIG) = 0;
219
220 //! \brief Serialize a 64-bit floating point value
221 //!
222 //! This method serializes a single 64-bit floating point value into the buffer.
223 //! The endianness of the serialization can be controlled via the mode parameter.
224 //!
225 //! \param val The 64-bit floating point value to serialize
226 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
227 //! \return SerializeStatus indicating the result of the operation
228 virtual SerializeStatus serializeFrom(F64 val, Endianness mode = Endianness::BIG) = 0;
229
230 //! \brief Serialize a boolean value
231 //!
232 //! This method serializes a single boolean value into the buffer.
233 //! The endianness of the serialization can be controlled via the mode parameter.
234 //!
235 //! \param val The boolean value to serialize
236 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
237 //! \return SerializeStatus indicating the result of the operation
238 virtual SerializeStatus serializeFrom(bool val, Endianness mode = Endianness::BIG) = 0;
239
240 //! \brief Serialize a pointer value
241 //!
242 //! This method serializes a pointer value into the buffer. Note that only
243 //! the pointer value itself is serialized, not the contents it points to.
244 //! The endianness of the serialization can be controlled via the mode parameter.
245 //!
246 //! \param val The pointer value to serialize
247 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
248 //! \return SerializeStatus indicating the result of the operation
249 virtual SerializeStatus serializeFrom(const void* val, Endianness mode = Endianness::BIG) = 0;
250
251 //! \brief Serialize a data buffer
252 //!
253 //! This method serializes a buffer of bytes into the serialization buffer.
254 //! The endianness of the serialization can be controlled via the mode parameter.
255 //!
256 //! \param buff Pointer to the buffer containing data to serialize
257 //! \param length Number of bytes to serialize from the buffer
258 //! \param endianMode Endianness mode for serialization (default is Endianness::BIG)
259 //! \return SerializeStatus indicating the result of the operation
260 virtual SerializeStatus serializeFrom(const U8* buff,
261 FwSizeType length,
262 Endianness endianMode = Endianness::BIG) = 0;
263
264 //! \brief Serialize a byte buffer with optional length prefix
265 //!
266 //! This method serializes a buffer of bytes into the serialization buffer.
267 //! If lengthMode is set to INCLUDE_LENGTH, the length is included as the first token.
268 //! The endianness of the serialization can be controlled via the endianMode parameter.
269 //!
270 //! \param buff Pointer to the buffer containing data to serialize
271 //! \param length Number of bytes to serialize from the buffer
272 //! \param lengthMode Specifies whether to include length in serialization (INCLUDE_LENGTH or OMIT_LENGTH)
273 //! \param endianMode Endianness mode for serialization (default is Endianness::BIG)
274 //! \return SerializeStatus indicating the result of the operation
275 virtual SerializeStatus serializeFrom(const U8* buff,
276 FwSizeType length,
277 Serialization::t lengthMode,
278 Endianness endianMode = Endianness::BIG) = 0;
279
280 //! \brief Serialize another LinearBufferBase object
281 //!
282 //! This method serializes the contents of another LinearBufferBase object
283 //! into this buffer. The endianness of the serialization can be controlled
284 //! via the mode parameter.
285 //!
286 //! \param val Reference to the LinearBufferBase object to serialize
287 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
288 //! \return SerializeStatus indicating the result of the operation
289 virtual SerializeStatus serializeFrom(const LinearBufferBase& val, Endianness mode = Endianness::BIG) = 0;
290
291 //! \brief Serialize a Serializable object
292 //!
293 //! This method serializes an object derived from the Serializable base class
294 //! into this buffer. The endianness of the serialization can be controlled
295 //! via the mode parameter.
296 //!
297 //! \param val Reference to the Serializable object to serialize
298 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
299 //! \return SerializeStatus indicating the result of the operation
300 virtual SerializeStatus serializeFrom(const Serializable& val, Endianness mode = Endianness::BIG) = 0;
301
302 //! \brief Serialize a size value
303 //!
304 //! This method serializes a size value (typically used for buffer sizes)
305 //! into this buffer. The endianness of the serialization can be controlled
306 //! via the mode parameter.
307 //!
308 //! \param size The size value to serialize
309 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
310 //! \return SerializeStatus indicating the result of the operation
311 virtual SerializeStatus serializeSize(const FwSizeType size, Endianness mode = Endianness::BIG) = 0;
312
313 // Deserialization for built-in types
314
315 //! \brief Deserialize an 8-bit unsigned integer value
316 //!
317 //! This method reads an 8-bit unsigned integer value from the deserialization
318 //! buffer and stores it in the provided reference. The endianness of the
319 //! deserialization can be controlled via the mode parameter.
320 //!
321 //! \param val Reference to store the deserialized 8-bit unsigned integer value
322 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
323 //! \return SerializeStatus indicating the result of the operation
324 virtual SerializeStatus deserializeTo(U8& val, Endianness mode = Endianness::BIG) = 0;
325
326 //! \brief Deserialize an 8-bit signed integer value
327 //!
328 //! This method reads an 8-bit signed integer value from the deserialization
329 //! buffer and stores it in the provided reference. The endianness of the
330 //! deserialization can be controlled via the mode parameter.
331 //!
332 //! \param val Reference to store the deserialized 8-bit signed integer value
333 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
334 //! \return SerializeStatus indicating the result of the operation
335 virtual SerializeStatus deserializeTo(I8& val, Endianness mode = Endianness::BIG) = 0;
336
337 #if FW_HAS_16_BIT == 1
338 //! \brief Deserialize a 16-bit unsigned integer value
339 //!
340 //! This method reads a 16-bit unsigned integer value from the deserialization
341 //! buffer and stores it in the provided reference. The endianness of the
342 //! deserialization can be controlled via the mode parameter.
343 //!
344 //! \param val Reference to store the deserialized 16-bit unsigned integer value
345 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
346 //! \return SerializeStatus indicating the result of the operation
347 virtual SerializeStatus deserializeTo(U16& val, Endianness mode = Endianness::BIG) = 0;
348
349 //! \brief Deserialize a 16-bit signed integer value
350 //!
351 //! This method reads a 16-bit signed integer value from the deserialization
352 //! buffer and stores it in the provided reference. The endianness of the
353 //! deserialization can be controlled via the mode parameter.
354 //!
355 //! \param val Reference to store the deserialized 16-bit signed integer value
356 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
357 //! \return SerializeStatus indicating the result of the operation
358 virtual SerializeStatus deserializeTo(I16& val, Endianness mode = Endianness::BIG) = 0;
359 #endif
360
361 #if FW_HAS_32_BIT == 1
362 //! \brief Deserialize a 32-bit unsigned integer value
363 //!
364 //! This method reads a 32-bit unsigned integer value from the deserialization
365 //! buffer and stores it in the provided reference. The endianness of the
366 //! deserialization can be controlled via the mode parameter.
367 //!
368 //! \param val Reference to store the deserialized 32-bit unsigned integer value
369 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
370 //! \return SerializeStatus indicating the result of the operation
371 virtual SerializeStatus deserializeTo(U32& val, Endianness mode = Endianness::BIG) = 0;
372
373 //! \brief Deserialize a 32-bit signed integer value
374 //!
375 //! This method reads a 32-bit signed integer value from the deserialization
376 //! buffer and stores it in the provided reference. The endianness of the
377 //! deserialization can be controlled via the mode parameter.
378 //!
379 //! \param val Reference to store the deserialized 32-bit signed integer value
380 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
381 //! \return SerializeStatus indicating the result of the operation
382 virtual SerializeStatus deserializeTo(I32& val, Endianness mode = Endianness::BIG) = 0;
383 #endif
384 #if FW_HAS_64_BIT == 1
385 //! \brief Deserialize a 64-bit unsigned integer value
386 //!
387 //! This method reads a 64-bit unsigned integer value from the deserialization
388 //! buffer and stores it in the provided reference. The endianness of the
389 //! deserialization can be controlled via the mode parameter.
390 //!
391 //! \param val Reference to store the deserialized 64-bit unsigned integer value
392 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
393 //! \return SerializeStatus indicating the result of the operation
394 virtual SerializeStatus deserializeTo(U64& val, Endianness mode = Endianness::BIG) = 0;
395
396 //! \brief Deserialize a 64-bit signed integer value
397 //!
398 //! This method reads a 64-bit signed integer value from the deserialization
399 //! buffer and stores it in the provided reference. The endianness of the
400 //! deserialization can be controlled via the mode parameter.
401 //!
402 //! \param val Reference to store the deserialized 64-bit signed integer value
403 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
404 //! \return SerializeStatus indicating the result of the operation
405 virtual SerializeStatus deserializeTo(I64& val, Endianness mode = Endianness::BIG) = 0;
406 #endif
407 //! \brief Deserialize a 32-bit floating point value
408 //!
409 //! This method reads a 32-bit floating point value from the deserialization
410 //! buffer and stores it in the provided reference. The endianness of the
411 //! deserialization can be controlled via the mode parameter.
412 //!
413 //! \param val Reference to store the deserialized 32-bit floating point value
414 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
415 //! \return SerializeStatus indicating the result of the operation
416 virtual SerializeStatus deserializeTo(F32& val, Endianness mode = Endianness::BIG) = 0;
417
418 //! \brief Deserialize a 64-bit floating point value
419 //!
420 //! This method reads a 64-bit floating point value from the deserialization
421 //! buffer and stores it in the provided reference. The endianness of the
422 //! deserialization can be controlled via the mode parameter.
423 //!
424 //! \param val Reference to store the deserialized 64-bit floating point value
425 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
426 //! \return SerializeStatus indicating the result of the operation
427 virtual SerializeStatus deserializeTo(F64& val, Endianness mode = Endianness::BIG) = 0;
428
429 //! \brief Deserialize a boolean value
430 //!
431 //! This method reads a boolean value from the deserialization buffer
432 //! and stores it in the provided reference. The endianness of the
433 //! deserialization can be controlled via the mode parameter.
434 //!
435 //! \param val Reference to store the deserialized boolean value
436 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
437 //! \return SerializeStatus indicating the result of the operation
438 virtual SerializeStatus deserializeTo(bool& val, Endianness mode = Endianness::BIG) = 0;
439
440 //! \brief Deserialize a pointer value
441 //!
442 //! This method reads a pointer value from the deserialization buffer
443 //! and stores it in the provided reference. Note that only the pointer
444 //! value itself is deserialized, not the contents it points to. The
445 //! endianness of the deserialization can be controlled via the mode parameter.
446 //!
447 //! \param val Reference to store the deserialized pointer value
448 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
449 //! \return SerializeStatus indicating the result of the operation
450 virtual SerializeStatus deserializeTo(void*& val, Endianness mode = Endianness::BIG) = 0;
451
452 //! \brief Deserialize a data buffer
453 //!
454 //! This method reads a buffer of bytes from the deserialization buffer
455 //! and stores them in the provided buffer. The endianness of the
456 //! deserialization can be controlled via the endianMode parameter.
457 //!
458 //! \param buff Pointer to the buffer where deserialized data will be stored
459 //! \param length Reference to store the actual number of bytes deserialized
460 //! \param endianMode Endianness mode for deserialization (default is Endianness::BIG)
461 //! \return SerializeStatus indicating the result of the operation
462 virtual SerializeStatus deserializeTo(U8* buff, FwSizeType& length, Endianness endianMode = Endianness::BIG) = 0;
463
464 //! \brief Deserialize a byte buffer with optional length prefix
465 //!
466 //! This method reads a buffer of bytes from the deserialization buffer
467 //! and stores them in the provided buffer. If lengthMode indicates that
468 //! a length prefix was included, it will be read from the buffer first.
469 //! The endianness of the deserialization can be controlled via the
470 //! endianMode parameter.
471 //!
472 //! \param buff Pointer to the buffer where deserialized data will be stored
473 //! \param length Reference to store the actual number of bytes deserialized
474 //! \param lengthMode Specifies whether length was included in serialization (INCLUDE_LENGTH or OMIT_LENGTH)
475 //! \param endianMode Endianness mode for deserialization (default is Endianness::BIG)
476 //! \return SerializeStatus indicating the result of the operation
477 virtual SerializeStatus deserializeTo(U8* buff,
478 FwSizeType& length,
479 Serialization::t lengthMode,
480 Endianness endianMode = Endianness::BIG) = 0;
481
482 //! \brief Deserialize a Serializable object
483 //!
484 //! This method reads data from the deserialization buffer and reconstructs
485 //! a Serializable object from it. The endianness of the deserialization
486 //! can be controlled via the mode parameter.
487 //!
488 //! \param val Reference to the Serializable object that will be populated with deserialized data
489 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
490 //! \return SerializeStatus indicating the result of the operation
491 virtual SerializeStatus deserializeTo(Serializable& val, Endianness mode = Endianness::BIG) = 0;
492
493 //! \brief Deserialize a LinearBufferBase object
494 //!
495 //! This method reads data from the deserialization buffer and reconstructs
496 //! a LinearBufferBase object from it. The endianness of the deserialization
497 //! can be controlled via the mode parameter.
498 //!
499 //! \param val Reference to the LinearBufferBase object that will be populated with deserialized data
500 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
501 //! \return SerializeStatus indicating the result of the operation
502 virtual SerializeStatus deserializeTo(LinearBufferBase& val, Endianness mode = Endianness::BIG) = 0;
503
504 //! \brief Deserialize a size value
505 //!
506 //! This method reads a size value (typically used for buffer sizes)
507 //! from the deserialization buffer. The endianness of the deserialization
508 //! can be controlled via the mode parameter.
509 //!
510 //! \param size Reference to store the deserialized size value
511 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
512 //! \return SerializeStatus indicating the result of the operation
513 virtual SerializeStatus deserializeSize(FwSizeType& size, Endianness mode = Endianness::BIG) = 0;
514
515 //! \brief Copy raw bytes from the source (this) into a destination buffer and advance source offset
516 //!
517 //! Copies exactly `size` bytes starting at the current deserialization pointer of `this` into `dest`.
518 //! This operation does not prepend a length field and does not interpret the data.
519 //!
520 //! Preconditions:
521 //! - `size` bytes must remain in the source (`getDeserializeSizeLeft() >= size`).
522 //! - Destination must have sufficient capacity (`dest.getCapacity() >= size`).
523 //!
524 //! Post-conditions on success:
525 //! - `dest` contains exactly the copied bytes and its previous contents are discarded.
526 //! - `this` has advanced its deserialization pointer by `size` bytes.
527 //!
528 //! \param dest Destination serialization buffer to receive the bytes (its contents are replaced)
529 //! \param size Number of bytes to copy from the source
530 //! \return `FW_SERIALIZE_OK` on success; `FW_SERIALIZE_NO_ROOM_LEFT` if destination capacity is insufficient;
531 //! `FW_DESERIALIZE_SIZE_MISMATCH` if source does not contain `size` bytes remaining
532 virtual SerializeStatus copyRaw(SerialBufferBase& dest, Serializable::SizeType size) = 0;
533
534 //! \brief Append raw bytes to destination (no length) and advance source offset
535 //!
536 //! Appends exactly `size` bytes from the current deserialization pointer of `this` into `dest` using
537 //! `Serialization::OMIT_LENGTH`, preserving any existing bytes already serialized in `dest`.
538 //!
539 //! Preconditions:
540 //! - `size` bytes must remain in the source (`getDeserializeSizeLeft() >= size`).
541 //! - Destination must have space for the append (`dest.getCapacity() >= dest.getSize() + size`).
542 //!
543 //! Post-conditions on success:
544 //! - `dest` gains `size` additional bytes at the end; no length token is written.
545 //! - `this` has advanced its deserialization pointer by `size` bytes.
546 //!
547 //! \param dest Destination serialization buffer to append to
548 //! \param size Number of bytes to copy from the source and append to dest
549 //! \return `FW_SERIALIZE_OK` on success; `FW_SERIALIZE_NO_ROOM_LEFT` if destination capacity is insufficient;
550 //! `FW_DESERIALIZE_SIZE_MISMATCH` if source does not contain `size` bytes remaining
551 virtual SerializeStatus copyRawOffset(SerialBufferBase& dest, Serializable::SizeType size) = 0;
552
553 //! \brief Reset serialization pointer to beginning of buffer
554 //!
555 //! This method resets the serialization pointer to the beginning of the buffer,
556 //! allowing the buffer to be reused for new serialization operations. Any
557 //! data that was previously serialized in the buffer will be overwritten.
558 virtual void resetSer() = 0;
559
560 //! \brief Reset deserialization pointer to beginning of buffer
561 //!
562 //! This method resets the deserialization pointer to the beginning of the buffer,
563 //! allowing the buffer to be reused for new deserialization operations. The buffer
564 //! contents are not modified, but the pointer is reset to allow reading from the
565 //! start of the data.
566 virtual void resetDeser() = 0;
567
568 //! \brief Move serialization pointer to specified offset
569 //!
570 //! This method moves the serialization pointer to the specified offset within
571 //! the buffer. This allows for skipping over data or positioning the serializer
572 //! at a specific location in the buffer.
573 //!
574 //! \param offset The offset to move the serialization pointer to
575 //! \return SerializeStatus indicating the result of the operation
576 virtual SerializeStatus moveSerToOffset(FwSizeType offset) = 0;
577
578 //! \brief Move deserialization pointer to specified offset
579 //!
580 //! This method moves the deserialization pointer to the specified offset within
581 //! the buffer. This allows for skipping over data or positioning the deserializer
582 //! at a specific location in the buffer.
583 //!
584 //! \param offset The offset to move the deserialization pointer to
585 //! \return SerializeStatus indicating the result of the operation
586 virtual SerializeStatus moveDeserToOffset(FwSizeType offset) = 0;
587
588 //! \brief Skip specified number of bytes during serialization
589 //!
590 //! This method advances the serialization pointer by the specified number of bytes
591 //! without writing any data. This can be used to reserve space in the buffer or skip
592 //! over data that will be written later.
593 //!
594 //! \param numBytesToSkip Number of bytes to skip during serialization
595 //! \return SerializeStatus indicating the result of the operation
596 virtual SerializeStatus serializeSkip(FwSizeType numBytesToSkip) = 0;
597
598 //! \brief Skip specified number of bytes during deserialization
599 //!
600 //! This method advances the deserialization pointer by the specified number of bytes
601 //! without reading any data. This can be used to skip over data in the buffer that
602 //! is not needed or to advance to the next relevant data segment.
603 //!
604 //! \param numBytesToSkip Number of bytes to skip during deserialization
605 //! \return SerializeStatus indicating the result of the operation
606 virtual SerializeStatus deserializeSkip(FwSizeType numBytesToSkip) = 0;
607
608 //! \brief Get buffer capacity
609 //!
610 //! This method returns the total capacity of the buffer, which is the maximum
611 //! amount of data that can be stored in the buffer. This is not the same as
612 //! the current size, which indicates how much data is currently in the buffer.
613 //!
614 //! \return The capacity of the buffer in bytes
615 virtual Serializable::SizeType getCapacity() const = 0;
616
617 //! \brief Get current buffer size
618 //!
619 //! This method returns the current size of the buffer, which indicates how
620 //! much data is currently stored in the buffer. This may be less than or
621 //! equal to the buffer's capacity.
622 //!
623 //! \return The current size of the buffer in bytes
624 virtual Serializable::SizeType getSize() const = 0;
625
626 //! \brief Get remaining deserialization buffer size
627 //!
628 //! This method returns the amount of data that remains to be deserialized
629 //! from the buffer. It indicates how much data is left starting from the
630 //! current deserialization pointer to the end of the valid size (returned by getSize()).
631 //!
632 //! \return The remaining size of the deserialization buffer in bytes
633 virtual Serializable::SizeType getDeserializeSizeLeft() const = 0;
634
635 //! \brief Get remaining serialization buffer size
636 //!
637 //! This method returns the amount of space available for serialization
638 //! in the buffer. It indicates how much data can still be written to the
639 //! buffer starting from the current serialization pointer to the end of
640 //! the buffer's capacity.
641 //!
642 //! \return The remaining size of the serialization buffer in bytes
643 virtual Serializable::SizeType getSerializeSizeLeft() const = 0;
644
645 //! \brief Set buffer contents from external source
646 //!
647 //! This method sets the contents of the buffer from an external source.
648 //! It copies the specified number of bytes from the source pointer into
649 //! the buffer and updates the buffer size accordingly.
650 //!
651 //! \param src Pointer to the external data source
652 //! \param length Number of bytes to copy from the source
653 //! \return SerializeStatus indicating the result of the operation
654 virtual SerializeStatus setBuff(const U8* src, Serializable::SizeType length) = 0;
655
656 //! \brief Set buffer length manually
657 //!
658 //! This method manually sets the length of the buffer without modifying
659 //! its contents. This can be used after filling the buffer with data through
660 //! other means to indicate how much valid data is in the buffer.
661 //!
662 //! \param length The new length to set for the buffer
663 //! \return SerializeStatus indicating the result of the operation
664 virtual SerializeStatus setBuffLen(Serializable::SizeType length) = 0;
665 };
666
667 class LinearBufferBase : public SerialBufferBase {
668 friend class LinearBufferBaseTester;
669
670 protected:
671 //! \brief Copy assignment operator
672 //!
673 //! Assigns the contents of another LinearBufferBase instance to this one.
674 //! This includes copying the buffer data, serialization location, and
675 //! deserialization location from the source to this instance.
676 //!
677 //! \param src Reference to the source LinearBufferBase to copy from
678 //! \return Reference to this instance after assignment
679 LinearBufferBase& operator=(const LinearBufferBase& src);
680
681 public:
682 //! \brief Get the static serialized size of a buffer
683 //! This is the max size of the buffer data plus the size of the stored size
684 static constexpr Serializable::SizeType STATIC_SERIALIZED_SIZE(
685 Serializable::SizeType maxSize //!< The maximum buffer data size
686 ) {
687 return static_cast<Serializable::SizeType>(sizeof(FwSizeStoreType)) + maxSize;
688 }
689
690 //! \brief Destructor
691 //!
692 //! Destroys a LinearBufferBase instance. This is a virtual destructor
693 //! that allows proper cleanup of derived classes.
694 virtual ~LinearBufferBase();
695
696 // Serialization for built-in types
697
698 //! \brief Serialize an 8-bit unsigned integer value
699 //!
700 //! This method serializes a single 8-bit unsigned integer value into the buffer.
701 //! The endianness of the serialization can be controlled via the mode parameter.
702 //!
703 //! NOTE: The 'mode' argument here for endianness has no effect as there is no
704 //! concept of endianness for an U8. It has been left in for compatibility.
705 //!
706 //! \param val The 8-bit unsigned integer value to serialize
707 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
708 //! \return SerializeStatus indicating the result of the operation
709 SerializeStatus serializeFrom(U8 val, Endianness mode = Endianness::BIG) override;
710
711 //! \brief Serialize an 8-bit signed integer value
712 //!
713 //! This method serializes a single 8-bit signed integer value into the buffer.
714 //! The endianness of the serialization can be controlled via the mode parameter.
715 //!
716 //! NOTE: The 'mode' argument here for endianness has no effect as there is no
717 //! concept of endianness for an I8. It has been left in for compatibility.
718 //!
719 //! \param val The 8-bit signed integer value to serialize
720 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
721 //! \return SerializeStatus indicating the result of the operation
722 SerializeStatus serializeFrom(I8 val, Endianness mode = Endianness::BIG) override;
723
724 #if FW_HAS_16_BIT == 1
725 //! \brief Serialize a 16-bit unsigned integer value
726 //!
727 //! This method serializes a single 16-bit unsigned integer value into the buffer.
728 //! The endianness of the serialization can be controlled via the mode parameter.
729 //!
730 //! \param val The 16-bit unsigned integer value to serialize
731 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
732 //! \return SerializeStatus indicating the result of the operation
733 SerializeStatus serializeFrom(U16 val, Endianness mode = Endianness::BIG) override;
734
735 //! \brief Serialize a 16-bit signed integer value
736 //!
737 //! This method serializes a single 16-bit signed integer value into the buffer.
738 //! The endianness of the serialization can be controlled via the mode parameter.
739 //!
740 //! \param val The 16-bit signed integer value to serialize
741 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
742 //! \return SerializeStatus indicating the result of the operation
743 SerializeStatus serializeFrom(I16 val, Endianness mode = Endianness::BIG) override;
744 #endif
745 #if FW_HAS_32_BIT == 1
746 //! \brief Serialize a 32-bit unsigned integer value
747 //!
748 //! This method serializes a single 32-bit unsigned integer value into the buffer.
749 //! The endianness of the serialization can be controlled via the mode parameter.
750 //!
751 //! \param val The 32-bit unsigned integer value to serialize
752 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
753 //! \return SerializeStatus indicating the result of the operation
754 SerializeStatus serializeFrom(U32 val, Endianness mode = Endianness::BIG) override;
755
756 //! \brief Serialize a 32-bit signed integer value
757 //!
758 //! This method serializes a single 32-bit signed integer value into the buffer.
759 //! The endianness of the serialization can be controlled via the mode parameter.
760 //!
761 //! \param val The 32-bit signed integer value to serialize
762 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
763 //! \return SerializeStatus indicating the result of the operation
764 SerializeStatus serializeFrom(I32 val, Endianness mode = Endianness::BIG) override;
765 #endif
766 #if FW_HAS_64_BIT == 1
767 //! \brief Serialize a 64-bit unsigned integer value
768 //!
769 //! This method serializes a single 64-bit unsigned integer value into the buffer.
770 //! The endianness of the serialization can be controlled via the mode parameter.
771 //!
772 //! \param val The 64-bit unsigned integer value to serialize
773 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
774 //! \return SerializeStatus indicating the result of the operation
775 SerializeStatus serializeFrom(U64 val, Endianness mode = Endianness::BIG) override;
776
777 //! \brief Serialize a 64-bit signed integer value
778 //!
779 //! This method serializes a single 64-bit signed integer value into the buffer.
780 //! The endianness of the serialization can be controlled via the mode parameter.
781 //!
782 //! \param val The 64-bit signed integer value to serialize
783 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
784 //! \return SerializeStatus indicating the result of the operation
785 SerializeStatus serializeFrom(I64 val, Endianness mode = Endianness::BIG) override;
786 #endif
787 //! \brief Serialize a 32-bit floating point value
788 //!
789 //! This method serializes a single 32-bit floating point value into the buffer.
790 //! The endianness of the serialization can be controlled via the mode parameter.
791 //!
792 //! \param val The 32-bit floating point value to serialize
793 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
794 //! \return SerializeStatus indicating the result of the operation
795 SerializeStatus serializeFrom(F32 val, Endianness mode = Endianness::BIG) override;
796
797 //! \brief Serialize a 64-bit floating point value
798 //!
799 //! This method serializes a single 64-bit floating point value into the buffer.
800 //! The endianness of the serialization can be controlled via the mode parameter.
801 //!
802 //! \param val The 64-bit floating point value to serialize
803 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
804 //! \return SerializeStatus indicating the result of the operation
805 SerializeStatus serializeFrom(F64 val, Endianness mode = Endianness::BIG) override;
806
807 //! \brief Serialize a boolean value
808 //!
809 //! This method serializes a single boolean value into the buffer.
810 //! The endianness of the serialization can be controlled via the mode parameter.
811 //!
812 //! \param val The boolean value to serialize
813 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
814 //! \return SerializeStatus indicating the result of the operation
815 SerializeStatus serializeFrom(bool val, Endianness mode = Endianness::BIG) override;
816
817 //! \brief Serialize a pointer value
818 //!
819 //! This method serializes a pointer value into the buffer. Note that only
820 //! the pointer value itself is serialized, not the contents it points to.
821 //! The endianness of the serialization can be controlled via the mode parameter.
822 //!
823 //! \param val The pointer value to serialize
824 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
825 //! \return SerializeStatus indicating the result of the operation
826 SerializeStatus serializeFrom(const void* val, Endianness mode = Endianness::BIG) override;
827
828 //! \brief Serialize a data buffer
829 //!
830 //! This method serializes a buffer of bytes into the serialization buffer.
831 //! The endianness of the serialization can be controlled via the endianMode parameter.
832 //!
833 //! \param buff Pointer to the buffer containing data to serialize
834 //! \param length Number of bytes to serialize from the buffer
835 //! \param endianMode Endianness mode for serialization (default is Endianness::BIG)
836 //! \return SerializeStatus indicating the result of the operation
837 SerializeStatus serializeFrom(const U8* buff, FwSizeType length, Endianness endianMode = Endianness::BIG) override;
838
839 //! \brief Serialize a byte buffer with optional length prefix
840 //!
841 //! This method serializes a buffer of bytes into the serialization buffer.
842 //! If lengthMode is set to INCLUDE_LENGTH, the length is included as the first token.
843 //! The endianness of the serialization can be controlled via the endianMode parameter.
844 //!
845 //! \param buff Pointer to the buffer containing data to serialize
846 //! \param length Number of bytes to serialize from the buffer
847 //! \param lengthMode Specifies whether to include length in serialization (INCLUDE_LENGTH or OMIT_LENGTH)
848 //! \param endianMode Endianness mode for serialization (default is Endianness::BIG)
849 //! \return SerializeStatus indicating the result of the operation
850 SerializeStatus serializeFrom(const U8* buff,
851 FwSizeType length,
852 Serialization::t lengthMode,
853 Endianness endianMode = Endianness::BIG) override;
854
855 //! \brief Serialize another LinearBufferBase object
856 //!
857 //! This method serializes the contents of another LinearBufferBase object
858 //! into this buffer. The endianness of the serialization can be controlled
859 //! via the mode parameter.
860 //!
861 //! \param val Reference to the LinearBufferBase object to serialize
862 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
863 //! \return SerializeStatus indicating the result of the operation
864 SerializeStatus serializeFrom(const LinearBufferBase& val, Endianness mode = Endianness::BIG) override;
865
866 //! \brief Serialize a Serializable object
867 //!
868 //! This method serializes an object derived from the Serializable base class
869 //! into this buffer. The endianness of the serialization can be controlled
870 //! via the mode parameter.
871 //!
872 //! \param val Reference to the Serializable object to serialize
873 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
874 //! \return SerializeStatus indicating the result of the operation
875 SerializeStatus serializeFrom(const Serializable& val, Endianness mode = Endianness::BIG) override;
876
877 //! \brief Serialize a size value
878 //!
879 //! This method serializes a size value (typically used for buffer sizes)
880 //! into this buffer. The endianness of the serialization can be controlled
881 //! via the mode parameter.
882 //!
883 //! \param size The size value to serialize
884 //! \param mode Endianness mode for serialization (default is Endianness::BIG)
885 //! \return SerializeStatus indicating the result of the operation
886 SerializeStatus serializeSize(const FwSizeType size, Endianness mode = Endianness::BIG) override;
887
888 // Deserialization for built-in types
889
890 //! \brief Deserialize an 8-bit unsigned integer value
891 //!
892 //! This method reads an 8-bit unsigned integer value from the deserialization
893 //! buffer and stores it in the provided reference. The endianness of the
894 //! deserialization can be controlled via the mode parameter.
895 //!
896 //! \param val Reference to store the deserialized 8-bit unsigned integer value
897 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
898 //! \return SerializeStatus indicating the result of the operation
899 SerializeStatus deserializeTo(U8& val, Endianness mode = Endianness::BIG) override;
900
901 //! \brief Deserialize an 8-bit signed integer value
902 //!
903 //! This method reads an 8-bit signed integer value from the deserialization
904 //! buffer and stores it in the provided reference. The endianness of the
905 //! deserialization can be controlled via the mode parameter.
906 //!
907 //! \param val Reference to store the deserialized 8-bit signed integer value
908 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
909 //! \return SerializeStatus indicating the result of the operation
910 SerializeStatus deserializeTo(I8& val, Endianness mode = Endianness::BIG) override;
911
912 #if FW_HAS_16_BIT == 1
913 //! \brief Deserialize a 16-bit unsigned integer value
914 //!
915 //! This method reads a 16-bit unsigned integer value from the deserialization
916 //! buffer and stores it in the provided reference. The endianness of the
917 //! deserialization can be controlled via the mode parameter.
918 //!
919 //! \param val Reference to store the deserialized 16-bit unsigned integer value
920 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
921 //! \return SerializeStatus indicating the result of the operation
922 SerializeStatus deserializeTo(U16& val, Endianness mode = Endianness::BIG) override;
923
924 //! \brief Deserialize a 16-bit signed integer value
925 //!
926 //! This method reads a 16-bit signed integer value from the deserialization
927 //! buffer and stores it in the provided reference. The endianness of the
928 //! deserialization can be controlled via the mode parameter.
929 //!
930 //! \param val Reference to store the deserialized 16-bit signed integer value
931 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
932 //! \return SerializeStatus indicating the result of the operation
933 SerializeStatus deserializeTo(I16& val, Endianness mode = Endianness::BIG) override;
934 #endif
935
936 #if FW_HAS_32_BIT == 1
937 //! \brief Deserialize a 32-bit unsigned integer value
938 //!
939 //! This method reads a 32-bit unsigned integer value from the deserialization
940 //! buffer and stores it in the provided reference. The endianness of the
941 //! deserialization can be controlled via the mode parameter.
942 //!
943 //! \param val Reference to store the deserialized 32-bit unsigned integer value
944 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
945 //! \return SerializeStatus indicating the result of the operation
946 SerializeStatus deserializeTo(U32& val, Endianness mode = Endianness::BIG) override;
947
948 //! \brief Deserialize a 32-bit signed integer value
949 //!
950 //! This method reads a 32-bit signed integer value from the deserialization
951 //! buffer and stores it in the provided reference. The endianness of the
952 //! deserialization can be controlled via the mode parameter.
953 //!
954 //! \param val Reference to store the deserialized 32-bit signed integer value
955 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
956 //! \return SerializeStatus indicating the result of the operation
957 SerializeStatus deserializeTo(I32& val, Endianness mode = Endianness::BIG) override;
958 #endif
959 #if FW_HAS_64_BIT == 1
960 //! \brief Deserialize a 64-bit unsigned integer value
961 //!
962 //! This method reads a 64-bit unsigned integer value from the deserialization
963 //! buffer and stores it in the provided reference. The endianness of the
964 //! deserialization can be controlled via the mode parameter.
965 //!
966 //! \param val Reference to store the deserialized 64-bit unsigned integer value
967 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
968 //! \return SerializeStatus indicating the result of the operation
969 SerializeStatus deserializeTo(U64& val, Endianness mode = Endianness::BIG) override;
970
971 //! \brief Deserialize a 64-bit signed integer value
972 //!
973 //! This method reads a 64-bit signed integer value from the deserialization
974 //! buffer and stores it in the provided reference. The endianness of the
975 //! deserialization can be controlled via the mode parameter.
976 //!
977 //! \param val Reference to store the deserialized 64-bit signed integer value
978 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
979 //! \return SerializeStatus indicating the result of the operation
980 SerializeStatus deserializeTo(I64& val, Endianness mode = Endianness::BIG) override;
981 #endif
982 //! \brief Deserialize a 32-bit floating point value
983 //!
984 //! This method reads a 32-bit floating point value from the deserialization
985 //! buffer and stores it in the provided reference. The endianness of the
986 //! deserialization can be controlled via the mode parameter.
987 //!
988 //! \param val Reference to store the deserialized 32-bit floating point value
989 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
990 //! \return SerializeStatus indicating the result of the operation
991 SerializeStatus deserializeTo(F32& val, Endianness mode = Endianness::BIG) override;
992
993 //! \brief Deserialize a 64-bit floating point value
994 //!
995 //! This method reads a 64-bit floating point value from the deserialization
996 //! buffer and stores it in the provided reference. The endianness of the
997 //! deserialization can be controlled via the mode parameter.
998 //!
999 //! \param val Reference to store the deserialized 64-bit floating point value
1000 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1001 //! \return SerializeStatus indicating the result of the operation
1002 SerializeStatus deserializeTo(F64& val, Endianness mode = Endianness::BIG) override;
1003
1004 //! \brief Deserialize a boolean value
1005 //!
1006 //! This method reads a boolean value from the deserialization buffer
1007 //! and stores it in the provided reference. The endianness of the
1008 //! deserialization can be controlled via the mode parameter.
1009 //!
1010 //! \param val Reference to store the deserialized boolean value
1011 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1012 //! \return SerializeStatus indicating the result of the operation
1013 SerializeStatus deserializeTo(bool& val, Endianness mode = Endianness::BIG) override;
1014
1015 //! \brief Deserialize a pointer value
1016 //!
1017 //! This method reads a pointer value from the deserialization buffer
1018 //! and stores it in the provided reference. Note that only the pointer
1019 //! value itself is deserialized, not the contents it points to. The
1020 //! endianness of the deserialization can be controlled via the mode parameter.
1021 //!
1022 //! \param val Reference to store the deserialized pointer value
1023 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1024 //! \return SerializeStatus indicating the result of the operation
1025 SerializeStatus deserializeTo(void*& val, Endianness mode = Endianness::BIG) override;
1026
1027 //! \brief Deserialize a data buffer
1028 //!
1029 //! This method reads a buffer of bytes from the deserialization buffer
1030 //! and stores them in the provided buffer. The endianness of the
1031 //! deserialization can be controlled via the endianMode parameter.
1032 //!
1033 //! \param buff Pointer to the buffer where deserialized data will be stored
1034 //! \param length Reference to store the actual number of bytes deserialized
1035 //! \param endianMode Endianness mode for deserialization (default is Endianness::BIG)
1036 //! \return SerializeStatus indicating the result of the operation
1037 SerializeStatus deserializeTo(U8* buff, FwSizeType& length, Endianness endianMode = Endianness::BIG) override;
1038
1039 //! \brief Deserialize a byte buffer with optional length prefix
1040 //!
1041 //! This method reads a buffer of bytes from the deserialization buffer
1042 //! and stores them in the provided buffer. If lengthMode indicates that
1043 //! a length prefix was included, it will be read from the buffer first.
1044 //! The endianness of the deserialization can be controlled via the
1045 //! endianMode parameter.
1046 //!
1047 //! \param buff Pointer to the buffer where deserialized data will be stored
1048 //! \param length Reference to store the actual number of bytes deserialized
1049 //! \param lengthMode Specifies whether length was included in serialization (INCLUDE_LENGTH or OMIT_LENGTH)
1050 //! \param endianMode Endianness mode for deserialization (default is Endianness::BIG)
1051 //! \return SerializeStatus indicating the result of the operation
1052 SerializeStatus deserializeTo(U8* buff,
1053 FwSizeType& length,
1054 Serialization::t lengthMode,
1055 Endianness endianMode = Endianness::BIG) override;
1056
1057 //! \brief Deserialize a Serializable object
1058 //!
1059 //! This method reads data from the deserialization buffer and reconstructs
1060 //! a Serializable object from it. The endianness of the deserialization
1061 //! can be controlled via the mode parameter.
1062 //!
1063 //! \param val Reference to the Serializable object that will be populated with deserialized data
1064 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1065 //! \return SerializeStatus indicating the result of the operation
1066 SerializeStatus deserializeTo(Serializable& val, Endianness mode = Endianness::BIG) override;
1067
1068 //! \brief Deserialize a LinearBufferBase object
1069 //!
1070 //! This method reads data from the deserialization buffer and reconstructs
1071 //! a LinearBufferBase object from it. The endianness of the deserialization
1072 //! can be controlled via the mode parameter.
1073 //!
1074 //! \param val Reference to the LinearBufferBase object that will be populated with deserialized data
1075 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1076 //! \return SerializeStatus indicating the result of the operation
1077 SerializeStatus deserializeTo(LinearBufferBase& val, Endianness mode = Endianness::BIG) override;
1078
1079 //! \brief Deserialize a size value
1080 //!
1081 //! This method reads a size value (typically used for buffer sizes)
1082 //! from the deserialization buffer. The endianness of the deserialization
1083 //! can be controlled via the mode parameter.
1084 //!
1085 //! \param size Reference to store the deserialized size value
1086 //! \param mode Endianness mode for deserialization (default is Endianness::BIG)
1087 //! \return SerializeStatus indicating the result of the operation
1088 SerializeStatus deserializeSize(FwSizeType& size, Endianness mode = Endianness::BIG) override;
1089
1090 DEPRECATED(SerializeStatus serialize(const LinearBufferBase& val),
1091 "Use serializeFrom(const SerialBufferBase& val) instead");
1092 DEPRECATED(SerializeStatus deserialize(LinearBufferBase& val), "Use deserializeTo(SerialBufferBase& val) instead");
1093
1094 //! \brief Reset serialization pointer to beginning of buffer
1095 //!
1096 //! This method resets the serialization pointer to the beginning of the buffer,
1097 //! allowing the buffer to be reused for new serialization operations. Any
1098 //! data that was previously serialized in the buffer will be overwritten.
1099 //!
1100 //! \return None
1101 void resetSer() override;
1102
1103 //! \brief Reset deserialization pointer to beginning of buffer
1104 //!
1105 //! This method resets the deserialization pointer to the beginning of the buffer,
1106 //! allowing the buffer to be reused for new deserialization operations. The buffer
1107 //! contents are not modified, but the pointer is reset to allow reading from the
1108 //! start of the data.
1109 //!
1110 //! \return None
1111 void resetDeser() override;
1112
1113 //! \brief Move serialization pointer to specified offset
1114 //!
1115 //! This method moves the serialization pointer to the specified offset within
1116 //! the buffer. This allows for skipping over data or positioning the serializer
1117 //! at a specific location in the buffer.
1118 //!
1119 //! \param offset The offset to move the serialization pointer to
1120 //! \return SerializeStatus indicating the result of the operation
1121 SerializeStatus moveSerToOffset(FwSizeType offset) override;
1122
1123 //! \brief Move deserialization pointer to specified offset
1124 //!
1125 //! This method moves the deserialization pointer to the specified offset within
1126 //! the buffer. This allows for skipping over data or positioning the deserializer
1127 //! at a specific location in the buffer.
1128 //!
1129 //! \param offset The offset to move the deserialization pointer to
1130 //! \return SerializeStatus indicating the result of the operation
1131 SerializeStatus moveDeserToOffset(FwSizeType offset) override;
1132
1133 //! \brief Skip specified number of bytes during serialization
1134 //!
1135 //! This method advances the serialization pointer by the specified number of bytes
1136 //! without writing any data. This can be used to reserve space in the buffer or skip
1137 //! over data that will be written later.
1138 //!
1139 //! \param numBytesToSkip Number of bytes to skip during serialization
1140 //! \return SerializeStatus indicating the result of the operation
1141 SerializeStatus serializeSkip(FwSizeType numBytesToSkip) override;
1142
1143 //! \brief Skip specified number of bytes during deserialization
1144 //!
1145 //! This method advances the deserialization pointer by the specified number of bytes
1146 //! without reading any data. This can be used to skip over data in the buffer that
1147 //! is not needed or to advance to the next relevant data segment.
1148 //!
1149 //! \param numBytesToSkip Number of bytes to skip during deserialization
1150 //! \return SerializeStatus indicating the result of the operation
1151 SerializeStatus deserializeSkip(FwSizeType numBytesToSkip) override;
1152
1153 DEPRECATED(Serializable::SizeType getBuffCapacity() const, "Use getCapacity() instead");
1154 DEPRECATED(Serializable::SizeType getBuffLength() const, "Use getSize() instead");
1155 DEPRECATED(Serializable::SizeType getBuffLeft(), "Use getDeserializeSizeLeft() instead");
1156
1157 //! \brief Get buffer capacity
1158 //!
1159 //! This method returns the total capacity of the buffer, which is the maximum
1160 //! amount of data that can be stored in the buffer. This is not the same as
1161 //! the current size, which indicates how much data is currently in the buffer.
1162 //!
1163 //! \return The capacity of the buffer in bytes
1164 Serializable::SizeType getCapacity() const override { return this->m_capacity; }
1165
1166 //! \brief Get current buffer size
1167 //!
1168 //! This method returns the current size of the buffer, which indicates how
1169 //! much data is currently stored in the buffer. This may be less than or
1170 //! equal to the buffer's capacity.
1171 //!
1172 //! \return The current size of the buffer in bytes
1173 Serializable::SizeType getSize() const override;
1174
1175 //! \brief Get remaining deserialization buffer size
1176 //!
1177 //! This method returns the amount of data that remains to be deserialized
1178 //! from the buffer. It indicates how much data is left starting from the
1179 //! current deserialization pointer to the end of the buffer.
1180 //!
1181 //! \return The remaining size of the deserialization buffer in bytes
1182 Serializable::SizeType getDeserializeSizeLeft() const override;
1183
1184 //! \brief Get remaining serialization buffer size
1185 //!
1186 //! This method returns the amount of space available for serialization
1187 //! in the buffer. It indicates how much data can still be written to the
1188 //! buffer starting from the current serialization pointer to the end of
1189 //! the buffer's capacity.
1190 //!
1191 //! \return The remaining size of the serialization buffer in bytes
1192 Serializable::SizeType getSerializeSizeLeft() const override;
1193
1194 //! \brief Get buffer address for data filling (non-const version)
1195 //!
1196 //! This method returns a pointer to the buffer's data area where data can
1197 //! be written. This is the non-const version of the method, allowing the
1198 //! buffer contents to be modified.
1199 //!
1200 //! \return Pointer to the buffer's data area
1201 U8* getBuffAddr() { return this->m_buffAddr; }
1202
1203 //! \brief Get buffer address for data reading (const version)
1204 //!
1205 //! This method returns a const pointer to the buffer's data area where data
1206 //! can be read. This is the const version of the method, preventing modification
1207 //! of the buffer contents.
1208 //!
1209 //! \return Const pointer to the buffer's data area
1210 const U8* getBuffAddr() const { return this->m_buffAddr; }
1211
1212 //! \brief Get address of remaining non-deserialized data
1213 //!
1214 //! This method returns a const pointer to the portion of the buffer that
1215 //! has not yet been deserialized. This can be used to examine remaining
1216 //! data or to determine how much data is left to process.
1217 //!
1218 //! \return Const pointer to the remaining non-deserialized data
1219 const U8* getBuffAddrLeft() const;
1220
1221 //! \brief Get address of end of serialization (DANGEROUS!)
1222 //!
1223 //! This method returns a pointer to the current end of serialized data
1224 //! in the buffer. This is a dangerous operation as it requires knowledge
1225 //! of the maximum buffer size and proper adjustment when done.
1226 //!
1227 //! \return Pointer to the end of serialized data
1228 U8* getBuffAddrSer();
1229
1230 //! \brief Set buffer contents from external source
1231 //!
1232 //! This method sets the contents of the buffer from an external source.
1233 //! It copies the specified number of bytes from the source pointer into
1234 //! the buffer and updates the buffer size accordingly.
1235 //!
1236 //! \param src Pointer to the external data source
1237 //! \param length Number of bytes to copy from the source
1238 //! \return SerializeStatus indicating the result of the operation
1239 SerializeStatus setBuff(const U8* src, Serializable::SizeType length) override;
1240
1241 //! \brief Set buffer length manually
1242 //!
1243 //! This method manually sets the length of the buffer without modifying
1244 //! its contents. This can be used after filling the buffer with data through
1245 //! other means to indicate how much valid data is in the buffer.
1246 //!
1247 //! \param length The new length to set for the buffer
1248 //! \return SerializeStatus indicating the result of the operation
1249 SerializeStatus setBuffLen(Serializable::SizeType length) override;
1250
1251 //! \brief Copy raw bytes from this buffer to destination and advance source offset
1252 //!
1253 //! This method copies exactly `size` bytes from the current position in this
1254 //! buffer to the destination buffer. It advances the source buffer's position
1255 //! by the number of bytes copied.
1256 //!
1257 //! \param dest Destination buffer to receive the copied data
1258 //! \param size Number of bytes to copy
1259 //! \return SerializeStatus indicating the result of the operation
1260 SerializeStatus copyRaw(SerialBufferBase& dest, Serializable::SizeType size) override;
1261
1262 //! \brief Append raw bytes to destination from this buffer and advance source offset
1263 //!
1264 //! This method appends exactly `size` bytes from the current position in this
1265 //! buffer to the destination buffer. It uses `Serialization::OMIT_LENGTH` mode,
1266 //! meaning no length token is written. The source buffer's position is advanced
1267 //! by the number of bytes copied.
1268 //!
1269 //! \param dest Destination buffer to append data to
1270 //! \param size Number of bytes to append
1271 //! \return SerializeStatus indicating the result of the operation
1272 SerializeStatus copyRawOffset(SerialBufferBase& dest, Serializable::SizeType size) override;
1273
1274 // ----------------------------------------------------------------------
1275 // Deprecated Serialization methods
1276 // ----------------------------------------------------------------------
1277
1278 DEPRECATED(SerializeStatus serialize(U8 val), "Use serializeFrom(U8 val) instead");
1279 DEPRECATED(SerializeStatus serialize(I8 val), "Use serializeFrom(I8 val) instead");
1280 #if FW_HAS_16_BIT == 1
1281 DEPRECATED(SerializeStatus serialize(U16 val), "Use serializeFrom(U16 val) instead");
1282 DEPRECATED(SerializeStatus serialize(I16 val), "Use serializeFrom(I16 val) instead");
1283 #endif
1284 #if FW_HAS_32_BIT == 1
1285 DEPRECATED(SerializeStatus serialize(U32 val), "Use serializeFrom(U32 val) instead");
1286 DEPRECATED(SerializeStatus serialize(I32 val), "Use serializeFrom(I32 val) instead");
1287 #endif
1288 #if FW_HAS_64_BIT == 1
1289 DEPRECATED(SerializeStatus serialize(U64 val), "Use serializeFrom(U64 val) instead");
1290 DEPRECATED(SerializeStatus serialize(I64 val), "Use serializeFrom(I64 val) instead");
1291 #endif
1292
1293 DEPRECATED(SerializeStatus serialize(F32 val), "Use serializeFrom(F32 val) instead");
1294 DEPRECATED(SerializeStatus serialize(F64 val), "Use serializeFrom(F64 val) instead");
1295 DEPRECATED(SerializeStatus serialize(bool val), "Use serializeFrom(bool val) instead");
1296 DEPRECATED(SerializeStatus serialize(const void* val), "Use serializeFrom(const void* val) instead");
1297 DEPRECATED(SerializeStatus serialize(const U8* buff, FwSizeType length, bool noLength),
1298 "Use serialize(const U8* buff, FwSizeType length, Serialization::t mode) instead");
1299 DEPRECATED(SerializeStatus serialize(const U8* buff, FwSizeType length),
1300 "Use serializeFrom(const U8* buff, FwSizeType length) instead");
1301 DEPRECATED(SerializeStatus serialize(const U8* buff, FwSizeType length, Serialization::t mode),
1302 "Use serializeFrom(const U8* buff, FwSizeType length, Serialization::t mode) instead");
1303 DEPRECATED(SerializeStatus serialize(const Serializable& val),
1304 "Use serializeFrom(const Serializable& val) instead");
1305
1306 DEPRECATED(SerializeStatus deserialize(U8& val), "Use deserializeTo(U8& val) instead");
1307 DEPRECATED(SerializeStatus deserialize(I8& val), "Use deserializeTo(I8& val) instead");
1308 #if FW_HAS_16_BIT == 1
1309 DEPRECATED(SerializeStatus deserialize(U16& val), "Use deserializeTo(U16& val) instead");
1310 DEPRECATED(SerializeStatus deserialize(I16& val), "Use deserializeTo(I16& val) instead");
1311 #endif
1312 #if FW_HAS_32_BIT == 1
1313 DEPRECATED(SerializeStatus deserialize(U32& val), "Use deserializeTo(U32& val) instead");
1314 DEPRECATED(SerializeStatus deserialize(I32& val), "Use deserializeTo(I32& val) instead");
1315 #endif
1316 #if FW_HAS_64_BIT == 1
1317 DEPRECATED(SerializeStatus deserialize(U64& val), "Use deserializeTo(U64& val) instead");
1318 DEPRECATED(SerializeStatus deserialize(I64& val), "Use deserializeTo(I64& val) instead");
1319 #endif
1320
1321 DEPRECATED(SerializeStatus deserialize(F32& val), "Use deserializeTo(F32& val) instead");
1322 DEPRECATED(SerializeStatus deserialize(F64& val), "Use deserializeTo(F64& val) instead");
1323 DEPRECATED(SerializeStatus deserialize(bool& val), "Use deserializeTo(bool& val) instead");
1324 DEPRECATED(SerializeStatus deserialize(void*& val), "Use deserializeTo(void*& val) instead");
1325 DEPRECATED(SerializeStatus deserialize(U8* buff, FwSizeType& length, bool noLength),
1326 "Use deserialize(U8* buff, FwSizeType& length, Serialization::t mode) instead");
1327 DEPRECATED(SerializeStatus deserialize(U8* buff, FwSizeType& length),
1328 "Use deserializeTo(U8* buff, FwSizeType& length) instead");
1329 DEPRECATED(SerializeStatus deserialize(U8* buff, FwSizeType& length, Serialization::t mode),
1330 "Use deserializeTo(U8* buff, FwSizeType& length, Serialization::t mode) instead");
1331 DEPRECATED(SerializeStatus deserialize(Serializable& val), "Use deserializeTo(Serializable& val) instead");
1332
1333 #ifdef BUILD_UT
1334 //! \brief Equality comparison operator
1335 //!
1336 //! Compares this LinearBufferBase instance with another for equality.
1337 //! Two buffers are considered equal if they have the same contents and size.
1338 //!
1339 //! \param other Reference to the other LinearBufferBase instance to compare with
1340 //! \return true if the buffers are equal, false otherwise
1341 bool operator==(const LinearBufferBase& other) const;
1342
1343 //! \brief Stream insertion operator for LinearBufferBase
1344 //!
1345 //! Allows a LinearBufferBase instance to be output to a stream (e.g., for debugging).
1346 //! This provides a human-readable representation of the buffer's contents.
1347 //!
1348 //! \param os Reference to the output stream
1349 //! \param buff Reference to the LinearBufferBase instance to output
1350 //! \return Reference to the output stream
1351 friend std::ostream& operator<<(std::ostream& os, const LinearBufferBase& buff);
1352 #endif
1353
1354 protected:
1355 //! There is no default constructor: every derived class must supply its
1356 //! storage during construction
1357 LinearBufferBase() = delete;
1358
1359 //! \brief Storage constructor
1360 //!
1361 //! Initializes a LinearBufferBase instance with the buffer storage that the
1362 //! derived class provides. Using the constructor makes it a
1363 //! compile-time error for a derived class to forget to setup its storage.
1364 //!
1365 //! \param buffAddr Pointer to the buffer address (may be nullptr)
1366 //! \param capacity Capacity of the buffer storage in bytes
1367 LinearBufferBase(U8* buffAddr, Serializable::SizeType capacity);
1368
1369 //! \brief Copy constructor (protected)
1370 //!
1371 //! Creates a copy of another LinearBufferBase instance. This constructor
1372 //! is protected and intended for use only by derived classes or internal
1373 //! implementation details.
1374 //!
1375 //! \param src Reference to the source LinearBufferBase to copy from
1376 LinearBufferBase(const LinearBufferBase& src);
1377
1378 //! \brief Copy data from source buffer
1379 //!
1380 //! Copies the contents from another LinearBufferBase instance to this one.
1381 //! This includes copying the buffer data, serialization location, and
1382 //! deserialization location.
1383 //!
1384 //! \param src Reference to the source LinearBufferBase to copy data from
1385 void copyFrom(const LinearBufferBase& src);
1386
1387 // Protected accessors for serialization/deserialization location
1388 // These are needed by ExternalSerializeBufferWithMemberCopy
1389 Serializable::SizeType getSerLoc() const { return this->m_serLoc; }
1390 Serializable::SizeType getDeserLoc() const { return this->m_deserLoc; }
1391 void setSerLoc(Serializable::SizeType loc) { this->m_serLoc = loc; }
1392 void setDeserLoc(Serializable::SizeType loc) { this->m_deserLoc = loc; }
1393
1394 // Protected setters for buffer address and capacity
1395 // These are needed by ExternalSerializeBuffer::setExtBuffer() and clear()
1396 53854 void setBuffAddrInternal(U8* addr) { this->m_buffAddr = addr; }
1397 53855 void setCapacityInternal(Serializable::SizeType capacity) { this->m_capacity = capacity; }
1398
1399 private:
1400 U8* m_buffAddr; //!< pointer to buffer storage
1401 Serializable::SizeType m_capacity; //!< capacity of buffer storage
1402 Serializable::SizeType m_serLoc; //!< current offset in buffer of serialized data
1403 Serializable::SizeType m_deserLoc; //!< current offset for deserialization
1404 };
1405
1406 // Helper classes for building buffers with external storage
1407
1408 //! \brief External serialize buffer with no copy semantics
1409 //!
1410 //! This class provides a serialization buffer that uses an external buffer
1411 //! without copying data. It is designed for scenarios where you want to avoid
1412 //! data copying for performance reasons and are willing to manage the buffer
1413 //! lifetime manually.
1414 //!
1415 //! \note The external buffer must remain valid for the lifetime of the
1416 //! ExternalSerializeBuffer instance. The class does not take ownership of
1417 //! the buffer or copy its contents.
1418 class ExternalSerializeBuffer : public LinearBufferBase {
1419 public:
1420 //! \brief Construct with external buffer
1421 //!
1422 //! Creates an ExternalSerializeBuffer instance that uses the provided
1423 //! external buffer. The buffer must remain valid for the lifetime of
1424 //! this instance.
1425 //!
1426 //! \param buffPtr Pointer to the external buffer
1427 //! \param size Size of the external buffer in bytes
1428 ExternalSerializeBuffer(U8* buffPtr, Serializable::SizeType size);
1429
1430 //! \brief Default constructor
1431 //!
1432 //! Creates an ExternalSerializeBuffer instance without an external buffer.
1433 //! The buffer must be set later using setExtBuffer().
1434 ExternalSerializeBuffer();
1435
1436 //! \brief Destructor
1437 //!
1438 //! Destroys the ExternalSerializeBuffer instance. Note that this does
1439 //! not free the external buffer if one was set.
1440 ~ExternalSerializeBuffer() {}
1441
1442 //! \brief Set the external buffer
1443 //!
1444 //! Sets a new external buffer for this instance. This action also resets
1445 //! the serialization and deserialization pointers to the beginning of
1446 //! the new buffer.
1447 //!
1448 //! \param buffPtr Pointer to the new external buffer
1449 //! \param size Size of the new external buffer in bytes
1450 void setExtBuffer(U8* buffPtr, Serializable::SizeType size);
1451
1452 //! \brief Clear external buffer
1453 //!
1454 //! Clears the external buffer reference. After calling this method,
1455 //! the buffer is effectively empty and cannot be used for serialization
1456 //! or deserialization until a new buffer is set.
1457 void clear();
1458
1459 //! \brief Deleted copy constructor
1460 //!
1461 //! The copy constructor is deleted to prevent copying instances of
1462 //! ExternalSerializeBuffer, as this could lead to issues with buffer
1463 //! management.
1464 ExternalSerializeBuffer(const ExternalSerializeBuffer& src) = delete;
1465
1466 DEPRECATED(Serializable::SizeType getBuffCapacity() const, "Use getCapacity() instead");
1467
1468 //! \brief Deleted copy assignment operator
1469 //!
1470 //! The copy assignment operator is deleted to prevent copying instances of
1471 //! ExternalSerializeBuffer, as this could lead to issues with buffer
1472 //! management.
1473 ExternalSerializeBuffer& operator=(const LinearBufferBase& src) = delete;
1474 };
1475
1476 //! \brief External serialize buffer with data copy semantics
1477 //!
1478 //! This class provides a serialization buffer that uses an external buffer
1479 //! and performs data copying during assignment operations. It is designed
1480 //! for scenarios where you want to ensure that the buffer always contains
1481 //! valid data and are willing to pay the performance cost of copying.
1482 //!
1483 //! \note This class should be used when the object on the left-hand side of
1484 //! an assignment (esb = sbb) is guaranteed to have a valid buffer.
1485 //!
1486 //! \see ExternalSerializeBuffer for a version without data copying
1487 class ExternalSerializeBufferWithDataCopy final : public ExternalSerializeBuffer {
1488 public:
1489 //! \brief Construct with external buffer
1490 //!
1491 //! Creates an ExternalSerializeBufferWithDataCopy instance that uses the
1492 //! provided external buffer.
1493 //!
1494 //! \param buffPtr Pointer to the external buffer
1495 //! \param size Size of the external buffer in bytes
1496 ExternalSerializeBufferWithDataCopy(U8* buffPtr, Serializable::SizeType size)
1497 : ExternalSerializeBuffer(buffPtr, size) {}
1498
1499 //! \brief Default constructor
1500 //!
1501 //! Creates an ExternalSerializeBufferWithDataCopy instance without an
1502 //! external buffer. The buffer must be set later using setExtBuffer().
1503 ExternalSerializeBufferWithDataCopy() : ExternalSerializeBuffer() {}
1504
1505 //! \brief Destructor
1506 //!
1507 //! Destroys the ExternalSerializeBufferWithDataCopy instance.
1508 ~ExternalSerializeBufferWithDataCopy() {}
1509
1510 //! \brief Deleted copy constructor
1511 //!
1512 //! The copy constructor is deleted to prevent copying instances of
1513 //! ExternalSerializeBufferWithDataCopy, as this could lead to issues
1514 //! with buffer management.
1515 ExternalSerializeBufferWithDataCopy(const LinearBufferBase& src) = delete;
1516
1517 //! \brief Copy assignment operator with data copying
1518 //!
1519 //! This assignment operator copies data from the source buffer to the
1520 //! destination buffer. It ensures that the destination buffer always
1521 //! contains valid data after the assignment.
1522 //!
1523 //! \param src Reference to the source buffer to copy data from
1524 //! \return Reference to this instance
1525 ExternalSerializeBufferWithDataCopy& operator=(LinearBufferBase& src) {
1526 (void)LinearBufferBase::operator=(src);
1527 return *this;
1528 }
1529 };
1530
1531 //! \brief External serialize buffer with member copy semantics
1532 //!
1533 //! This class provides a serialization buffer that uses an external buffer
1534 //! and performs member copying during assignment operations. It is designed
1535 //! for scenarios where you want to move data between buffers efficiently.
1536 //!
1537 //! \note This class should be used when the object on the left-hand side of
1538 //! an assignment (esb1 = esb2) has an invalid buffer, and you want to move
1539 //! the buffer of esb2 into it. In this case, there should usually be no more
1540 //! uses of esb2 after the assignment.
1541 //!
1542 //! \see ExternalSerializeBuffer for a version without data copying
1543 //! \see ExternalSerializeBufferWithDataCopy for a version with data copying
1544 class ExternalSerializeBufferWithMemberCopy final : public ExternalSerializeBuffer {
1545 public:
1546 //! \brief Construct with external buffer
1547 //!
1548 //! Creates an ExternalSerializeBufferWithMemberCopy instance that uses the
1549 //! provided external buffer.
1550 //!
1551 //! \param buffPtr Pointer to the external buffer
1552 //! \param size Size of the external buffer in bytes
1553 ExternalSerializeBufferWithMemberCopy(U8* buffPtr, Serializable::SizeType size)
1554 : ExternalSerializeBuffer(buffPtr, size) {}
1555
1556 //! \brief Default constructor
1557 //!
1558 //! Creates an ExternalSerializeBufferWithMemberCopy instance without an
1559 //! external buffer. The buffer must be set later using setExtBuffer().
1560 ExternalSerializeBufferWithMemberCopy() : ExternalSerializeBuffer() {}
1561
1562 //! \brief Destructor
1563 //!
1564 //! Destroys the ExternalSerializeBufferWithMemberCopy instance.
1565 ~ExternalSerializeBufferWithMemberCopy() {}
1566
1567 //! \brief Copy constructor with member copying
1568 //!
1569 //! This constructor copies members from the source instance, including
1570 //! the buffer pointer, size, serialization location, and deserialization
1571 //! location.
1572 //!
1573 //! \param src Reference to the source instance to copy from
1574 ExternalSerializeBufferWithMemberCopy(const ExternalSerializeBufferWithMemberCopy& src)
1575 : ExternalSerializeBuffer(const_cast<U8*>(src.getBuffAddr()), src.getCapacity()) {
1576 this->setSerLoc(src.getSerLoc());
1577 this->setDeserLoc(src.getDeserLoc());
1578 }
1579
1580 //! \brief Copy assignment operator with member copying
1581 //!
1582 //! This assignment operator copies members from the source instance,
1583 //! including the buffer pointer, size, serialization location, and
1584 //! deserialization location. It guards against self-assignment.
1585 //!
1586 //! \param src Reference to the source instance to copy from
1587 //! \return Reference to this instance
1588 ExternalSerializeBufferWithMemberCopy& operator=(const ExternalSerializeBufferWithMemberCopy& src) {
1589 // Ward against self-assignment
1590 if (this != &src) {
1591 this->setExtBuffer(const_cast<U8*>(src.getBuffAddr()), src.getCapacity());
1592 this->setSerLoc(src.getSerLoc());
1593 this->setDeserLoc(src.getDeserLoc());
1594 }
1595 return *this;
1596 }
1597 };
1598
1599 } // namespace Fw
1600 #endif
1601