GCC Code Coverage Report


Directory: ./
File: Fw/Types/Serializable.cpp
Date: 2026-09-23 21:11:01
Exec Total Coverage
Lines: 415 576 72.0%
Functions: 57 101 56.4%
Branches: 132 208 63.5%

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 78510149 Serializable::Serializable() {}
15
16 156937348 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 10248596 SerialBufferBase::~SerialBufferBase() {}
39
40 5129664 LinearBufferBase::LinearBufferBase(U8* buffAddr, Serializable::SizeType capacity)
41 5131627 : m_buffAddr(buffAddr), m_capacity(capacity), m_serLoc(0), m_deserLoc(0) {
42 // Ensure buffAddr & capacity are consistent
43 5131243 FW_ASSERT((buffAddr == nullptr) == (capacity == 0), static_cast<FwAssertArgType>(capacity));
44 5131243 }
45
46 10249652 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 10882325 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U8 val, Endianness mode) {
71
2/2
✓ Branch 8 taken 1999997 times.
✓ Branch 9 taken 8882328 times.
10882325 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
72 1999997 return FW_SERIALIZE_NO_ROOM_LEFT;
73 }
74 8882328 U8* buffAddr = this->m_buffAddr;
75 8882328 FW_ASSERT(buffAddr != nullptr);
76 8882328 buffAddr[this->m_serLoc] = val;
77 8882328 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
78 8882328 this->m_deserLoc = 0;
79
80 8882328 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 2263489 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U16 val, Endianness mode) {
89
2/2
✓ Branch 8 taken 1999995 times.
✓ Branch 9 taken 263494 times.
2263489 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
90 1999995 return FW_SERIALIZE_NO_ROOM_LEFT;
91 }
92 263494 U8* buffAddr = this->m_buffAddr;
93 263494 FW_ASSERT(buffAddr != nullptr);
94
2/3
✓ Branch 0 taken 263491 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
263494 switch (mode) {
95 263491 case Endianness::BIG:
96 // MSB first
97 263491 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 8);
98 263491 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val);
99 263491 break;
100 3 case Endianness::LITTLE:
101 // LSB first
102 3 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
103 3 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
104 3 break;
105 ✗ default:
106 ✗ FW_ASSERT(false);
107 ✗ break;
108 }
109 263494 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
110 263494 this->m_deserLoc = 0;
111 263494 return FW_SERIALIZE_OK;
112 }
113
114 151696 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I16 val, Endianness mode) {
115 151696 return serializeFrom(static_cast<U16>(val), mode);
116 }
117 #endif
118 #if FW_HAS_32_BIT == 1
119 5065376 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U32 val, Endianness mode) {
120
2/2
✓ Branch 8 taken 3999991 times.
✓ Branch 9 taken 1065385 times.
5065376 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
121 3999991 return FW_SERIALIZE_NO_ROOM_LEFT;
122 }
123 1065385 U8* buffAddr = this->m_buffAddr;
124 1065385 FW_ASSERT(buffAddr != nullptr);
125
2/3
✓ Branch 0 taken 1065374 times.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
1065385 switch (mode) {
126 1065374 case Endianness::BIG:
127 // MSB first
128 1065374 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 24);
129 1065374 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 16);
130 1065374 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 8);
131 1065374 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val);
132 1065374 break;
133 11 case Endianness::LITTLE:
134 // LSB first
135 11 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
136 11 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
137 11 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 16);
138 11 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 24);
139 11 break;
140 ✗ default:
141 ✗ FW_ASSERT(false);
142 ✗ break;
143 }
144 1065385 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
145 1065385 this->m_deserLoc = 0;
146 1065385 return FW_SERIALIZE_OK;
147 }
148
149 194718 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I32 val, Endianness mode) {
150 194718 return serializeFrom(static_cast<U32>(val), mode);
151 }
152 #endif
153
154 #if FW_HAS_64_BIT == 1
155 3677678 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(U64 val, Endianness mode) {
156
2/2
✓ Branch 8 taken 1999996 times.
✓ Branch 9 taken 1677682 times.
3677678 if (this->m_serLoc + static_cast<Serializable::SizeType>(sizeof(val)) - 1 >= this->m_capacity) {
157 1999996 return FW_SERIALIZE_NO_ROOM_LEFT;
158 }
159 1677682 U8* buffAddr = this->m_buffAddr;
160 1677682 FW_ASSERT(buffAddr != nullptr);
161
2/3
✓ Branch 0 taken 1677676 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
1677682 switch (mode) {
162 1677676 case Endianness::BIG:
163 // MSB first
164 1677676 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val >> 56);
165 1677676 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 48);
166 1677676 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 40);
167 1677676 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 32);
168 1677676 buffAddr[this->m_serLoc + 4] = static_cast<U8>(val >> 24);
169 1677676 buffAddr[this->m_serLoc + 5] = static_cast<U8>(val >> 16);
170 1677676 buffAddr[this->m_serLoc + 6] = static_cast<U8>(val >> 8);
171 1677676 buffAddr[this->m_serLoc + 7] = static_cast<U8>(val);
172 1677676 break;
173 6 case Endianness::LITTLE:
174 // LSB first
175 6 buffAddr[this->m_serLoc + 0] = static_cast<U8>(val);
176 6 buffAddr[this->m_serLoc + 1] = static_cast<U8>(val >> 8);
177 6 buffAddr[this->m_serLoc + 2] = static_cast<U8>(val >> 16);
178 6 buffAddr[this->m_serLoc + 3] = static_cast<U8>(val >> 24);
179 6 buffAddr[this->m_serLoc + 4] = static_cast<U8>(val >> 32);
180 6 buffAddr[this->m_serLoc + 5] = static_cast<U8>(val >> 40);
181 6 buffAddr[this->m_serLoc + 6] = static_cast<U8>(val >> 48);
182 6 buffAddr[this->m_serLoc + 7] = static_cast<U8>(val >> 56);
183 6 break;
184 ✗ default:
185 ✗ FW_ASSERT(false);
186 ✗ break;
187 }
188 1677682 this->m_serLoc += static_cast<Serializable::SizeType>(sizeof(val));
189 1677682 this->m_deserLoc = 0;
190 1677682 return FW_SERIALIZE_OK;
191 }
192
193 151 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(I64 val, Endianness mode) {
194 151 return serializeFrom(static_cast<U64>(val), mode);
195 }
196 #endif
197
198 1000012 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 1000012 U64 u64Val;
201 1000012 (void)memcpy(&u64Val, &val, sizeof(val));
202
1/1
✓ Branch 7 taken 1000012 times.
2000024 return this->serializeFrom(u64Val, mode);
203 }
204
205 2000272 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 2000272 U32 u32Val;
208 2000272 (void)memcpy(&u32Val, &val, sizeof(val));
209
1/1
✓ Branch 7 taken 2000272 times.
4000544 return this->serializeFrom(u32Val, mode);
210 }
211
212 5362 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(bool val, Endianness mode) {
213 // booleans are encoded as a single byte
214 static_assert(FW_SERIALIZE_TRUE_VALUE <= 0xFF && FW_SERIALIZE_FALSE_VALUE <= 0xFF,
215 "boolean wire values must fit in one byte");
216 static_assert(static_cast<int>(FW_SERIALIZE_TRUE_VALUE) != static_cast<int>(FW_SERIALIZE_FALSE_VALUE),
217 "boolean wire values must be distinct");
218
2/2
✓ Branch 0 taken 127 times.
✓ Branch 1 taken 5235 times.
5362 const U8 byteVal = val ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE) : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE);
219 5362 return this->serializeFrom(byteVal, mode);
220 }
221
222 35 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const void* val, Endianness mode) {
223 // pointers are serialized as their integer representation
224 35 return this->serializeFrom(reinterpret_cast<PlatformPointerCastType>(val), mode);
225 }
226
227 2012039 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const U8* buff,
228 Serializable::SizeType length,
229 Endianness endianMode) {
230 2012039 return this->serializeFrom(buff, static_cast<FwSizeType>(length), Serialization::INCLUDE_LENGTH, endianMode);
231 }
232
233 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus
234 2565618 LinearBufferBase::serializeFrom(const U8* buff,
235 FwSizeType length,
236 Serialization::t lengthMode,
237 Endianness endianMode) { // First serialize length
238 SerializeStatus stat;
239
2/2
✓ Branch 0 taken 2053739 times.
✓ Branch 1 taken 511879 times.
2565618 if (lengthMode == Serialization::INCLUDE_LENGTH) {
240 2053739 stat = this->serializeFrom(static_cast<FwSizeStoreType>(length), endianMode);
241
2/2
✓ Branch 0 taken 1999994 times.
✓ Branch 1 taken 53745 times.
2053739 if (stat != FW_SERIALIZE_OK) {
242 1999994 return stat;
243 }
244 }
245
246 // make sure we have enough space
247 // Note: m_serLoc <= m_capacity is a class invariant, so this subtraction cannot underflow.
248
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 565624 times.
565624 if (length > this->m_capacity - this->m_serLoc) {
249 ✗ return FW_SERIALIZE_NO_ROOM_LEFT;
250 }
251
252
2/2
✓ Branch 0 taken 564174 times.
✓ Branch 1 taken 1450 times.
565624 if (length > 0) {
253 564174 FW_ASSERT(buff != nullptr);
254 }
255 565624 U8* buffAddr = this->m_buffAddr;
256 565624 FW_ASSERT(buffAddr != nullptr);
257 // copy buffer to our buffer; memmove is used because the source may overlap this buffer
258
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 565624 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 565624 times.
565624 (void)memmove(&buffAddr[this->m_serLoc], buff, static_cast<size_t>(length));
259 565624 this->m_serLoc += static_cast<Serializable::SizeType>(length);
260 565624 this->m_deserLoc = 0;
261
262 565624 return FW_SERIALIZE_OK;
263 }
264
265 1153086 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const Serializable& val,
266 Endianness mode) {
267 1153086 return val.serializeTo(*this, mode);
268 }
269
270 13449 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeFrom(const LinearBufferBase& val,
271 Endianness mode) {
272 13449 Serializable::SizeType size = val.getSize();
273 // Note: m_serLoc <= m_capacity is a class invariant, so this subtraction cannot underflow.
274 13449 Serializable::SizeType available = this->m_capacity - this->m_serLoc;
275
2/4
✓ Branch 0 taken 13449 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13449 times.
13449 if (size > available || static_cast<Serializable::SizeType>(sizeof(FwSizeStoreType)) > available - size) {
276 ✗ return FW_SERIALIZE_NO_ROOM_LEFT;
277 }
278
279 // First, serialize size
280 13449 SerializeStatus stat = this->serializeFrom(static_cast<FwSizeStoreType>(size), mode);
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13449 times.
13449 if (stat != FW_SERIALIZE_OK) {
282 ✗ return stat;
283 }
284
285 13449 U8* thisBuffAddr = this->m_buffAddr;
286 13449 const U8* valBuffAddr = val.getBuffAddr();
287 13449 FW_ASSERT(thisBuffAddr != nullptr);
288 13449 FW_ASSERT(valBuffAddr != nullptr);
289 // serialize buffer
290
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 13449 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13449 times.
13449 (void)memcpy(&thisBuffAddr[this->m_serLoc], valBuffAddr, static_cast<size_t>(size));
291 13449 this->m_serLoc += size;
292 13449 this->m_deserLoc = 0;
293
294 13449 return FW_SERIALIZE_OK;
295 }
296
297 32870 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeSize(const FwSizeType size, Endianness mode) {
298 32870 SerializeStatus status = FW_SERIALIZE_OK;
299
3/6
✓ Branch 1 taken 32870 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 32870 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 32870 times.
32870 if ((size < std::numeric_limits<FwSizeStoreType>::min()) || (size > std::numeric_limits<FwSizeStoreType>::max())) {
300 ✗ status = FW_SERIALIZE_FORMAT_ERROR;
301 }
302
1/2
✓ Branch 0 taken 32870 times.
✗ Branch 1 not taken.
32870 if (status == FW_SERIALIZE_OK) {
303 32870 status = this->serializeFrom(static_cast<FwSizeStoreType>(size), mode);
304 }
305 32870 return status;
306 }
307
308 // deserialization routines
309
310 780635 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8& val, Endianness mode) {
311 // check for room
312 780635 const Serializable::SizeType size = this->m_serLoc;
313
2/2
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 780626 times.
780635 if (size == this->m_deserLoc) {
314 9 return FW_DESERIALIZE_BUFFER_EMPTY;
315
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 780626 times.
780626 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
316 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
317 }
318 // read from current location
319 780626 U8* buffAddr = this->m_buffAddr;
320 780626 FW_ASSERT(buffAddr != nullptr);
321 780626 val = buffAddr[this->m_deserLoc + 0];
322 780626 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
323 780626 return FW_SERIALIZE_OK;
324 }
325
326 13 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I8& val, Endianness mode) {
327 // check for room
328 13 const Serializable::SizeType size = this->m_serLoc;
329
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
13 if (size == this->m_deserLoc) {
330 ✗ return FW_DESERIALIZE_BUFFER_EMPTY;
331
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
13 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
332 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
333 }
334 // read from current location
335 13 U8* buffAddr = this->m_buffAddr;
336 13 FW_ASSERT(buffAddr != nullptr);
337 13 val = static_cast<I8>(buffAddr[this->m_deserLoc + 0]);
338 13 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
339 13 return FW_SERIALIZE_OK;
340 }
341
342 #if FW_HAS_16_BIT == 1
343 297065 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U16& val, Endianness mode) {
344 // check for room
345 297065 const Serializable::SizeType size = this->m_serLoc;
346
2/2
✓ Branch 4 taken 78463 times.
✓ Branch 5 taken 219277 times.
297919 if (size == this->m_deserLoc) {
347 78463 return FW_DESERIALIZE_BUFFER_EMPTY;
348
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 219275 times.
219277 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
349 2 return FW_DESERIALIZE_SIZE_MISMATCH;
350 }
351 // read from current location
352 219275 U8* buffAddr = this->m_buffAddr;
353 219275 FW_ASSERT(buffAddr != nullptr);
354
2/3
✓ Branch 0 taken 219272 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
219275 switch (mode) {
355 219272 case Endianness::BIG:
356 // MSB first
357
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 219272 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 219272 times.
219272 val = static_cast<U16>(((buffAddr[this->m_deserLoc + 1]) << 0) | ((buffAddr[this->m_deserLoc + 0]) << 8));
358 219272 break;
359 3 case Endianness::LITTLE:
360 // LSB first
361
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 3 times.
3 val = static_cast<U16>(((buffAddr[this->m_deserLoc + 0]) << 0) | ((buffAddr[this->m_deserLoc + 1]) << 8));
362 3 break;
363 ✗ default:
364 ✗ FW_ASSERT(false);
365 ✗ break;
366 }
367 219275 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
368 219275 return FW_SERIALIZE_OK;
369 }
370
371 90996 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I16& val, Endianness mode) {
372 90996 U16 unsignVal = 0;
373
1/1
✓ Branch 7 taken 90996 times.
90996 SerializeStatus res = deserializeTo(unsignVal, mode);
374
2/2
✓ Branch 0 taken 90995 times.
✓ Branch 1 taken 1 times.
90996 if (res == SerializeStatus::FW_SERIALIZE_OK) {
375 90995 val = static_cast<I16>(unsignVal);
376 }
377 90996 return res;
378 }
379 #endif
380 #if FW_HAS_32_BIT == 1
381 989037 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U32& val, Endianness mode) {
382 // check for room
383 989037 const Serializable::SizeType size = this->m_serLoc;
384
2/2
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 989023 times.
989037 if (size == this->m_deserLoc) {
385 14 return FW_DESERIALIZE_BUFFER_EMPTY;
386
2/2
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 989015 times.
989023 } else if (size - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
387 8 return FW_DESERIALIZE_SIZE_MISMATCH;
388 }
389 // read from current location
390 989015 U8* buffAddr = this->m_buffAddr;
391 989015 FW_ASSERT(buffAddr != nullptr);
392
2/3
✓ Branch 0 taken 989011 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
989015 switch (mode) {
393 989011 case Endianness::BIG:
394 // MSB first
395 989011 val = (static_cast<U32>(buffAddr[this->m_deserLoc + 3]) << 0) |
396 989011 (static_cast<U32>(buffAddr[this->m_deserLoc + 2]) << 8) |
397 989011 (static_cast<U32>(buffAddr[this->m_deserLoc + 1]) << 16) |
398 989011 (static_cast<U32>(buffAddr[this->m_deserLoc + 0]) << 24);
399 989011 break;
400 4 case Endianness::LITTLE:
401 // LSB first
402 4 val = (static_cast<U32>(buffAddr[this->m_deserLoc + 0]) << 0) |
403 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 1]) << 8) |
404 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 2]) << 16) |
405 4 (static_cast<U32>(buffAddr[this->m_deserLoc + 3]) << 24);
406 4 break;
407 ✗ default:
408 ✗ FW_ASSERT(false);
409 ✗ break;
410 }
411 989015 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
412 989015 return FW_SERIALIZE_OK;
413 }
414
415 133819 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I32& val, Endianness mode) {
416 133819 U32 unsignVal = 0;
417
1/1
✓ Branch 7 taken 133819 times.
133819 SerializeStatus res = deserializeTo(unsignVal, mode);
418
1/2
✓ Branch 0 taken 133819 times.
✗ Branch 1 not taken.
133819 if (res == SerializeStatus::FW_SERIALIZE_OK) {
419 133819 val = static_cast<I32>(unsignVal);
420 }
421 133819 return res;
422 }
423 #endif
424
425 #if FW_HAS_64_BIT == 1
426
427 1683262 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U64& val, Endianness mode) {
428 // check for room
429
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1683262 times.
1683262 if (this->m_serLoc == this->m_deserLoc) {
430 ✗ return FW_DESERIALIZE_BUFFER_EMPTY;
431
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 1683262 times.
1683262 } else if (this->m_serLoc - this->m_deserLoc < static_cast<Serializable::SizeType>(sizeof(val))) {
432 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
433 }
434 // read from current location
435 1683262 U8* buffAddr = this->m_buffAddr;
436 1683262 FW_ASSERT(buffAddr != nullptr);
437
2/3
✓ Branch 0 taken 1683256 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
1683262 switch (mode) {
438 1683256 case Endianness::BIG:
439 // MSB first
440 1683256 val = (static_cast<U64>(buffAddr[this->m_deserLoc + 7]) << 0) |
441 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 6]) << 8) |
442 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 5]) << 16) |
443 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 4]) << 24) |
444 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 3]) << 32) |
445 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 2]) << 40) |
446 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 1]) << 48) |
447 1683256 (static_cast<U64>(buffAddr[this->m_deserLoc + 0]) << 56);
448 1683256 break;
449 6 case Endianness::LITTLE:
450 // LSB first
451 6 val = (static_cast<U64>(buffAddr[this->m_deserLoc + 0]) << 0) |
452 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 1]) << 8) |
453 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 2]) << 16) |
454 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 3]) << 24) |
455 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 4]) << 32) |
456 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 5]) << 40) |
457 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 6]) << 48) |
458 6 (static_cast<U64>(buffAddr[this->m_deserLoc + 7]) << 56);
459 6 break;
460 ✗ default:
461 ✗ FW_ASSERT(false);
462 ✗ break;
463 }
464 1683262 this->m_deserLoc += static_cast<Serializable::SizeType>(sizeof(val));
465 1683262 return FW_SERIALIZE_OK;
466 }
467
468 151 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(I64& val, Endianness mode) {
469 151 U64 unsignVal;
470
1/1
✓ Branch 7 taken 151 times.
151 SerializeStatus res = deserializeTo(unsignVal, mode);
471
1/2
✓ Branch 0 taken 151 times.
✗ Branch 1 not taken.
151 if (res == SerializeStatus::FW_SERIALIZE_OK) {
472 151 val = static_cast<I64>(unsignVal);
473 }
474 151 return res;
475 }
476 #endif
477
478 1000011 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(F64& val, Endianness mode) {
479 // deserialize as 64-bit int to handle endianness
480 1000011 U64 tempVal;
481
1/1
✓ Branch 7 taken 1000011 times.
1000011 SerializeStatus stat = this->deserializeTo(tempVal, mode);
482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1000011 times.
1000011 if (stat != FW_SERIALIZE_OK) {
483 ✗ return stat;
484 }
485 // copy to argument
486 1000011 (void)memcpy(&val, &tempVal, sizeof(val));
487
488 1000011 return FW_SERIALIZE_OK;
489 }
490
491 5358 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(bool& val, Endianness mode) {
492 5358 U8 byteVal = 0;
493
1/1
✓ Branch 7 taken 5358 times.
5358 const SerializeStatus stat = this->deserializeTo(byteVal, mode);
494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5358 times.
5358 if (stat != FW_SERIALIZE_OK) {
495 ✗ return stat;
496 }
497
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 5234 times.
5358 if (FW_SERIALIZE_TRUE_VALUE == byteVal) {
498 124 val = true;
499
2/2
✓ Branch 0 taken 5233 times.
✓ Branch 1 taken 1 times.
5234 } else if (FW_SERIALIZE_FALSE_VALUE == byteVal) {
500 5233 val = false;
501 } else {
502 // leave the malformed byte unconsumed
503 1 this->m_deserLoc -= static_cast<Serializable::SizeType>(sizeof(byteVal));
504 1 return FW_DESERIALIZE_FORMAT_ERROR;
505 }
506 5357 return FW_SERIALIZE_OK;
507 }
508
509 4 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(void*& val, Endianness mode) {
510 // Deserialize as pointer cast, then convert to void*
511 4 PlatformPointerCastType pointerCastVal = 0;
512
1/1
✓ Branch 7 taken 4 times.
4 const SerializeStatus stat = this->deserializeTo(pointerCastVal, mode);
513
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (stat == FW_SERIALIZE_OK) {
514 4 val = reinterpret_cast<void*>(pointerCastVal);
515 }
516 4 return stat;
517 }
518
519 42 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(F32& val, Endianness mode) {
520 // deserialize as 32-bit int to handle endianness
521 42 U32 tempVal = 0;
522
1/1
✓ Branch 7 taken 42 times.
42 SerializeStatus stat = this->deserializeTo(tempVal, mode);
523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (stat != FW_SERIALIZE_OK) {
524 ✗ return stat;
525 }
526 42 (void)memcpy(&val, &tempVal, sizeof(val));
527
528 42 return FW_SERIALIZE_OK;
529 }
530
531 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8* buff,
532 Serializable::SizeType& length,
533 Endianness endianMode) {
534 ✗ FwSizeType length_in_out = static_cast<FwSizeType>(length);
535 ✗ SerializeStatus status = this->deserializeTo(buff, length_in_out, Serialization::INCLUDE_LENGTH, endianMode);
536 ✗ length = static_cast<Serializable::SizeType>(length_in_out);
537 ✗ return status;
538 }
539
540 155693 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(U8* buff,
541 Serializable::SizeType& length,
542 Serialization::t lengthMode,
543 Endianness endianMode) {
544 155693 U8* buffAddr = this->m_buffAddr;
545 155693 FW_ASSERT(buffAddr != nullptr);
546
547
2/2
✓ Branch 0 taken 42656 times.
✓ Branch 1 taken 113037 times.
155693 if (lengthMode == Serialization::INCLUDE_LENGTH) {
548 42656 FwSizeStoreType storedLength = 0;
549
550
1/1
✓ Branch 7 taken 42656 times.
42656 SerializeStatus stat = this->deserializeTo(storedLength, endianMode);
551
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42656 times.
42656 if (stat != FW_SERIALIZE_OK) {
553 ✗ return stat;
554 }
555
556 // make sure it fits
557
6/7
✓ Branch 7 taken 42656 times.
✓ Branch 9 taken 42655 times.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 42655 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 42655 times.
42656 if ((storedLength > this->getDeserializeSizeLeft()) || (storedLength > length)) {
558 1 return FW_DESERIALIZE_SIZE_MISMATCH;
559 }
560
561
2/2
✓ Branch 0 taken 42248 times.
✓ Branch 1 taken 407 times.
42655 if (storedLength > 0) {
562 42248 FW_ASSERT(buff != nullptr);
563 }
564
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 42655 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 42655 times.
42655 (void)memcpy(buff, &buffAddr[this->m_deserLoc], static_cast<size_t>(storedLength));
565
566 42655 length = static_cast<FwSizeType>(storedLength);
567
568 } else {
569 // make sure enough is left
570
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 113036 times.
113037 if (length > this->getDeserializeSizeLeft()) {
571 1 return FW_DESERIALIZE_SIZE_MISMATCH;
572 }
573
574
2/2
✓ Branch 1 taken 113031 times.
✓ Branch 2 taken 5 times.
113036 if (length > 0) {
575 113031 FW_ASSERT(buff != nullptr);
576 }
577
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 113036 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 113036 times.
113036 (void)memcpy(buff, &buffAddr[this->m_deserLoc], static_cast<size_t>(length));
578 }
579
580 155691 this->m_deserLoc += static_cast<Serializable::SizeType>(length);
581 155691 return FW_SERIALIZE_OK;
582 }
583
584 1216666 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(Serializable& val, Endianness mode) {
585 1216666 return val.deserializeFrom(*this, mode);
586 }
587
588 11229 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeTo(LinearBufferBase& val, Endianness mode) {
589 11229 U8* valBuffAddr = val.getBuffAddr();
590 11229 FW_ASSERT(valBuffAddr != nullptr);
591 11229 SerializeStatus stat = FW_SERIALIZE_OK;
592
593 11229 FwSizeStoreType storedLength = 0;
594
595
1/1
✓ Branch 7 taken 11229 times.
11229 stat = this->deserializeTo(storedLength, mode);
596
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11229 times.
11229 if (stat != FW_SERIALIZE_OK) {
598 ✗ return stat;
599 }
600
601 // make sure destination has enough room
602
603
5/8
✓ Branch 7 taken 11229 times.
✓ Branch 9 taken 11229 times.
✗ Branch 10 not taken.
✓ Branch 18 taken 11229 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 11229 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 11229 times.
11229 if ((storedLength > val.getCapacity()) || (storedLength > this->getDeserializeSizeLeft())) {
604 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
605 }
606
607 11229 U8* thisBuffAddr = this->m_buffAddr;
608 11229 FW_ASSERT(thisBuffAddr != nullptr);
609
2/4
✗ Branch 5 not taken.
✓ Branch 6 taken 11229 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11229 times.
11229 (void)memcpy(valBuffAddr, &thisBuffAddr[this->m_deserLoc], static_cast<size_t>(storedLength));
610
611
1/1
✓ Branch 7 taken 11229 times.
11229 stat = val.setBuffLen(storedLength);
612
613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11229 times.
11229 if (stat != FW_SERIALIZE_OK) {
614 ✗ return stat;
615 }
616
617 11229 this->m_deserLoc += storedLength;
618
619 11229 return FW_SERIALIZE_OK;
620 }
621
622 42120 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeSize(FwSizeType& size, Endianness mode) {
623 42120 FwSizeStoreType storedSize = 0;
624
1/1
✓ Branch 7 taken 42120 times.
42120 Fw::SerializeStatus status = this->deserializeTo(storedSize, mode);
625
1/2
✓ Branch 0 taken 42120 times.
✗ Branch 1 not taken.
42120 if (status == FW_SERIALIZE_OK) {
626 42120 size = static_cast<FwSizeType>(storedSize);
627 }
628 42120 return status;
629 }
630
631 5948763 void LinearBufferBase::resetSer() {
632 5948763 this->m_deserLoc = 0;
633 5948763 this->m_serLoc = 0;
634 5948763 }
635
636 4993479 void LinearBufferBase::resetDeser() {
637 4993479 this->m_deserLoc = 0;
638 4993479 }
639
640 2640 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serializeSkip(FwSizeType numBytesToSkip) {
641 2640 Fw::SerializeStatus status = FW_SERIALIZE_OK;
642 // compute new ser loc
643 2640 const FwSizeType newSerLoc = this->m_serLoc + numBytesToSkip;
644 // check for room
645
1/2
✓ Branch 4 taken 2640 times.
✗ Branch 5 not taken.
2640 if (newSerLoc <= this->m_capacity) {
646 // update ser loc
647 2640 this->m_serLoc = static_cast<Serializable::SizeType>(newSerLoc);
648 } else {
649 ✗ status = FW_SERIALIZE_NO_ROOM_LEFT;
650 }
651 2640 return status;
652 }
653
654 1042469 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserializeSkip(FwSizeType numBytesToSkip) {
655 // check for room
656 1042469 const Serializable::SizeType size = this->m_serLoc;
657
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1042468 times.
1042469 if (size == this->m_deserLoc) {
658 1 return FW_DESERIALIZE_BUFFER_EMPTY;
659
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1042467 times.
1042468 } else if (size - this->m_deserLoc < numBytesToSkip) {
660 1 return FW_DESERIALIZE_SIZE_MISMATCH;
661 }
662 // update location in buffer to skip the value
663 1042467 this->m_deserLoc += static_cast<Serializable::SizeType>(numBytesToSkip);
664 1042467 return FW_SERIALIZE_OK;
665 }
666
667 122 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::moveSerToOffset(FwSizeType offset) {
668 // Reset serialization
669 122 this->resetSer();
670 // Advance to offset
671 122 return this->serializeSkip(offset);
672 }
673 59407 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::moveDeserToOffset(FwSizeType offset) {
674 // Reset deserialization
675 59407 this->resetDeser();
676 // Advance to offset
677 59407 return this->deserializeSkip(offset);
678 }
679
680 3279202 Serializable::SizeType LinearBufferBase::getSize() const {
681 3279202 return this->m_serLoc;
682 }
683
684 734529 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::setBuff(const U8* src, Serializable::SizeType length) {
685
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 734529 times.
734529 if (this->m_capacity < length) {
686 ✗ return FW_SERIALIZE_NO_ROOM_LEFT;
687 } else {
688 734529 FW_ASSERT(src);
689 734529 U8* buffAddr = this->m_buffAddr;
690 734529 FW_ASSERT(buffAddr != nullptr);
691
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 734529 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 734529 times.
734529 (void)memcpy(buffAddr, src, static_cast<size_t>(length));
692 734529 this->m_serLoc = length;
693 734529 this->m_deserLoc = 0;
694 734529 return FW_SERIALIZE_OK;
695 }
696 }
697
698 188796 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::setBuffLen(Serializable::SizeType length) {
699
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 188796 times.
188796 if (this->m_capacity < length) {
700 ✗ return FW_SERIALIZE_NO_ROOM_LEFT;
701 } else {
702 188796 this->m_serLoc = length;
703 188796 this->m_deserLoc = 0;
704 188796 return FW_SERIALIZE_OK;
705 }
706 }
707
708 3112880 Serializable::SizeType LinearBufferBase::getDeserializeSizeLeft() const {
709 3112880 FW_ASSERT(this->m_serLoc >= this->m_deserLoc, static_cast<FwAssertArgType>(this->m_serLoc),
710 static_cast<FwAssertArgType>(this->m_deserLoc));
711 3112880 return this->m_serLoc - this->m_deserLoc;
712 }
713
714 2 Serializable::SizeType LinearBufferBase::getSerializeSizeLeft() const {
715 2 FW_ASSERT(this->m_capacity >= this->m_serLoc, static_cast<FwAssertArgType>(this->m_capacity),
716 static_cast<FwAssertArgType>(this->m_serLoc));
717 2 return this->m_capacity - this->m_serLoc;
718 }
719
720 7524 FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::copyRaw(SerialBufferBase& dest,
721 Serializable::SizeType size) {
722 // make sure there is sufficient size in destination
723
2/2
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7523 times.
7524 if (dest.getCapacity() < size) {
724 1 return FW_SERIALIZE_NO_ROOM_LEFT;
725 }
726 // make sure there is sufficient buffer in source
727
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 7523 times.
7523 if (this->getDeserializeSizeLeft() < size) {
728 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
729 }
730
731 // otherwise, set destination buffer to data from deserialization pointer plus size
732 7523 U8* buffAddr = this->m_buffAddr;
733
734 7523 FW_ASSERT(buffAddr);
735 7523 SerializeStatus stat = dest.setBuff(&buffAddr[this->m_deserLoc], size);
736
1/2
✓ Branch 0 taken 7523 times.
✗ Branch 1 not taken.
7523 if (stat == FW_SERIALIZE_OK) {
737 7523 this->m_deserLoc += size;
738 }
739 7523 return stat;
740 }
741
742 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::copyRawOffset(SerialBufferBase& dest,
743 Serializable::SizeType size) {
744 // make sure there is sufficient size in destination
745 ✗ const Serializable::SizeType destCapacity = dest.getCapacity();
746 ✗ const Serializable::SizeType destSize = dest.getSize();
747 ✗ if (destCapacity < size + destSize) {
748 ✗ return FW_SERIALIZE_NO_ROOM_LEFT;
749 }
750 // make sure there is sufficient buffer in source
751 ✗ if (this->getDeserializeSizeLeft() < size) {
752 ✗ return FW_DESERIALIZE_SIZE_MISMATCH;
753 }
754
755 // otherwise, serialize bytes to destination without writing length
756 ✗ U8* buffAddr = this->m_buffAddr;
757 ✗ SerializeStatus stat = dest.serializeFrom(&buffAddr[this->m_deserLoc], size, Serialization::OMIT_LENGTH);
758 ✗ if (stat == FW_SERIALIZE_OK) {
759 ✗ this->m_deserLoc += size;
760 }
761 ✗ return stat;
762 }
763
764 // return address of buffer not yet deserialized. This is used
765 // to copy the remainder of a buffer.
766 1014157 const U8* LinearBufferBase::getBuffAddrLeft() const {
767 1014157 const U8* buffAddr = this->m_buffAddr;
768 1014157 FW_ASSERT(buffAddr != nullptr);
769 1014157 return &buffAddr[this->m_deserLoc];
770 }
771
772 //!< gets address of end of serialization. Used to manually place data at the end
773 89339 U8* LinearBufferBase::getBuffAddrSer() {
774 89339 U8* buffAddr = this->m_buffAddr;
775 89339 FW_ASSERT(buffAddr != nullptr);
776 89339 return &buffAddr[this->m_serLoc];
777 }
778
779 #ifdef BUILD_UT
780 183 bool LinearBufferBase::operator==(const LinearBufferBase& other) const {
781
1/2
✗ Branch 11 not taken.
✓ Branch 12 taken 183 times.
183 if (this->m_serLoc != other.getSize()) {
782 ✗ return false;
783 }
784
785 183 const U8* us = this->m_buffAddr;
786 183 const U8* them = other.getBuffAddr();
787
788 183 FW_ASSERT(us);
789 183 FW_ASSERT(them);
790
791
2/2
✓ Branch 4 taken 4938 times.
✓ Branch 5 taken 183 times.
5121 for (Serializable::SizeType byte = 0; byte < this->m_serLoc; byte++) {
792
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4938 times.
4938 if (us[byte] != them[byte]) {
793 ✗ return false;
794 }
795 }
796
797 183 return true;
798 }
799
800 ✗ std::ostream& operator<<(std::ostream& os, const LinearBufferBase& buff) {
801 ✗ const U8* us = buff.getBuffAddr();
802
803 ✗ FW_ASSERT(us);
804
805 ✗ for (Serializable::SizeType byte = 0; byte < buff.getSize(); byte++) {
806 ✗ os << "[" << std::setw(2) << std::hex << std::setfill('0') << us[byte] << "]" << std::dec;
807 }
808
809 ✗ return os;
810 }
811 #endif
812
813 294780 ExternalSerializeBuffer::ExternalSerializeBuffer(U8* buffPtr, Serializable::SizeType size)
814 294780 : LinearBufferBase(nullptr, 0) {
815
1/1
✓ Branch 4 taken 294780 times.
294780 this->setExtBuffer(buffPtr, size);
816 294780 }
817
818 2069051 ExternalSerializeBuffer::ExternalSerializeBuffer() : LinearBufferBase(nullptr, 0) {
819
1/1
✓ Branch 4 taken 2069051 times.
2069051 this->clear();
820 2069051 }
821
822 2691155 void ExternalSerializeBuffer::setExtBuffer(U8* buffPtr, Serializable::SizeType size) {
823 // Allow setting buffer with null pointer and zero size (for initialization/reset)
824 // but reject null pointer with non-zero size
825 2691155 FW_ASSERT((buffPtr != nullptr) || (size == 0), static_cast<FwAssertArgType>(size));
826 2691155 this->clear();
827 2691155 this->setBuffAddrInternal(buffPtr);
828 2691155 this->setCapacityInternal(size);
829 2691155 }
830
831 4760303 void ExternalSerializeBuffer::clear() {
832 4760303 this->resetSer();
833 4760303 this->resetDeser();
834 4760303 this->setBuffAddrInternal(nullptr);
835 4760303 this->setCapacityInternal(0);
836 4760303 }
837
838 // ----------------------------------------------------------------------
839 // Deprecated method implementations for backward compatibility
840 // ----------------------------------------------------------------------
841
842 ✗ Serializable::SizeType LinearBufferBase::getBuffLength() const {
843 ✗ return this->m_serLoc;
844 }
845
846 ✗ Serializable::SizeType LinearBufferBase::getBuffLeft() {
847 ✗ return this->getDeserializeSizeLeft();
848 }
849
850 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U8 val) {
851 ✗ return this->serializeFrom(val);
852 }
853 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I8 val) {
854 ✗ return this->serializeFrom(val);
855 }
856 #if FW_HAS_16_BIT == 1
857 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U16 val) {
858 ✗ return this->serializeFrom(val);
859 }
860 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I16 val) {
861 ✗ return this->serializeFrom(val);
862 }
863 #endif
864 #if FW_HAS_32_BIT == 1
865 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U32 val) {
866 ✗ return this->serializeFrom(val);
867 }
868 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I32 val) {
869 ✗ return this->serializeFrom(val);
870 }
871 #endif
872 #if FW_HAS_64_BIT == 1
873 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(U64 val) {
874 ✗ return this->serializeFrom(val);
875 }
876 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(I64 val) {
877 ✗ return this->serializeFrom(val);
878 }
879 #endif
880 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(F32 val) {
881 ✗ return this->serializeFrom(val);
882 }
883 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(F64 val) {
884 ✗ return this->serializeFrom(val);
885 }
886 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(bool val) {
887 ✗ return this->serializeFrom(val);
888 }
889 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const void* val) {
890 ✗ return this->serializeFrom(val);
891 }
892
893 // Deprecated method for backward compatibility
894 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff,
895 FwSizeType length,
896 bool noLength) {
897 ✗ const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH;
898 ✗ return this->serializeFrom(buff, length, mode);
899 }
900
901 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff, FwSizeType length) {
902 ✗ return this->serializeFrom(buff, length);
903 }
904 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const U8* buff,
905 FwSizeType length,
906 Serialization::t mode) {
907 ✗ return this->serializeFrom(buff, length, mode);
908 }
909 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const Serializable& val) {
910 ✗ return this->serializeFrom(val);
911 }
912 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::serialize(const LinearBufferBase& val) {
913 ✗ return this->serializeFrom(val);
914 }
915
916 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8& val) {
917 ✗ return this->deserializeTo(val);
918 }
919 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I8& val) {
920 ✗ return this->deserializeTo(val);
921 }
922 #if FW_HAS_16_BIT == 1
923 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U16& val) {
924 ✗ return this->deserializeTo(val);
925 }
926 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I16& val) {
927 ✗ return this->deserializeTo(val);
928 }
929 #endif
930 #if FW_HAS_32_BIT == 1
931 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U32& val) {
932 ✗ return this->deserializeTo(val);
933 }
934 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I32& val) {
935 ✗ return this->deserializeTo(val);
936 }
937 #endif
938 #if FW_HAS_64_BIT == 1
939 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U64& val) {
940 ✗ return this->deserializeTo(val);
941 }
942 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(I64& val) {
943 ✗ return this->deserializeTo(val);
944 }
945 #endif
946 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(F32& val) {
947 ✗ return this->deserializeTo(val);
948 }
949 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(F64& val) {
950 ✗ return this->deserializeTo(val);
951 }
952 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(bool& val) {
953 ✗ return this->deserializeTo(val);
954 }
955 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(void*& val) {
956 ✗ return this->deserializeTo(val);
957 }
958
959 // Deprecated method for backward compatibility
960 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff,
961 FwSizeType& length,
962 bool noLength) {
963 ✗ const Serialization::t mode = noLength ? Serialization::OMIT_LENGTH : Serialization::INCLUDE_LENGTH;
964 ✗ return this->deserializeTo(buff, length, mode);
965 }
966
967 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff, FwSizeType& length) {
968 ✗ return this->deserializeTo(buff, length, Serialization::INCLUDE_LENGTH);
969 }
970
971 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(U8* buff,
972 FwSizeType& length,
973 Serialization::t mode) {
974 ✗ return this->deserializeTo(buff, length, mode);
975 }
976
977 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(Serializable& val) {
978 ✗ return this->deserializeTo(val);
979 }
980 ✗ FW_SERIALIZE_FORCE_INLINE_LBB SerializeStatus LinearBufferBase::deserialize(LinearBufferBase& val) {
981 ✗ return this->deserializeTo(val);
982 }
983
984 ✗ Serializable::SizeType ExternalSerializeBuffer::getBuffCapacity() const {
985 ✗ return this->getCapacity();
986 }
987
988 } // namespace Fw
989