20 #if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT 22 void Serializable::toString(
StringBase& text)
const {
29 std::ostream& operator<<(std::ostream& os,
const Serializable& val) {
44 this->m_serLoc = src.m_serLoc;
45 this->m_deserLoc = src.m_deserLoc;
64 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
76 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
80 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val);
86 #if FW_HAS_16_BIT == 1 88 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
93 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 8);
94 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val);
101 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
106 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 8);
107 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val);
109 this->m_deserLoc = 0;
113 #if FW_HAS_32_BIT == 1 115 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
120 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 24);
121 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 16);
122 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 8);
123 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val);
125 this->m_deserLoc = 0;
130 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
135 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 24);
136 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 16);
137 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 8);
138 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val);
140 this->m_deserLoc = 0;
145 #if FW_HAS_64_BIT == 1 147 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
152 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 56);
153 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 48);
154 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 40);
155 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val >> 32);
156 this->
getBuffAddr()[this->m_serLoc + 4] =
static_cast<U8>(val >> 24);
157 this->
getBuffAddr()[this->m_serLoc + 5] =
static_cast<U8>(val >> 16);
158 this->
getBuffAddr()[this->m_serLoc + 6] =
static_cast<U8>(val >> 8);
159 this->
getBuffAddr()[this->m_serLoc + 7] =
static_cast<U8>(val);
161 this->m_deserLoc = 0;
166 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getBuffCapacity()) {
171 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 56);
172 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 48);
173 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 40);
174 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val >> 32);
175 this->
getBuffAddr()[this->m_serLoc + 4] =
static_cast<U8>(val >> 24);
176 this->
getBuffAddr()[this->m_serLoc + 5] =
static_cast<U8>(val >> 16);
177 this->
getBuffAddr()[this->m_serLoc + 6] =
static_cast<U8>(val >> 8);
178 this->
getBuffAddr()[this->m_serLoc + 7] =
static_cast<U8>(val);
180 this->m_deserLoc = 0;
185 #if FW_HAS_F64 && FW_HAS_64_BIT 190 (void)memcpy(&u64Val, &val,
sizeof(val));
199 (void)memcpy(&u32Val, &val,
sizeof(val));
204 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(
U8)) - 1 >= this->
getBuffCapacity()) {
216 this->m_deserLoc = 0;
221 if (this->m_serLoc + static_cast<Serializable::SizeType>(
sizeof(
void*)) - 1 >= this->
getBuffCapacity()) {
225 return this->
serialize(reinterpret_cast<PlatformPointerCastType>(val));
233 return this->
serialize(buff, static_cast<FwSizeType>(length),
241 stat = this->
serialize(static_cast<FwSizeStoreType>(length));
253 (void)memcpy(&this->
getBuffAddr()[this->m_serLoc], buff,
static_cast<size_t>(length));
255 this->m_deserLoc = 0;
266 if (this->m_serLoc + size + static_cast<Serializable::SizeType>(
sizeof(
FwSizeStoreType)) >
281 this->m_serLoc += size;
282 this->m_deserLoc = 0;
293 status = this->
serialize(static_cast<FwSizeStoreType>(size));
304 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
318 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
323 val =
static_cast<I8>(this->
getBuffAddr()[this->m_deserLoc + 0]);
328 #if FW_HAS_16_BIT == 1 333 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
339 val =
static_cast<U16
>(((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
340 ((this->
getBuffAddr()[this->m_deserLoc + 0]) << 8));
349 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
355 val =
static_cast<I16
>(((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
356 ((this->
getBuffAddr()[this->m_deserLoc + 0]) << 8));
361 #if FW_HAS_32_BIT == 1 366 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
372 val = (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 0) |
373 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 8) |
374 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 16) |
375 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 24);
384 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
390 val = (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 0) |
391 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 8) |
392 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 16) |
393 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 24);
399 #if FW_HAS_64_BIT == 1 405 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
411 val = (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 7]) << 0) |
412 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 6]) << 8) |
413 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 5]) << 16) |
414 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 4]) << 24) |
415 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 32) |
416 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 40) |
417 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 48) |
418 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 56);
428 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
434 val = (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 7]) << 0) |
435 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 6]) << 8) |
436 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 5]) << 16) |
437 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 4]) << 24) |
438 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 32) |
439 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 40) |
440 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 48) |
441 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 56);
457 (void)memcpy(&val, &tempVal,
sizeof(val));
468 }
else if (this->
getBuffLength() - this->m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(
U8))) {
487 PlatformPointerCastType pointerCastVal = 0;
490 val =
reinterpret_cast<void*
>(pointerCastVal);
502 (void)memcpy(&val, &tempVal,
sizeof(val));
535 if ((storedLength > this->
getBuffLeft()) or (storedLength > length)) {
539 (void)memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc],
static_cast<size_t>(storedLength));
541 length =
static_cast<FwSizeType>(storedLength);
549 (void)memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc],
static_cast<size_t>(length));
579 (void)memcpy(val.
getBuffAddr(), &this->
getBuffAddr()[this->m_deserLoc],
static_cast<size_t>(storedLength));
587 this->m_deserLoc += storedLength;
602 this->m_deserLoc = 0;
607 this->m_deserLoc = 0;
613 const FwSizeType newSerLoc = this->m_serLoc + numBytesToSkip;
628 }
else if (this->
getBuffLength() - this->m_deserLoc < numBytesToSkip) {
650 return this->m_serLoc;
659 (void)memcpy(this->
getBuffAddr(), src,
static_cast<size_t>(length));
660 this->m_serLoc = length;
661 this->m_deserLoc = 0;
670 this->m_serLoc = length;
671 this->m_deserLoc = 0;
677 FW_ASSERT(this->m_serLoc >= this->m_deserLoc, static_cast<FwAssertArgType>(this->m_serLoc),
678 static_cast<FwAssertArgType>(this->m_deserLoc));
679 return this->m_serLoc - this->m_deserLoc;
690 this->m_deserLoc += size;
708 this->m_deserLoc += size;
737 if (us[byte] != them[byte]) {
745 std::ostream& operator<<(std::ostream& os,
const SerializeBufferBase& buff) {
746 const U8* us = buff.getBuffAddr();
751 os <<
"[" << std::setw(2) << std::hex << std::setfill(
'0') << us[byte] <<
"]" << std::dec;
Serialization/Deserialization operation was successful.
PlatformAssertArgType FwAssertArgType
void clear()
clear external buffer
SerializeBufferBase()
default constructor
Deserialization buffer was empty when trying to read more data.
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeStatus copyRaw(SerializeBufferBase &dest, Serializable::SizeType size)
directly copies buffer without looking for a size in the stream.
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
int8_t I8
8-bit signed integer
PlatformSizeType FwSizeType
No room left in the buffer to serialize data.
Serializable::SizeType m_buffSize
size of external buffer
virtual ~SerializeBufferBase()
destructor
Deserialization data had incorrect values (unexpected data types)
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
ExternalSerializeBuffer()
default constructor
SerializeStatus
forward declaration for string
float F32
32-bit floating point
Serializable::SizeType getBuffLength() const
returns current buffer size
Serializable::SizeType getBuffLeft() const
returns how much deserialization buffer is left
Include length as first token in serialization.
Data was the wrong format (e.g. wrong packet type)
#define FW_SERIALIZE_FALSE_VALUE
Value encoded during serialization for boolean false.
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const =0
serialize contents
U8 * m_buff
pointer to external buffer
SerializeStatus serializeSize(const FwSizeType size)
serialize a size value
Data was left in the buffer, but not enough to deserialize.
SerializeStatus deserializeSize(FwSizeType &size)
deserialize a size value
Serializable()
Default constructor.
void resetDeser()
reset deserialization to beginning
SerializeStatus copyRawOffset(SerializeBufferBase &dest, Serializable::SizeType size)
directly copies buffer without looking for a size in the stream.
#define FW_SERIALIZE_TRUE_VALUE
Value encoded during serialization for boolean true.
SerializeStatus moveDeserToOffset(FwSizeType offset)
Moves deserialization to the specified offset.
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)=0
deserialize to contents
SerializeStatus moveSerToOffset(FwSizeType offset)
Moves serialization to the specified offset.
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
virtual Serializable::SizeType getBuffCapacity() const =0
returns capacity, not current size, of buffer
SerializeStatus deserializeSkip(FwSizeType numBytesToSkip)
Skips the number of specified bytes for deserialization.
static U32 min(const U32 a, const U32 b)
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
Omit length from serialization.
virtual ~Serializable()
destructor
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeBufferBase & operator=(const SerializeBufferBase &src)
copy assignment operator
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length)
sets buffer contents and size
Serializable::SizeType getBuffCapacity() const
returns capacity, not current size, of buffer
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
SerializeStatus serializeSkip(FwSizeType numBytesToSkip)
Skips the number of specified bytes for serialization.
U8 * getBuffAddr()
gets buffer address for data filling
SerializeStatus setBuffLen(Serializable::SizeType length)
sets buffer length manually after filling with data