22 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
24 void Serializable::toString(
StringBase& text)
const {
31 std::ostream& operator<<(std::ostream& os,
const Serializable& val) {
42 m_serLoc(0), m_deserLoc(0) {
49 this->m_serLoc = src.m_serLoc;
50 this->m_deserLoc = src.m_deserLoc;
73 this->m_serLoc +=
sizeof(val);
84 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val);
85 this->m_serLoc +=
sizeof(val);
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;
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;
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;
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;
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;
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;
194 (void) memcpy(&u64Val, &val,
sizeof(val));
205 (void) memcpy(&u32Val, &val,
sizeof(val));
222 this->m_serLoc +=
sizeof(
U8);
223 this->m_deserLoc = 0;
233 return this->
serialize(
reinterpret_cast<POINTER_CAST
>(val));
253 (void) memcpy(&this->
getBuffAddr()[this->m_serLoc], buff, length);
254 this->m_serLoc += length;
255 this->m_deserLoc = 0;
282 this->m_serLoc += size;
283 this->m_deserLoc = 0;
300 this->m_deserLoc +=
sizeof(val);
313 val =
static_cast<I8>(this->
getBuffAddr()[this->m_deserLoc + 0]);
314 this->m_deserLoc +=
sizeof(val);
329 val =
static_cast<U16
>(
330 ((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
333 this->m_deserLoc +=
sizeof(val);
347 val =
static_cast<I16
>(
348 ((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
351 this->m_deserLoc +=
sizeof(val);
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);
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);
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);
414 this->m_deserLoc +=
sizeof(val);
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);
452 (void) memcpy(&val, &tempVal,
sizeof(val));
476 this->m_deserLoc +=
sizeof(
U8);
481 return this->
deserialize(
reinterpret_cast<POINTER_CAST&
>(val));
491 (void) memcpy(&val, &tempVal,
sizeof(val));
510 if ((storedLength > this->
getBuffLeft()) or (storedLength > length)) {
514 (void) memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc], storedLength);
524 (void) memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc], length);
527 this->m_deserLoc += length;
564 this->m_deserLoc += storedLength;
570 this->m_deserLoc = 0;
575 this->m_deserLoc = 0;
583 }
else if (this->
getBuffLength() - this->m_deserLoc < numBytesToSkip) {
587 this->m_deserLoc += numBytesToSkip;
592 return this->m_serLoc;
602 this->m_serLoc = length;
603 this->m_deserLoc = 0;
612 this->m_serLoc = length;
613 this->m_deserLoc = 0;
619 return this->m_serLoc - this->m_deserLoc;
630 this->m_deserLoc += size;
649 this->m_deserLoc += size;
679 if (us[
byte] != them[
byte]) {
687 std::ostream& operator<<(std::ostream& os,
const SerializeBufferBase& buff) {
689 const U8* us = buff.getBuffAddr();
694 os <<
"[" << std::setw(2) << std::hex << std::setfill(
'0') << us[byte] <<
"]" << std::dec;
711 this->m_buff = buffPtr;
712 this->m_buffSize = size;
716 this->m_buff =
nullptr;
717 this->m_buffSize = 0;
721 return this->m_buffSize;