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;
80 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val);
86 #if FW_HAS_16_BIT == 1
93 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 8);
94 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val);
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
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;
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
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;
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));
216 this->m_deserLoc = 0;
253 (void)memcpy(&this->
getBuffAddr()[this->m_serLoc], buff, length);
255 this->m_deserLoc = 0;
281 this->m_serLoc += size;
282 this->m_deserLoc = 0;
323 val =
static_cast<I8>(this->
getBuffAddr()[this->m_deserLoc + 0]);
328 #if FW_HAS_16_BIT == 1
339 val =
static_cast<U16
>(((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
340 ((this->
getBuffAddr()[this->m_deserLoc + 0]) << 8));
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
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);
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
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);
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));
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], storedLength);
541 length =
static_cast<FwSizeType>(storedLength);
549 (void)memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc], length);
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;
660 this->m_serLoc = length;
661 this->m_deserLoc = 0;
670 this->m_serLoc = length;
671 this->m_deserLoc = 0;
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;
PlatformPointerCastType POINTER_CAST
int8_t I8
8-bit signed integer
float F32
32-bit floating point
uint8_t U8
8-bit unsigned integer
static U32 min(const U32 a, const U32 b)
uint8_t PlatformPointerCastType
PlatformAssertArgType FwAssertArgType
#define FW_SERIALIZE_TRUE_VALUE
Value encoded during serialization for boolean true.
#define FW_SERIALIZE_FALSE_VALUE
Value encoded during serialization for boolean false.
PlatformSizeType FwSizeType
C++-compatible configuration header for fprime configuration.
U8 * getBuffAddr()
gets buffer address for data filling
Serializable::SizeType getBuffCapacity() const
returns capacity, not current size, of buffer
U8 * m_buff
pointer to external buffer
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
void clear()
clear external buffer
ExternalSerializeBuffer()
default constructor
Serializable::SizeType m_buffSize
size of external buffer
NATIVE_UINT_TYPE SizeType
Serializable()
Default constructor.
virtual ~Serializable()
destructor
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)=0
deserialize to contents
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const =0
serialize contents
@ OMIT_LENGTH
Omit length from serialization.
@ INCLUDE_LENGTH
Include length as first token in serialization.
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
SerializeStatus deserializeSize(FwSizeType &size)
deserialize a size value
SerializeStatus setBuffLen(Serializable::SizeType length)
sets buffer length manually after filling with data
void resetDeser()
reset deserialization to beginning
SerializeStatus moveDeserToOffset(FwSizeType offset)
Moves deserialization to the specified offset.
Serializable::SizeType getBuffLeft() const
returns how much deserialization buffer is left
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeStatus serializeSkip(FwSizeType numBytesToSkip)
Skips the number of specified bytes for serialization.
SerializeStatus moveSerToOffset(FwSizeType offset)
Moves serialization to the specified offset.
SerializeBufferBase()
default constructor
Serializable::SizeType getBuffLength() const
returns current buffer size
SerializeBufferBase & operator=(const SerializeBufferBase &src)
copy assignment operator
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length)
sets buffer contents and size
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
virtual ~SerializeBufferBase()
destructor
SerializeStatus deserializeSkip(FwSizeType numBytesToSkip)
Skips the number of specified bytes for deserialization.
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
SerializeStatus copyRawOffset(SerializeBufferBase &dest, Serializable::SizeType size)
directly copies buffer without looking for a size in the stream.
virtual Serializable::SizeType getBuffCapacity() const =0
returns capacity, not current size, of buffer
SerializeStatus serializeSize(const FwSizeType size)
serialize a size value
SerializeStatus
forward declaration for string
@ FW_DESERIALIZE_FORMAT_ERROR
Deserialization data had incorrect values (unexpected data types)
@ FW_DESERIALIZE_BUFFER_EMPTY
Deserialization buffer was empty when trying to read more data.
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_SERIALIZE_FORMAT_ERROR
Data was the wrong format (e.g. wrong packet type)
@ FW_DESERIALIZE_SIZE_MISMATCH
Data was left in the buffer, but not enough to deserialize.
@ FW_SERIALIZE_NO_ROOM_LEFT
No room left in the buffer to serialize data.