F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Serializable.cpp
Go to the documentation of this file.
2#include <cstring> // memcpy
3#include <Fw/Types/Assert.hpp>
5#include <cstdio>
6#include <FpConfig.hpp>
7#ifdef BUILD_UT
8#include <iomanip>
9#include <Fw/Types/String.hpp>
10#endif
11
12// Some macros/functions to optimize for architectures
13
14namespace Fw {
15
18
21
22#if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT
23
24 void Serializable::toString(StringBase& text) const {
25 text = "NOSPEC"; // set to not specified.
26 }
27
28#endif
29
30#ifdef BUILD_UT
31 std::ostream& operator<<(std::ostream& os, const Serializable& val) {
32 Fw::String out;
33 val.toString(out);
34
35 os << out;
36
37 return os;
38 }
39#endif
40
42 m_serLoc(0), m_deserLoc(0) {
43 }
44
47
48 void SerializeBufferBase::copyFrom(const SerializeBufferBase& src) {
49 this->m_serLoc = src.m_serLoc;
50 this->m_deserLoc = src.m_deserLoc;
52 FW_ASSERT(this->getBuffAddr());
53 // destination has to be same or bigger
54 FW_ASSERT(src.getBuffLength() <= this->getBuffCapacity(),src.getBuffLength(),this->getBuffLength());
55 (void) memcpy(this->getBuffAddr(),src.getBuffAddr(),this->m_serLoc);
56 }
57
58 // Copy constructor doesn't make sense in this virtual class as there is nothing to copy. Derived classes should
59 // call the empty constructor and then call their own copy function
61 this->copyFrom(src);
62 return *this;
63 }
64
65 // serialization routines
66
68 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
70 }
71 FW_ASSERT(this->getBuffAddr());
72 this->getBuffAddr()[this->m_serLoc] = val;
73 this->m_serLoc += sizeof(val);
74 this->m_deserLoc = 0;
75
76 return FW_SERIALIZE_OK;
77 }
78
80 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
82 }
83 FW_ASSERT(this->getBuffAddr());
84 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val);
85 this->m_serLoc += sizeof(val);
86 this->m_deserLoc = 0;
87 return FW_SERIALIZE_OK;
88 }
89
90#if FW_HAS_16_BIT==1
92 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
94 }
95 FW_ASSERT(this->getBuffAddr());
96 // MSB first
97 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 8);
98 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val);
99 this->m_serLoc += sizeof(val);
100 this->m_deserLoc = 0;
101 return FW_SERIALIZE_OK;
102 }
103
105 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
107 }
108 FW_ASSERT(this->getBuffAddr());
109 // MSB first
110 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 8);
111 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val);
112 this->m_serLoc += sizeof(val);
113 this->m_deserLoc = 0;
114 return FW_SERIALIZE_OK;
115 }
116#endif
117#if FW_HAS_32_BIT==1
119 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
121 }
122 FW_ASSERT(this->getBuffAddr());
123 // MSB first
124 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 24);
125 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val >> 16);
126 this->getBuffAddr()[this->m_serLoc + 2] = static_cast<U8>(val >> 8);
127 this->getBuffAddr()[this->m_serLoc + 3] = static_cast<U8>(val);
128 this->m_serLoc += sizeof(val);
129 this->m_deserLoc = 0;
130 return FW_SERIALIZE_OK;
131 }
132
134 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
136 }
137 FW_ASSERT(this->getBuffAddr());
138 // MSB first
139 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 24);
140 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val >> 16);
141 this->getBuffAddr()[this->m_serLoc + 2] = static_cast<U8>(val >> 8);
142 this->getBuffAddr()[this->m_serLoc + 3] = static_cast<U8>(val);
143 this->m_serLoc += sizeof(val);
144 this->m_deserLoc = 0;
145 return FW_SERIALIZE_OK;
146 }
147#endif
148
149#if FW_HAS_64_BIT==1
151 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
153 }
154 FW_ASSERT(this->getBuffAddr());
155 // MSB first
156 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 56);
157 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val >> 48);
158 this->getBuffAddr()[this->m_serLoc + 2] = static_cast<U8>(val >> 40);
159 this->getBuffAddr()[this->m_serLoc + 3] = static_cast<U8>(val >> 32);
160 this->getBuffAddr()[this->m_serLoc + 4] = static_cast<U8>(val >> 24);
161 this->getBuffAddr()[this->m_serLoc + 5] = static_cast<U8>(val >> 16);
162 this->getBuffAddr()[this->m_serLoc + 6] = static_cast<U8>(val >> 8);
163 this->getBuffAddr()[this->m_serLoc + 7] = static_cast<U8>(val);
164 this->m_serLoc += sizeof(val);
165 this->m_deserLoc = 0;
166 return FW_SERIALIZE_OK;
167 }
168
170 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(val)) - 1 >= this->getBuffCapacity()) {
172 }
173 FW_ASSERT(this->getBuffAddr());
174 // MSB first
175 this->getBuffAddr()[this->m_serLoc + 0] = static_cast<U8>(val >> 56);
176 this->getBuffAddr()[this->m_serLoc + 1] = static_cast<U8>(val >> 48);
177 this->getBuffAddr()[this->m_serLoc + 2] = static_cast<U8>(val >> 40);
178 this->getBuffAddr()[this->m_serLoc + 3] = static_cast<U8>(val >> 32);
179 this->getBuffAddr()[this->m_serLoc + 4] = static_cast<U8>(val >> 24);
180 this->getBuffAddr()[this->m_serLoc + 5] = static_cast<U8>(val >> 16);
181 this->getBuffAddr()[this->m_serLoc + 6] = static_cast<U8>(val >> 8);
182 this->getBuffAddr()[this->m_serLoc + 7] = static_cast<U8>(val);
183 this->m_serLoc += sizeof(val);
184 this->m_deserLoc = 0;
185 return FW_SERIALIZE_OK;
186 }
187#endif
188
189#if FW_HAS_F64 && FW_HAS_64_BIT
190
192 // floating point values need to be byte-swapped as well, so copy to U64 and use that routine
193 U64 u64Val;
194 (void) memcpy(&u64Val, &val, sizeof(val));
195 return this->serialize(u64Val);
196
197 }
198
199#endif
200
202
203 // floating point values need to be byte-swapped as well, so copy to U32 and use that routine
204 U32 u32Val;
205 (void) memcpy(&u32Val, &val, sizeof(val));
206 return this->serialize(u32Val);
207
208 }
209
211 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(U8)) - 1 >= this->getBuffCapacity()) {
213 }
214
215 FW_ASSERT(this->getBuffAddr());
216 if (val) {
217 this->getBuffAddr()[this->m_serLoc + 0] = FW_SERIALIZE_TRUE_VALUE;
218 } else {
219 this->getBuffAddr()[this->m_serLoc + 0] = FW_SERIALIZE_FALSE_VALUE;
220 }
221
222 this->m_serLoc += sizeof(U8);
223 this->m_deserLoc = 0;
224 return FW_SERIALIZE_OK;
225 }
226
228 if (this->m_serLoc + static_cast<NATIVE_UINT_TYPE>(sizeof(void*)) - 1
229 >= this->getBuffCapacity()) {
231 }
232
233 return this->serialize(reinterpret_cast<POINTER_CAST>(val));
234
235 }
236
238 // First serialize length
239 SerializeStatus stat;
240 if (not noLength) {
241 stat = this->serialize(static_cast<FwBuffSizeType>(length));
242 if (stat != FW_SERIALIZE_OK) {
243 return stat;
244 }
245 }
246
247 // make sure we have enough space
248 if (this->m_serLoc + length > this->getBuffCapacity()) {
250 }
251
252 // copy buffer to our buffer
253 (void) memcpy(&this->getBuffAddr()[this->m_serLoc], buff, length);
254 this->m_serLoc += length;
255 this->m_deserLoc = 0;
256
257 return FW_SERIALIZE_OK;
258 }
259
261 return val.serialize(*this);
262 }
263
265 const SerializeBufferBase& val) {
266 NATIVE_UINT_TYPE size = val.getBuffLength();
267 if (this->m_serLoc + size + static_cast<NATIVE_UINT_TYPE>(sizeof(FwBuffSizeType))
268 > this->getBuffCapacity()) {
270 }
271
272 // First, serialize size
273 SerializeStatus stat = this->serialize(static_cast<FwBuffSizeType>(size));
274 if (stat != FW_SERIALIZE_OK) {
275 return stat;
276 }
277
278 FW_ASSERT(this->getBuffAddr());
279 FW_ASSERT(val.getBuffAddr());
280 // serialize buffer
281 (void) memcpy(&this->getBuffAddr()[this->m_serLoc], val.getBuffAddr(), size);
282 this->m_serLoc += size;
283 this->m_deserLoc = 0;
284
285 return FW_SERIALIZE_OK;
286 }
287
288 // deserialization routines
289
291 // check for room
292 if (this->getBuffLength() == this->m_deserLoc) {
294 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
296 }
297 // read from current location
298 FW_ASSERT(this->getBuffAddr());
299 val = this->getBuffAddr()[this->m_deserLoc + 0];
300 this->m_deserLoc += sizeof(val);
301 return FW_SERIALIZE_OK;
302 }
303
305 // check for room
306 if (this->getBuffLength() == this->m_deserLoc) {
308 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
310 }
311 // read from current location
312 FW_ASSERT(this->getBuffAddr());
313 val = static_cast<I8>(this->getBuffAddr()[this->m_deserLoc + 0]);
314 this->m_deserLoc += sizeof(val);
315 return FW_SERIALIZE_OK;
316 }
317
318#if FW_HAS_16_BIT==1
320 // check for room
321 if (this->getBuffLength() == this->m_deserLoc) {
323 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
325 }
326 // read from current location
327 FW_ASSERT(this->getBuffAddr());
328 // MSB first
329 val = static_cast<U16>(
330 ((this->getBuffAddr()[this->m_deserLoc + 1]) << 0) |
331 ((this->getBuffAddr()[this->m_deserLoc + 0]) << 8)
332 );
333 this->m_deserLoc += sizeof(val);
334 return FW_SERIALIZE_OK;
335 }
336
338 // check for room
339 if (this->getBuffLength() == this->m_deserLoc) {
341 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
343 }
344 // read from current location
345 FW_ASSERT(this->getBuffAddr());
346 // MSB first
347 val = static_cast<I16>(
348 ((this->getBuffAddr()[this->m_deserLoc + 1]) << 0) |
349 ((this->getBuffAddr()[this->m_deserLoc + 0]) << 8)
350 );
351 this->m_deserLoc += sizeof(val);
352 return FW_SERIALIZE_OK;
353 }
354#endif
355#if FW_HAS_32_BIT==1
357 // check for room
358 if (this->getBuffLength() == this->m_deserLoc) {
360 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
362 }
363 // read from current location
364 FW_ASSERT(this->getBuffAddr());
365 // MSB first
366 val = (static_cast<U32>(this->getBuffAddr()[this->m_deserLoc + 3]) << 0)
367 | (static_cast<U32>(this->getBuffAddr()[this->m_deserLoc + 2]) << 8)
368 | (static_cast<U32>(this->getBuffAddr()[this->m_deserLoc + 1]) << 16)
369 | (static_cast<U32>(this->getBuffAddr()[this->m_deserLoc + 0]) << 24);
370 this->m_deserLoc += sizeof(val);
371 return FW_SERIALIZE_OK;
372 }
373
375 // check for room
376 if (this->getBuffLength() == this->m_deserLoc) {
378 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
380 }
381 // read from current location
382 FW_ASSERT(this->getBuffAddr());
383 // MSB first
384 val = (static_cast<I32>(this->getBuffAddr()[this->m_deserLoc + 3]) << 0)
385 | (static_cast<I32>(this->getBuffAddr()[this->m_deserLoc + 2]) << 8)
386 | (static_cast<I32>(this->getBuffAddr()[this->m_deserLoc + 1]) << 16)
387 | (static_cast<I32>(this->getBuffAddr()[this->m_deserLoc + 0]) << 24);
388 this->m_deserLoc += sizeof(val);
389 return FW_SERIALIZE_OK;
390 }
391#endif
392
393#if FW_HAS_64_BIT==1
394
396 // check for room
397 if (this->getBuffLength() == this->m_deserLoc) {
399 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
401 }
402 // read from current location
403 FW_ASSERT(this->getBuffAddr());
404 // MSB first
405 val = (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 7]) << 0)
406 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 6]) << 8)
407 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 5]) << 16)
408 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 4]) << 24)
409 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 3]) << 32)
410 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 2]) << 40)
411 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 1]) << 48)
412 | (static_cast<U64>(this->getBuffAddr()[this->m_deserLoc + 0]) << 56);
413
414 this->m_deserLoc += sizeof(val);
415 return FW_SERIALIZE_OK;
416 }
417
419 // check for room
420 if (this->getBuffLength() == this->m_deserLoc) {
422 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(val))) {
424 }
425 // read from current location
426 FW_ASSERT(this->getBuffAddr());
427 // MSB first
428 val = (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 7]) << 0)
429 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 6]) << 8)
430 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 5]) << 16)
431 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 4]) << 24)
432 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 3]) << 32)
433 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 2]) << 40)
434 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 1]) << 48)
435 | (static_cast<I64>(this->getBuffAddr()[this->m_deserLoc + 0]) << 56);
436 this->m_deserLoc += sizeof(val);
437 return FW_SERIALIZE_OK;
438 }
439#endif
440
441#if FW_HAS_F64
442
444
445 // deserialize as 64-bit int to handle endianness
446 U64 tempVal;
447 SerializeStatus stat = this->deserialize(tempVal);
448 if (stat != FW_SERIALIZE_OK) {
449 return stat;
450 }
451 // copy to argument
452 (void) memcpy(&val, &tempVal, sizeof(val));
453
454 return FW_SERIALIZE_OK;
455 }
456
457#endif
458
460 // check for room
461 if (this->getBuffLength() == this->m_deserLoc) {
463 } else if (this->getBuffLength() - this->m_deserLoc < static_cast<NATIVE_UINT_TYPE>(sizeof(U8))) {
465 }
466 // read from current location
467 FW_ASSERT(this->getBuffAddr());
468 if (FW_SERIALIZE_TRUE_VALUE == this->getBuffAddr()[this->m_deserLoc + 0]) {
469 val = true;
470 } else if (FW_SERIALIZE_FALSE_VALUE == this->getBuffAddr()[this->m_deserLoc + 0]) {
471 val = false;
472 } else {
474 }
475
476 this->m_deserLoc += sizeof(U8);
477 return FW_SERIALIZE_OK;
478 }
479
481 // Deserialize as pointer cast, then convert to void*
482 PlatformPointerCastType pointerCastVal = 0;
483 const SerializeStatus stat = this->deserialize(pointerCastVal);
484 if (stat == FW_SERIALIZE_OK) {
485 val = reinterpret_cast<void*>(pointerCastVal);
486 }
487 return stat;
488 }
489
491 // deserialize as 64-bit int to handle endianness
492 U32 tempVal;
493 SerializeStatus stat = this->deserialize(tempVal);
494 if (stat != FW_SERIALIZE_OK) {
495 return stat;
496 }
497 (void) memcpy(&val, &tempVal, sizeof(val));
498
499 return FW_SERIALIZE_OK;
500 }
501
503
504 FW_ASSERT(this->getBuffAddr());
505
506 if (not noLength) {
507 FwBuffSizeType storedLength;
508
509 SerializeStatus stat = this->deserialize(storedLength);
510
511 if (stat != FW_SERIALIZE_OK) {
512 return stat;
513 }
514
515 // make sure it fits
516 if ((storedLength > this->getBuffLeft()) or (storedLength > length)) {
518 }
519
520 (void) memcpy(buff, &this->getBuffAddr()[this->m_deserLoc], storedLength);
521
522 length = static_cast<NATIVE_UINT_TYPE>(storedLength);
523
524 } else {
525 // make sure enough is left
526 if (length > this->getBuffLeft()) {
528 }
529
530 (void) memcpy(buff, &this->getBuffAddr()[this->m_deserLoc], length);
531 }
532
533 this->m_deserLoc += length;
534 return FW_SERIALIZE_OK;
535 }
536
540
542
543 FW_ASSERT(val.getBuffAddr());
545
546 FwBuffSizeType storedLength;
547
548 stat = this->deserialize(storedLength);
549
550 if (stat != FW_SERIALIZE_OK) {
551 return stat;
552 }
553
554 // make sure destination has enough room
555
556 if ((storedLength > val.getBuffCapacity()) or (storedLength > this->getBuffLeft()) ) {
558 }
559
560 FW_ASSERT(this->getBuffAddr());
561 (void) memcpy(val.getBuffAddr(), &this->getBuffAddr()[this->m_deserLoc],
562 storedLength);
563
564 stat = val.setBuffLen(storedLength);
565
566 if (stat != FW_SERIALIZE_OK) {
567 return stat;
568 }
569
570 this->m_deserLoc += storedLength;
571
572 return FW_SERIALIZE_OK;
573 }
574
576 this->m_deserLoc = 0;
577 this->m_serLoc = 0;
578 }
579
581 this->m_deserLoc = 0;
582 }
583
585 {
586 // check for room
587 if (this->getBuffLength() == this->m_deserLoc) {
589 } else if (this->getBuffLength() - this->m_deserLoc < numBytesToSkip) {
591 }
592 // update location in buffer to skip the value
593 this->m_deserLoc += numBytesToSkip;
594 return FW_SERIALIZE_OK;
595 }
596
598 return this->m_serLoc;
599 }
600
602 if (this->getBuffCapacity() < length) {
604 } else {
605 FW_ASSERT(src);
606 FW_ASSERT(this->getBuffAddr());
607 memcpy(this->getBuffAddr(), src, length);
608 this->m_serLoc = length;
609 this->m_deserLoc = 0;
610 return FW_SERIALIZE_OK;
611 }
612 }
613
615 if (this->getBuffCapacity() < length) {
617 } else {
618 this->m_serLoc = length;
619 this->m_deserLoc = 0;
620 return FW_SERIALIZE_OK;
621 }
622 }
623
625 return this->m_serLoc - this->m_deserLoc;
626 }
627
629 // make sure there is sufficient size in destination
630 if (dest.getBuffCapacity() < size) {
632 }
633 // otherwise, set destination buffer to data from deserialization pointer plus size
634 SerializeStatus stat = dest.setBuff(&this->getBuffAddr()[this->m_deserLoc],size);
635 if (stat == FW_SERIALIZE_OK) {
636 this->m_deserLoc += size;
637 }
638 return stat;
639
640 }
641
643 // make sure there is sufficient size in destination
644 if (dest.getBuffCapacity() < size + dest.getBuffLength()) {
646 }
647 // make sure there is sufficient buffer in source
648 if (this->getBuffLeft() < size) {
650 }
651
652 // otherwise, serialize bytes to destination without writing length
653 SerializeStatus stat = dest.serialize(&this->getBuffAddr()[this->m_deserLoc], size, true);
654 if (stat == FW_SERIALIZE_OK) {
655 this->m_deserLoc += size;
656 }
657 return stat;
658
659 }
660
661 // return address of buffer not yet deserialized. This is used
662 // to copy the remainder of a buffer.
664 return &this->getBuffAddr()[this->m_deserLoc];
665 }
666
669 return &this->getBuffAddr()[this->m_serLoc];
670 }
671
672#ifdef BUILD_UT
673 bool SerializeBufferBase::operator==(const SerializeBufferBase& other) const {
674 if (this->getBuffLength() != other.getBuffLength()) {
675 return false;
676 }
677
678 const U8* us = this->getBuffAddr();
679 const U8* them = other.getBuffAddr();
680
681 FW_ASSERT(us);
682 FW_ASSERT(them);
683
684 for (NATIVE_UINT_TYPE byte = 0; byte < this->getBuffLength(); byte++) {
685 if (us[byte] != them[byte]) {
686 return false;
687 }
688 }
689
690 return true;
691 }
692
693 std::ostream& operator<<(std::ostream& os, const SerializeBufferBase& buff) {
694
695 const U8* us = buff.getBuffAddr();
696
697 FW_ASSERT(us);
698
699 for (NATIVE_UINT_TYPE byte = 0; byte < buff.getBuffLength(); byte++) {
700 os << "[" << std::setw(2) << std::hex << std::setfill('0') << us[byte] << "]" << std::dec;
701 }
702
703 return os;
704 }
705#endif
706
710
714
716 FW_ASSERT(buffPtr != nullptr);
717 this->m_buff = buffPtr;
718 this->m_buffSize = size;
719 }
720
722 this->m_buff = nullptr;
723 this->m_buffSize = 0;
724 }
725
727 return this->m_buffSize;
728 }
729
731 return this->m_buff;
732 }
733
735 return this->m_buff;
736 }
737
738}
739
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformPointerCastType POINTER_CAST
Definition BasicTypes.h:53
int8_t I8
8-bit signed integer
Definition BasicTypes.h:25
float F32
32-bit floating point
Definition BasicTypes.h:45
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
uint8_t PlatformPointerCastType
#define FW_SERIALIZE_TRUE_VALUE
Value encoded during serialization for boolean true.
Definition FpConfig.h:73
#define FW_SERIALIZE_FALSE_VALUE
Value encoded during serialization for boolean false.
Definition FpConfig.h:77
U16 FwBuffSizeType
Definition FpConfig.h:30
C++-compatible configuration header for fprime configuration.
Declares ISF string base class.
NATIVE_UINT_TYPE getBuffCapacity() const
returns capacity, not current size, of buffer
U8 * getBuffAddr()
gets buffer address for data filling
void setExtBuffer(U8 *buffPtr, NATIVE_UINT_TYPE size)
Set the external buffer.
void clear()
clear external buffer
ExternalSerializeBuffer()
default constructor
forward declaration
Serializable()
Default constructor.
virtual ~Serializable()
destructor
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)=0
deserialize to contents
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const =0
serialize contents
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
void resetDeser()
reset deserialization to beginning
SerializeStatus setBuffLen(NATIVE_UINT_TYPE length)
sets buffer length manually after filling with data
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeBufferBase()
default constructor
SerializeStatus setBuff(const U8 *src, NATIVE_UINT_TYPE length)
sets buffer contents and size
SerializeStatus deserializeSkip(NATIVE_UINT_TYPE numBytesToSkip)
Skips the number of specified bytes for deserialization.
SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
virtual NATIVE_UINT_TYPE getBuffCapacity() const =0
returns capacity, not current size, of buffer
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
virtual ~SerializeBufferBase()
destructor
U8 * getBuffAddrSer()
gets address of end of serialization. DANGEROUS! Need to know max buffer size and adjust when done
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
SerializeStatus copyRawOffset(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
SerializeStatus copyRaw(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
SerializeStatus
forward declaration for string
@ FW_DESERIALIZE_FORMAT_ERROR
Deserialization data had incorrect values (unexpected data types)
@ FW_DESERIALIZE_BUFFER_EMPTY
Deserialization buffer was empty when trying to read more data.
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_DESERIALIZE_SIZE_MISMATCH
Data was left in the buffer, but not enough to deserialize.
@ FW_SERIALIZE_NO_ROOM_LEFT
No room left in the buffer to serialize data.
#define U64(C)
Definition sha.h:176