GCC Code Coverage Report


Directory: ./
File: Fw/Types/Serializable.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 425 589 72.2%
Functions: 57 101 56.4%
Branches: 133 211 63.0%

Line Branch Exec Source
1 #include <Fw/FPrimeBasicTypes.hpp>
2 #include <Fw/Types/Assert.hpp>
3 #include <Fw/Types/Serializable.hpp>
4 #include <Fw/Types/StringType.hpp>
5 #include <cstdio>
6 #include <cstring> // memcpy
7 #ifdef BUILD_UT
8 #include <Fw/Types/String.hpp>
9 #include <iomanip>
10 #endif
11
12 namespace Fw {
13
14 84289456 Serializable::Serializable() {}
15
16 168515458 Serializable::~Serializable() {}
17
18 // ----------------------------------------------------------------------
19 #if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT
20
21 void Serializable::toString(StringBase& text) const {
22 text = "NOSPEC"; // set to not specified.
23 }
24
25 #endif
26
27 #ifdef BUILD_UT
28 std::ostream& operator<<(std::ostream& os, const Serializable& val) {
29 Fw::String out;
30 val.toString(out);
31
32 os << out;
33
34 return os;
35 }
36 #endif
37
38 9843290 SerialBufferBase::~SerialBufferBase() {}
39
40 4921715 LinearBufferBase::LinearBufferBase(U8* buffAddr, Serializable::SizeType capacity)
41 4921715 : m_buffAddr(buffAddr), m_capacity(capacity), m_serLoc(0), m_deserLoc(0) {
42 // Ensure buffAddr & capacity are consistent
43 4921715 FW_ASSERT((buffAddr == nullptr) == (capacity == 0), static_cast<FwAssertArgType>(capacity));
44 4921715 }
45
46 9843290 LinearBufferBase::~LinearBufferBase() {}
47
48 void LinearBufferBase::copyFrom(const LinearBufferBase& src) {
49 this->m_serLoc = src.m_serLoc;
50 this->m_deserLoc = src.m_deserLoc;
51 const U8* srcBuffAddr = src.m_buffAddr;
52 U8* thisBuffAddr = this->m_buffAddr;
53 FW_ASSERT(srcBuffAddr != nullptr);
54 FW_ASSERT(thisBuffAddr != nullptr);
55 // destination has to be same or bigger
56 FW_ASSERT(src.m_serLoc <= this->m_capacity, static_cast<FwAssertArgType>(src.m_serLoc),
57 static_cast<FwAssertArgType>(this->m_capacity));
58 (void)memcpy(thisBuffAddr, srcBuffAddr, static_cast<size_t>(this->m_serLoc));
59 }
60
61 // Copy constructor doesn't make sense in this virtual class as there is nothing to copy. Derived classes should
62 // call the empty constructor and then call their own copy function
63 LinearBufferBase& LinearBufferBase::operator=(const LinearBufferBase& src) { // lgtm[cpp/rule-of-two]
64 this->copyFrom(src);
65 return *this;
66 }
67
68 // serialization routines
69
70 10437508 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U8 val, Endianness mode) {
71
2/2
✓ Branch 8 taken 1999994 times.
✓ Branch 9 taken 8437514 times.
10437508 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
72 1999994 return FW_SERIALIZE_NO_ROOM_LEFT;
73 }
74 8437514 U8* buffAddr = this->m_buffAddr;
75 8437514 FW_ASSERT(buffAddr != nullptr);
76 8437514 buffAddr[this->m_serLoc] = val;
77 8437514 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
78 8437514 this->m_deserLoc = 0;
79
80 8437514 return FW_SERIALIZE_OK;
81 }
82
83 14 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I8 val, Endianness mode) {
84 14 return serializeFrom(static_cast<U8>(val), mode);
85 }
86
87 #if FW_HAS_16_BIT == 1
88 4814917 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U16 val, Endianness mode) {
89
2/2
✓ Branch 8 taken 3999984 times.
✓ Branch 9 taken 814933 times.
4814917 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
90 3999984 return FW_SERIALIZE_NO_ROOM_LEFT;
91 }
92 814933 U8* buffAddr = this->m_buffAddr;
93 814933 FW_ASSERT(buffAddr != nullptr);
94
2/3
✓ Branch 0 taken 814929 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
814933 switch (mode) {
95 814929 case Endianness::BIG:
96 // MSB first
97 814929 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 8);
98 814929 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val);
99 814929 break;
100 4 case Endianness::LITTLE:
101 // LSB first
102 4 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
103 4 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
104 4 break;
105 default:
106 FW_ASSERT(false);
107 break;
108 }
109 814933 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
110 814933 this->m_deserLoc = 0;
111 814933 return FW_SERIALIZE_OK;
112 }
113
114 136876 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I16 val, Endianness mode) {
115 136876 return serializeFrom(static_cast<U16>(val), mode);
116 }
117 #endif
118 #if FW_HAS_32_BIT == 1
119 5019328 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U32 val, Endianness mode) {
120
2/2
✓ Branch 8 taken 3999985 times.
✓ Branch 9 taken 1019343 times.
5019328 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
121 3999985 return FW_SERIALIZE_NO_ROOM_LEFT;
122 }
123 1019343 U8* buffAddr = this->m_buffAddr;
124 1019343 FW_ASSERT(buffAddr != nullptr);
125
2/3
✓ Branch 0 taken 1019339 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
1019343 switch (mode) {
126 1019339 case Endianness::BIG:
127 // MSB first
128 1019339 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 24);
129 1019339 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 16);
130 1019339 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 8);
131 1019339 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val);
132 1019339 break;
133 4 case Endianness::LITTLE:
134 // LSB first
135 4 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
136 4 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
137 4 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 16);
138 4 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 24);
139 4 break;
140 default:
141 FW_ASSERT(false);
142 break;
143 }
144 1019343 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
145 1019343 this->m_deserLoc = 0;
146 1019343 return FW_SERIALIZE_OK;
147 }
148
149 158573 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I32 val, Endianness mode) {
150 158573 return serializeFrom(static_cast<U32>(val), mode);
151 }
152 #endif
153
154 #if FW_HAS_64_BIT == 1
155 1080003 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U64 val, Endianness mode) {
156
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1080002 times.
1080003 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
157 1 return FW_SERIALIZE_NO_ROOM_LEFT;
158 }
159 1080002 U8* buffAddr = this->m_buffAddr;
160 1080002 FW_ASSERT(buffAddr != nullptr);
161
2/3
✓ Branch 0 taken 1079997 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
1080002 switch (mode) {
162 1079997 case Endianness::BIG:
163 // MSB first
164 1079997 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 56);
165 1079997 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 48);
166 1079997 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 40);
167 1079997 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 32);
168 1079997 buffAddr[this->m_serLoc + 4] = static_cast<U8>(val >> 24);
169 1079997 buffAddr[this->m_serLoc + 5] = static_cast<U8>(val >> 16);
170 1079997 buffAddr[this->m_serLoc + 6] = static_cast<U8>(val >> 8);
171 1079997 buffAddr[this->m_serLoc + 7] = static_cast<U8>(val);
172 1079997 break;
173 5 case Endianness::LITTLE:
174 // LSB first
175 5 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
176 5 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
177 5 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 16);
178 5 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 24);
179 5 buffAddr[this->m_serLoc + 4] = static_cast<U8>(val >> 32);
180 5 buffAddr[this->m_serLoc + 5] = static_cast<U8>(val >> 40);
181 5 buffAddr[this->m_serLoc + 6] = static_cast<U8>(val >> 48);
182 5 buffAddr[this->m_serLoc + 7] = static_cast<U8>(val >> 56);
183 5 break;
184 default:
185 FW_ASSERT(false);
186 break;
187 }
188 1080002 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
189 1080002 this->m_deserLoc = 0;
190 1080002 return FW_SERIALIZE_OK;
191 }
192
193 6 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I64 val, Endianness mode) {
194 6 return serializeFrom(static_cast<U64>(val), mode);
195 }
196 #endif
197
198 1000006 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(F64 val, Endianness mode) {
199 // floating point values need to be byte-swapped as well, so copy to U64 and use that routine
200 1000006 U64 u64Val;
201 1000006 (void)memcpy(&u64Val, &val, sizeof(val));
202
1/1
✓ Branch 7 taken 1000006 times.
2000012 return this->serializeFrom(u64Val, mode);
203 }
204
205 2000033 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(F32 val, Endianness mode) {
206 // floating point values need to be byte-swapped as well, so copy to U32 and use that routine
207 2000033 U32 u32Val;
208 2000033 (void)memcpy(&u32Val, &val, sizeof(val));
209
1/1
✓ Branch 7 taken 2000033 times.
4000066 return this->serializeFrom(u32Val, mode);
210 }
211
212 210 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(bool val, Endianness mode) {
213
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 210 times.
210 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(U8)) - 1 >= this->m_capacity) {
214 return FW_SERIALIZE_NO_ROOM_LEFT;
215 }
216
217 210 U8* buffAddr = this->m_buffAddr;
218 210 FW_ASSERT(buffAddr != nullptr);
219
2/2
✓ Branch 0 taken 125 times.
✓ Branch 1 taken 85 times.
210 if (val) {
220 125 buffAddr[this->m_serLoc + 0] = FW_SERIALIZE_TRUE_VALUE;
221 } else {
222 85 buffAddr[this->m_serLoc + 0] = FW_SERIALIZE_FALSE_VALUE;
223 }
224
225 210 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(U8));
226 210 this->m_deserLoc = 0;
227 210 return FW_SERIALIZE_OK;
228 }
229
230 34 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const void* val, Endianness mode) {
231
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 34 times.
34 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(void*)) - 1 >= this->m_capacity) {
232 return FW_SERIALIZE_NO_ROOM_LEFT;
233 }
234
235 34 return this->serializeFrom(reinterpret_cast<PlatformPointerCastType>(val), mode);
236 }
237
238 2011060 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const U8* buff,
239 Serializable::SizeType length,
240 Endianness endianMode) {
241 2011060 return this->serializeFrom(buff, static_cast<FwSizeType>(length), Serialization::INCLUDE_LENGTH, endianMode);
242 }
243
244 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus
245 2556354 LinearBufferBase::serializeFrom(const U8* buff,
246 FwSizeType length,
247 Serialization::t lengthMode,
248 Endianness endianMode) { // First serialize length
249 SerializeStatus stat;
250
2/2
✓ Branch 0 taken 2050781 times.
✓ Branch 1 taken 505573 times.
2556354 if (lengthMode == Serialization::INCLUDE_LENGTH) {
251 2050781 stat = this->serializeFrom(static_cast<FwSizeStoreType>(length), endianMode);
252
2/2
✓ Branch 0 taken 1999992 times.
✓ Branch 1 taken 50789 times.
2050781 if (stat != FW_SERIALIZE_OK) {
253 1999992 return stat;
254 }
255 }
256
257 // make sure we have enough space
258
2/2
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 556360 times.
556362 if (this->m_serLoc + length > this->m_capacity) {
259 2 return FW_SERIALIZE_NO_ROOM_LEFT;
260 }
261
262
2/2
✓ Branch 0 taken 555489 times.
✓ Branch 1 taken 871 times.
556360 if (length > 0) {
263 555489 FW_ASSERT(buff != nullptr);
264 }
265 556360 U8* buffAddr = this->m_buffAddr;
266 556360 FW_ASSERT(buffAddr != nullptr);
267 // copy buffer to our buffer; memmove is used because the source may overlap this buffer
268
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 556360 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 556360 times.
556360 (void)memmove(&buffAddr[this->m_serLoc], buff, static_cast<size_t>(length));
269 556360 this->m_serLoc += static_cast<Serializable::SizeType>(length);
270 556360 this->m_deserLoc = 0;
271
272 556360 return FW_SERIALIZE_OK;
273 }
274
275 1120084 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const Serializable& val,
276 Endianness mode) {
277 1120084 return val.serializeTo(*this, mode);
278 }
279
280 13070 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const LinearBufferBase& val,
281 Endianness mode) {
282 13070 Serializable::SizeType size = val.getSize();
283
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 13070 times.
13070 if (this->m_serLoc + size + static_cast<Serializable::SizeType>(sizeof(FwSizeStoreType)) > this->m_capacity) {
284 return FW_SERIALIZE_NO_ROOM_LEFT;
285 }
286
287 // First, serialize size
288 13070 SerializeStatus stat = this->serializeFrom(static_cast<FwSizeStoreType>(size), mode);
289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13070 times.
13070 if (stat != FW_SERIALIZE_OK) {
290 return stat;
291 }
292
293 13070 U8* thisBuffAddr = this->m_buffAddr;
294 13070 const U8* valBuffAddr = val.getBuffAddr();
295 13070 FW_ASSERT(thisBuffAddr != nullptr);
296 13070 FW_ASSERT(valBuffAddr != nullptr);
297 // serialize buffer
298
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 13070 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13070 times.
13070 (void)memcpy(&thisBuffAddr[this->m_serLoc], valBuffAddr, static_cast<size_t>(size));
299 13070 this->m_serLoc += size;
300 13070 this->m_deserLoc = 0;
301
302 13070 return FW_SERIALIZE_OK;
303 }
304
305 32874 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeSize(const FwSizeType size, Endianness mode) {
306 32874 SerializeStatus status = FW_SERIALIZE_OK;
307
3/6
✓ Branch 1 taken 32874 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 32874 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 32874 times.
32874 if ((size < std::numeric_limits<FwSizeStoreType>::min()) || (size > std::numeric_limits<FwSizeStoreType>::max())) {
308 status = FW_SERIALIZE_FORMAT_ERROR;
309 }
310
1/2
✓ Branch 0 taken 32874 times.
✗ Branch 1 not taken.
32874 if (status == FW_SERIALIZE_OK) {
311 32874 status = this->serializeFrom(static_cast<FwSizeStoreType>(size), mode);
312 }
313 32874 return status;
314 }
315
316 // deserialization routines
317
318 775677 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8& val, Endianness mode) {
319 // check for room
320 775677 const Serializable::SizeType size = this->m_serLoc;
321
2/2
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 775668 times.
775677 if (size == this->m_deserLoc) {
322 9 return FW_DESERIALIZE_BUFFER_EMPTY;
323
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 775668 times.
775668 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
324 return FW_DESERIALIZE_SIZE_MISMATCH;
325 }
326 // read from current location
327 775668 U8* buffAddr = this->m_buffAddr;
328 775668 FW_ASSERT(buffAddr != nullptr);
329 775668 val = buffAddr[this->m_deserLoc + 0];
330 775668 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
331 775668 return FW_SERIALIZE_OK;
332 }
333
334 13 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I8& val, Endianness mode) {
335 // check for room
336 13 const Serializable::SizeType size = this->m_serLoc;
337
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
13 if (size == this->m_deserLoc) {
338 return FW_DESERIALIZE_BUFFER_EMPTY;
339
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
13 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
340 return FW_DESERIALIZE_SIZE_MISMATCH;
341 }
342 // read from current location
343 13 U8* buffAddr = this->m_buffAddr;
344 13 FW_ASSERT(buffAddr != nullptr);
345 13 val = static_cast<I8>(buffAddr[this->m_deserLoc + 0]);
346 13 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
347 13 return FW_SERIALIZE_OK;
348 }
349
350 #if FW_HAS_16_BIT == 1
351 779557 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U16& val, Endianness mode) {
352 // check for room
353 779557 const Serializable::SizeType size = this->m_serLoc;
354
2/2
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 779554 times.
779557 if (size == this->m_deserLoc) {
355 3 return FW_DESERIALIZE_BUFFER_EMPTY;
356
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 779552 times.
779554 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
357 2 return FW_DESERIALIZE_SIZE_MISMATCH;
358 }
359 // read from current location
360 779552 U8* buffAddr = this->m_buffAddr;
361 779552 FW_ASSERT(buffAddr != nullptr);
362
2/3
✓ Branch 0 taken 779548 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
779552 switch (mode) {
363 779548 case Endianness::BIG:
364 // MSB first
365
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 779548 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 779548 times.
779548 val = static_cast<U16>(((buffAddr[this->m_deserLoc + 1]) << 0) | ((buffAddr[this->m_deserLoc + 0]) << 8));
366 779548 break;
367 4 case Endianness::LITTLE:
368 // LSB first
369
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 4 times.
4 val = static_cast<U16>(((buffAddr[this->m_deserLoc + 0]) << 0) | ((buffAddr[this->m_deserLoc + 1]) << 8));
370 4 break;
371 default:
372 FW_ASSERT(false);
373 break;
374 }
375 779552 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
376 779552 return FW_SERIALIZE_OK;
377 }
378
379 76178 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I16& val, Endianness mode) {
380 76178 U16 unsignVal = 0;
381
1/1
✓ Branch 7 taken 76178 times.
76178 SerializeStatus res = deserializeTo(unsignVal, mode);
382
2/2
✓ Branch 0 taken 76177 times.
✓ Branch 1 taken 1 times.
76178 if (res == SerializeStatus::FW_SERIALIZE_OK) {
383 76177 val = static_cast<I16>(unsignVal);
384 }
385 76178 return res;
386 }
387 #endif
388 #if FW_HAS_32_BIT == 1
389 943430 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U32& val, Endianness mode) {
390 // check for room
391 943430 const Serializable::SizeType size = this->m_serLoc;
392
2/2
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 943416 times.
943430 if (size == this->m_deserLoc) {
393 14 return FW_DESERIALIZE_BUFFER_EMPTY;
394
2/2
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 943408 times.
943416 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
395 8 return FW_DESERIALIZE_SIZE_MISMATCH;
396 }
397 // read from current location
398 943408 U8* buffAddr = this->m_buffAddr;
399 943408 FW_ASSERT(buffAddr != nullptr);
400
2/3
✓ Branch 0 taken 943404 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
943408 switch (mode) {
401 943404 case Endianness::BIG:
402 // MSB first
403 943404 val = (static_cast<U32>(buffAddr[this->m_deserLoc + 3]) << 0) |
404 943404 (static_cast<U32>(buffAddr[this->m_deserLoc + 2]) << 8) |
405 943404 (static_cast<U32>(buffAddr[this->m_deserLoc + 1]) << 16) |
406 943404 (static_cast<U32>(buffAddr[this->m_deserLoc + 0]) << 24);
407 943404 break;
408 4 case Endianness::LITTLE:
409 // LSB first
410 4 val = (static_cast<U32>(buffAddr[this->m_deserLoc + 0]) << 0) |
411 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 1]) << 8) |
412 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 2]) << 16) |
413 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 3]) << 24);
414 4 break;
415 default:
416 FW_ASSERT(false);
417 break;
418 }
419 943408 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
420 943408 return FW_SERIALIZE_OK;
421 }
422
423 97695 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I32& val, Endianness mode) {
424 97695 U32 unsignVal = 0;
425
1/1
✓ Branch 7 taken 97695 times.
97695 SerializeStatus res = deserializeTo(unsignVal, mode);
426
1/2
✓ Branch 0 taken 97695 times.
✗ Branch 1 not taken.
97695 if (res == SerializeStatus::FW_SERIALIZE_OK) {
427 97695 val = static_cast<I32>(unsignVal);
428 }
429 97695 return res;
430 }
431 #endif
432
433 #if FW_HAS_64_BIT == 1
434
435 1079850 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U64& val, Endianness mode) {
436 // check for room
437
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1079850 times.
1079850 if (this->m_serLoc == this->m_deserLoc) {
438 return FW_DESERIALIZE_BUFFER_EMPTY;
439
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1079850 times.
1079850 } else if (this->m_serLoc - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
440 return FW_DESERIALIZE_SIZE_MISMATCH;
441 }
442 // read from current location
443 1079850 U8* buffAddr = this->m_buffAddr;
444 1079850 FW_ASSERT(buffAddr != nullptr);
445
2/3
✓ Branch 0 taken 1079845 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
1079850 switch (mode) {
446 1079845 case Endianness::BIG:
447 // MSB first
448 1079845 val = (static_cast<U64>(buffAddr[this->m_deserLoc + 7]) << 0) |
449 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 6]) << 8) |
450 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 5]) << 16) |
451 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 4]) << 24) |
452 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 3]) << 32) |
453 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 2]) << 40) |
454 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 1]) << 48) |
455 1079845 (static_cast<U64>(buffAddr[this->m_deserLoc + 0]) << 56);
456 1079845 break;
457 5 case Endianness::LITTLE:
458 // LSB first
459 5 val = (static_cast<U64>(buffAddr[this->m_deserLoc + 0]) << 0) |
460 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 1]) << 8) |
461 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 2]) << 16) |
462 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 3]) << 24) |
463 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 4]) << 32) |
464 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 5]) << 40) |
465 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 6]) << 48) |
466 5 (static_cast<U64>(buffAddr[this->m_deserLoc + 7]) << 56);
467 5 break;
468 default:
469 FW_ASSERT(false);
470 break;
471 }
472 1079850 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
473 1079850 return FW_SERIALIZE_OK;
474 }
475
476 6 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I64& val, Endianness mode) {
477 6 U64 unsignVal;
478
1/1
✓ Branch 7 taken 6 times.
6 SerializeStatus res = deserializeTo(unsignVal, mode);
479
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (res == SerializeStatus::FW_SERIALIZE_OK) {
480 6 val = static_cast<I64>(unsignVal);
481 }
482 6 return res;
483 }
484 #endif
485
486 1000005 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(F64& val, Endianness mode) {
487 // deserialize as 64-bit int to handle endianness
488 1000005 U64 tempVal;
489
1/1
✓ Branch 7 taken 1000005 times.
1000005 SerializeStatus stat = this->deserializeTo(tempVal, mode);
490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1000005 times.
1000005 if (stat != FW_SERIALIZE_OK) {
491 return stat;
492 }
493 // copy to argument
494 1000005 (void)memcpy(&val, &tempVal, sizeof(val));
495
496 1000005 return FW_SERIALIZE_OK;
497 }
498
499 206 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(bool& val, Endianness mode) {
500 // check for room
501 206 const Serializable::SizeType size = this->m_serLoc;
502
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 206 times.
206 if (size == this->m_deserLoc) {
503 return FW_DESERIALIZE_BUFFER_EMPTY;
504
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 206 times.
206 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(U8))) {
505 return FW_DESERIALIZE_SIZE_MISMATCH;
506 }
507 // read from current location
508 206 U8* buffAddr = this->m_buffAddr;
509 206 FW_ASSERT(buffAddr != nullptr);
510 206 const U8 byteVal = buffAddr[this->m_deserLoc + 0];
511
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 83 times.
206 if (FW_SERIALIZE_TRUE_VALUE == byteVal) {
512 123 val = true;
513
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 } else if (FW_SERIALIZE_FALSE_VALUE == byteVal) {
514 83 val = false;
515 } else {
516 return FW_DESERIALIZE_FORMAT_ERROR;
517 }
518
519 206 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(U8));
520 206 return FW_SERIALIZE_OK;
521 }
522
523 4 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(void*& val, Endianness mode) {
524 // Deserialize as pointer cast, then convert to void*
525 4 PlatformPointerCastType pointerCastVal = 0;
526
1/1
✓ Branch 7 taken 4 times.
4 const SerializeStatus stat = this->deserializeTo(pointerCastVal, mode);
527
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (stat == FW_SERIALIZE_OK) {
528 4 val = reinterpret_cast<void*>(pointerCastVal);
529 }
530 4 return stat;
531 }
532
533 32 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(F32& val, Endianness mode) {
534 // deserialize as 32-bit int to handle endianness
535 32 U32 tempVal = 0;
536
1/1
✓ Branch 7 taken 32 times.
32 SerializeStatus stat = this->deserializeTo(tempVal, mode);
537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (stat != FW_SERIALIZE_OK) {
538 return stat;
539 }
540 32 (void)memcpy(&val, &tempVal, sizeof(val));
541
542 32 return FW_SERIALIZE_OK;
543 }
544
545 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8* buff,
546 Serializable::SizeType& length,
547 Endianness endianMode) {
548 FwSizeType length_in_out = static_cast<FwSizeType>(length);
549 SerializeStatus status = this->deserializeTo(buff, length_in_out, Serialization::INCLUDE_LENGTH, endianMode);
550 length = static_cast<Serializable::SizeType>(length_in_out);
551 return status;
552 }
553
554 153000 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8* buff,
555 Serializable::SizeType& length,
556 Serialization::t lengthMode,
557 Endianness endianMode) {
558 153000 U8* buffAddr = this->m_buffAddr;
559 153000 FW_ASSERT(buffAddr != nullptr);
560
561
2/2
✓ Branch 0 taken 39927 times.
✓ Branch 1 taken 113073 times.
153000 if (lengthMode == Serialization::INCLUDE_LENGTH) {
562 39927 FwSizeStoreType storedLength = 0;
563
564
1/1
✓ Branch 7 taken 39927 times.
39927 SerializeStatus stat = this->deserializeTo(storedLength, endianMode);
565
566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39927 times.
39927 if (stat != FW_SERIALIZE_OK) {
567 return stat;
568 }
569
570 // make sure it fits
571
6/7
✓ Branch 7 taken 39927 times.
✓ Branch 9 taken 39926 times.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 39926 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 39926 times.
39927 if ((storedLength > this->getDeserializeSizeLeft()) || (storedLength > length)) {
572 1 return FW_DESERIALIZE_SIZE_MISMATCH;
573 }
574
575
2/2
✓ Branch 0 taken 39868 times.
✓ Branch 1 taken 58 times.
39926 if (storedLength > 0) {
576 39868 FW_ASSERT(buff != nullptr);
577 }
578
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 39926 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39926 times.
39926 (void)memcpy(buff, &buffAddr[this->m_deserLoc], static_cast<size_t>(storedLength));
579
580 39926 length = static_cast<FwSizeType>(storedLength);
581
582 } else {
583 // make sure enough is left
584
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 113072 times.
113073 if (length > this->getDeserializeSizeLeft()) {
585 1 return FW_DESERIALIZE_SIZE_MISMATCH;
586 }
587
588
2/2
✓ Branch 1 taken 113067 times.
✓ Branch 2 taken 5 times.
113072 if (length > 0) {
589 113067 FW_ASSERT(buff != nullptr);
590 }
591
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 113072 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 113072 times.
113072 (void)memcpy(buff, &buffAddr[this->m_deserLoc], static_cast<size_t>(length));
592 }
593
594 152998 this->m_deserLoc += static_cast<Serializable::SizeType>(length);
595 152998 return FW_SERIALIZE_OK;
596 }
597
598 1182990 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(Serializable& val, Endianness mode) {
599 1182990 return val.deserializeFrom(*this, mode);
600 }
601
602 10850 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(LinearBufferBase& val, Endianness mode) {
603 10850 U8* valBuffAddr = val.getBuffAddr();
604 10850 FW_ASSERT(valBuffAddr != nullptr);
605 10850 SerializeStatus stat = FW_SERIALIZE_OK;
606
607 10850 FwSizeStoreType storedLength = 0;
608
609
1/1
✓ Branch 7 taken 10850 times.
10850 stat = this->deserializeTo(storedLength, mode);
610
611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10850 times.
10850 if (stat != FW_SERIALIZE_OK) {
612 return stat;
613 }
614
615 // make sure destination has enough room
616
617
5/8
✓ Branch 7 taken 10850 times.
✓ Branch 9 taken 10850 times.
✗ Branch 10 not taken.
✓ Branch 18 taken 10850 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 10850 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 10850 times.
10850 if ((storedLength > val.getCapacity()) || (storedLength > this->getDeserializeSizeLeft())) {
618 return FW_DESERIALIZE_SIZE_MISMATCH;
619 }
620
621 10850 U8* thisBuffAddr = this->m_buffAddr;
622 10850 FW_ASSERT(thisBuffAddr != nullptr);
623
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 10850 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10850 times.
10850 (void)memcpy(valBuffAddr, &thisBuffAddr[this->m_deserLoc], static_cast<size_t>(storedLength));
624
625
1/1
✓ Branch 7 taken 10850 times.
10850 stat = val.setBuffLen(storedLength);
626
627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10850 times.
10850 if (stat != FW_SERIALIZE_OK) {
628 return stat;
629 }
630
631 10850 this->m_deserLoc += storedLength;
632
633 10850 return FW_SERIALIZE_OK;
634 }
635
636 42156 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeSize(FwSizeType& size, Endianness mode) {
637 42156 FwSizeStoreType storedSize = 0;
638
1/1
✓ Branch 7 taken 42156 times.
42156 Fw::SerializeStatus status = this->deserializeTo(storedSize, mode);
639
1/2
✓ Branch 0 taken 42156 times.
✗ Branch 1 not taken.
42156 if (status == FW_SERIALIZE_OK) {
640 42156 size = static_cast<FwSizeType>(storedSize);
641 }
642 42156 return status;
643 }
644
645 5871699 void LinearBufferBase::resetSer() {
646 5871699 this->m_deserLoc = 0;
647 5871699 this->m_serLoc = 0;
648 5871699 }
649
650 4905095 void LinearBufferBase::resetDeser() {
651 4905095 this->m_deserLoc = 0;
652 4905095 }
653
654 2617 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeSkip(FwSizeType numBytesToSkip) {
655 2617 Fw::SerializeStatus status = FW_SERIALIZE_OK;
656 // compute new ser loc
657 2617 const FwSizeType newSerLoc = this->m_serLoc + numBytesToSkip;
658 // check for room
659
1/2
✓ Branch 4 taken 2617 times.
✗ Branch 5 not taken.
2617 if (newSerLoc <= this->m_capacity) {
660 // update ser loc
661 2617 this->m_serLoc = static_cast<Serializable::SizeType>(newSerLoc);
662 } else {
663 status = FW_SERIALIZE_NO_ROOM_LEFT;
664 }
665 2617 return status;
666 }
667
668 1025318 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeSkip(FwSizeType numBytesToSkip) {
669 // check for room
670 1025318 const Serializable::SizeType size = this->m_serLoc;
671
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1025317 times.
1025318 if (size == this->m_deserLoc) {
672 1 return FW_DESERIALIZE_BUFFER_EMPTY;
673
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1025316 times.
1025317 } else if (size - this->m_deserLoc < numBytesToSkip) {
674 1 return FW_DESERIALIZE_SIZE_MISMATCH;
675 }
676 // update location in buffer to skip the value
677 1025316 this->m_deserLoc += static_cast<Serializable::SizeType>(numBytesToSkip);
678 1025316 return FW_SERIALIZE_OK;
679 }
680
681 101 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::moveSerToOffset(FwSizeType offset) {
682 // Reset serialization
683 101 this->resetSer();
684 // Advance to offset
685 101 return this->serializeSkip(offset);
686 }
687 47950 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::moveDeserToOffset(FwSizeType offset) {
688 // Reset deserialization
689 47950 this->resetDeser();
690 // Advance to offset
691 47950 return this->deserializeSkip(offset);
692 }
693
694 3222455 Serializable::SizeType LinearBufferBase::getSize() const {
695 3222455 return this->m_serLoc;
696 }
697
698 730197 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::setBuff(const U8* src, Serializable::SizeType length) {
699
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 730197 times.
730197 if (this->m_capacity < length) {
700 return FW_SERIALIZE_NO_ROOM_LEFT;
701 } else {
702 730197 FW_ASSERT(src);
703 730197 U8* buffAddr = this->m_buffAddr;
704 730197 FW_ASSERT(buffAddr != nullptr);
705
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 730197 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 730197 times.
730197 (void)memcpy(buffAddr, src, static_cast<size_t>(length));
706 730197 this->m_serLoc = length;
707 730197 this->m_deserLoc = 0;
708 730197 return FW_SERIALIZE_OK;
709 }
710 }
711
712 176170 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::setBuffLen(Serializable::SizeType length) {
713
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 176170 times.
176170 if (this->m_capacity < length) {
714 return FW_SERIALIZE_NO_ROOM_LEFT;
715 } else {
716 176170 this->m_serLoc = length;
717 176170 this->m_deserLoc = 0;
718 176170 return FW_SERIALIZE_OK;
719 }
720 }
721
722 3080594 Serializable::SizeType LinearBufferBase::getDeserializeSizeLeft() const {
723 3080594 FW_ASSERT(this->m_serLoc >= this->m_deserLoc, static_cast<FwAssertArgType>(this->m_serLoc),
724 static_cast<FwAssertArgType>(this->m_deserLoc));
725 3080594 return this->m_serLoc - this->m_deserLoc;
726 }
727
728 2 Serializable::SizeType LinearBufferBase::getSerializeSizeLeft() const {
729 2 FW_ASSERT(this->m_capacity >= this->m_serLoc, static_cast<FwAssertArgType>(this->m_capacity),
730 static_cast<FwAssertArgType>(this->m_serLoc));
731 2 return this->m_capacity - this->m_serLoc;
732 }
733
734 7453 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::copyRaw(SerialBufferBase& dest,
735 Serializable::SizeType size) {
736 // make sure there is sufficient size in destination
737
2/2
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7452 times.
7453 if (dest.getCapacity() < size) {
738 1 return FW_SERIALIZE_NO_ROOM_LEFT;
739 }
740 // make sure there is sufficient buffer in source
741
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 7452 times.
7452 if (this->getDeserializeSizeLeft() < size) {
742 return FW_DESERIALIZE_SIZE_MISMATCH;
743 }
744
745 // otherwise, set destination buffer to data from deserialization pointer plus size
746 7452 U8* buffAddr = this->m_buffAddr;
747
748 7452 FW_ASSERT(buffAddr);
749 7452 SerializeStatus stat = dest.setBuff(&buffAddr[this->m_deserLoc], size);
750
1/2
✓ Branch 0 taken 7452 times.
✗ Branch 1 not taken.
7452 if (stat == FW_SERIALIZE_OK) {
751 7452 this->m_deserLoc += size;
752 }
753 7452 return stat;
754 }
755
756 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::copyRawOffset(SerialBufferBase& dest,
757 Serializable::SizeType size) {
758 // make sure there is sufficient size in destination
759 const Serializable::SizeType destCapacity = dest.getCapacity();
760 const Serializable::SizeType destSize = dest.getSize();
761 if (destCapacity < size + destSize) {
762 return FW_SERIALIZE_NO_ROOM_LEFT;
763 }
764 // make sure there is sufficient buffer in source
765 if (this->getDeserializeSizeLeft() < size) {
766 return FW_DESERIALIZE_SIZE_MISMATCH;
767 }
768
769 // otherwise, serialize bytes to destination without writing length
770 U8* buffAddr = this->m_buffAddr;
771 SerializeStatus stat = dest.serializeFrom(&buffAddr[this->m_deserLoc], size, Serialization::OMIT_LENGTH);
772 if (stat == FW_SERIALIZE_OK) {
773 this->m_deserLoc += size;
774 }
775 return stat;
776 }
777
778 // return address of buffer not yet deserialized. This is used
779 // to copy the remainder of a buffer.
780 1008599 const U8* LinearBufferBase::getBuffAddrLeft() const {
781 1008599 const U8* buffAddr = this->m_buffAddr;
782 1008599 FW_ASSERT(buffAddr != nullptr);
783 1008599 return &buffAddr[this->m_deserLoc];
784 }
785
786 //!< gets address of end of serialization. Used to manually place data at the end
787 77146 U8* LinearBufferBase::getBuffAddrSer() {
788 77146 U8* buffAddr = this->m_buffAddr;
789 77146 FW_ASSERT(buffAddr != nullptr);
790 77146 return &buffAddr[this->m_serLoc];
791 }
792
793 #ifdef BUILD_UT
794 181 bool LinearBufferBase::operator==(const LinearBufferBase& other) const {
795
1/2
✗ Branch 11 not taken.
✓ Branch 12 taken 181 times.
181 if (this->m_serLoc != other.getSize()) {
796 return false;
797 }
798
799 181 const U8* us = this->m_buffAddr;
800 181 const U8* them = other.getBuffAddr();
801
802 181 FW_ASSERT(us);
803 181 FW_ASSERT(them);
804
805
2/2
✓ Branch 4 taken 4896 times.
✓ Branch 5 taken 181 times.
5077 for (Serializable::SizeType byte = 0; byte < this->m_serLoc; byte++) {
806
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4896 times.
4896 if (us[byte] != them[byte]) {
807 return false;
808 }
809 }
810
811 181 return true;
812 }
813
814 std::ostream& operator<<(std::ostream& os, const LinearBufferBase& buff) {
815 const U8* us = buff.getBuffAddr();
816
817 FW_ASSERT(us);
818
819 for (Serializable::SizeType byte = 0; byte < buff.getSize(); byte++) {
820 os << "[" << std::setw(2) << std::hex << std::setfill('0') << us[byte] << "]" << std::dec;
821 }
822
823 return os;
824 }
825 #endif
826
827 295068 ExternalSerializeBuffer::ExternalSerializeBuffer(U8* buffPtr, Serializable::SizeType size)
828 295068 : LinearBufferBase(nullptr, 0) {
829
1/1
✓ Branch 4 taken 295068 times.
295068 this->setExtBuffer(buffPtr, size);
830 295068 }
831
832 2046405 ExternalSerializeBuffer::ExternalSerializeBuffer() : LinearBufferBase(nullptr, 0) {
833
1/1
✓ Branch 4 taken 2046405 times.
2046405 this->clear();
834 2046405 }
835
836 2652149 void ExternalSerializeBuffer::setExtBuffer(U8* buffPtr, Serializable::SizeType size) {
837 // Allow setting buffer with null pointer and zero size (for initialization/reset)
838 // but reject null pointer with non-zero size
839 2652149 FW_ASSERT((buffPtr != nullptr) || (size == 0), static_cast<FwAssertArgType>(size));
840 2652149 this->clear();
841 2652149 this->setBuffAddrInternal(buffPtr);
842 2652149 this->setCapacityInternal(size);
843 2652149 }
844
845 4698651 void ExternalSerializeBuffer::clear() {
846 4698651 this->resetSer();
847 4698651 this->resetDeser();
848 4698651 this->setBuffAddrInternal(nullptr);
849 4698651 this->setCapacityInternal(0);
850 4698651 }
851
852 // ----------------------------------------------------------------------
853 // Deprecated method implementations for backward compatibility
854 // ----------------------------------------------------------------------
855
856 Serializable::SizeType LinearBufferBase::getBuffLength() const {
857 return this->m_serLoc;
858 }
859
860 Serializable::SizeType LinearBufferBase::getBuffLeft() {
861 return this->getDeserializeSizeLeft();
862 }
863
864 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U8 val) {
865 return this->serializeFrom(val);
866 }
867 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I8 val) {
868 return this->serializeFrom(val);
869 }
870 #if FW_HAS_16_BIT == 1
871 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U16 val) {
872 return this->serializeFrom(val);
873 }
874 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I16 val) {
875 return this->serializeFrom(val);
876 }
877 #endif
878 #if FW_HAS_32_BIT == 1
879 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U32 val) {
880 return this->serializeFrom(val);
881 }
882 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I32 val) {
883 return this->serializeFrom(val);
884 }
885 #endif
886 #if FW_HAS_64_BIT == 1
887 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U64 val) {
888 return this->serializeFrom(val);
889 }
890 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I64 val) {
891 return this->serializeFrom(val);
892 }
893 #endif
894 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(F32 val) {
895 return this->serializeFrom(val);
896 }
897 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(F64 val) {
898 return this->serializeFrom(val);
899 }
900 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(bool val) {
901 return this->serializeFrom(val);
902 }
903 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const void* val) {
904 return this->serializeFrom(val);
905 }
906
907 // Deprecated method for backward compatibility
908 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff,
909 FwSizeType length,
910 bool noLength) {
911 const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH;
912 return this->serializeFrom(buff, length, mode);
913 }
914
915 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff, FwSizeType length) {
916 return this->serializeFrom(buff, length);
917 }
918 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff,
919 FwSizeType length,
920 Serialization::t mode) {
921 return this->serializeFrom(buff, length, mode);
922 }
923 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const Serializable& val) {
924 return this->serializeFrom(val);
925 }
926 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const LinearBufferBase& val) {
927 return this->serializeFrom(val);
928 }
929
930 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8& val) {
931 return this->deserializeTo(val);
932 }
933 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I8& val) {
934 return this->deserializeTo(val);
935 }
936 #if FW_HAS_16_BIT == 1
937 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U16& val) {
938 return this->deserializeTo(val);
939 }
940 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I16& val) {
941 return this->deserializeTo(val);
942 }
943 #endif
944 #if FW_HAS_32_BIT == 1
945 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U32& val) {
946 return this->deserializeTo(val);
947 }
948 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I32& val) {
949 return this->deserializeTo(val);
950 }
951 #endif
952 #if FW_HAS_64_BIT == 1
953 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U64& val) {
954 return this->deserializeTo(val);
955 }
956 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I64& val) {
957 return this->deserializeTo(val);
958 }
959 #endif
960 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(F32& val) {
961 return this->deserializeTo(val);
962 }
963 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(F64& val) {
964 return this->deserializeTo(val);
965 }
966 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(bool& val) {
967 return this->deserializeTo(val);
968 }
969 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(void*& val) {
970 return this->deserializeTo(val);
971 }
972
973 // Deprecated method for backward compatibility
974 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff,
975 FwSizeType& length,
976 bool noLength) {
977 const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH;
978 return this->deserializeTo(buff, length, mode);
979 }
980
981 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff, FwSizeType& length) {
982 return this->deserializeTo(buff, length, Serialization::INCLUDE_LENGTH);
983 }
984
985 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff,
986 FwSizeType& length,
987 Serialization::t mode) {
988 return this->deserializeTo(buff, length, mode);
989 }
990
991 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(Serializable& val) {
992 return this->deserializeTo(val);
993 }
994 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(LinearBufferBase& val) {
995 return this->deserializeTo(val);
996 }
997
998 Serializable::SizeType ExternalSerializeBuffer::getBuffCapacity() const {
999 return this->getCapacity();
1000 }
1001
1002 } // namespace Fw
1003