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;
82 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val);
88 #if FW_HAS_16_BIT == 1
95 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 8);
96 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val);
108 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 8);
109 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val);
111 this->m_deserLoc = 0;
115 #if FW_HAS_32_BIT == 1
122 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 24);
123 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 16);
124 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 8);
125 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val);
127 this->m_deserLoc = 0;
137 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 24);
138 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 16);
139 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 8);
140 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val);
142 this->m_deserLoc = 0;
147 #if FW_HAS_64_BIT == 1
154 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 56);
155 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 48);
156 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 40);
157 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val >> 32);
158 this->
getBuffAddr()[this->m_serLoc + 4] =
static_cast<U8>(val >> 24);
159 this->
getBuffAddr()[this->m_serLoc + 5] =
static_cast<U8>(val >> 16);
160 this->
getBuffAddr()[this->m_serLoc + 6] =
static_cast<U8>(val >> 8);
161 this->
getBuffAddr()[this->m_serLoc + 7] =
static_cast<U8>(val);
163 this->m_deserLoc = 0;
173 this->
getBuffAddr()[this->m_serLoc + 0] =
static_cast<U8>(val >> 56);
174 this->
getBuffAddr()[this->m_serLoc + 1] =
static_cast<U8>(val >> 48);
175 this->
getBuffAddr()[this->m_serLoc + 2] =
static_cast<U8>(val >> 40);
176 this->
getBuffAddr()[this->m_serLoc + 3] =
static_cast<U8>(val >> 32);
177 this->
getBuffAddr()[this->m_serLoc + 4] =
static_cast<U8>(val >> 24);
178 this->
getBuffAddr()[this->m_serLoc + 5] =
static_cast<U8>(val >> 16);
179 this->
getBuffAddr()[this->m_serLoc + 6] =
static_cast<U8>(val >> 8);
180 this->
getBuffAddr()[this->m_serLoc + 7] =
static_cast<U8>(val);
182 this->m_deserLoc = 0;
187 #if FW_HAS_F64 && FW_HAS_64_BIT
192 (void)memcpy(&u64Val, &val,
sizeof(val));
201 (void)memcpy(&u32Val, &val,
sizeof(val));
218 this->m_deserLoc = 0;
255 (void)memcpy(&this->
getBuffAddr()[this->m_serLoc], buff, length);
257 this->m_deserLoc = 0;
283 this->m_serLoc += size;
284 this->m_deserLoc = 0;
325 val =
static_cast<I8>(this->
getBuffAddr()[this->m_deserLoc + 0]);
330 #if FW_HAS_16_BIT == 1
341 val =
static_cast<U16
>(((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
342 ((this->
getBuffAddr()[this->m_deserLoc + 0]) << 8));
357 val =
static_cast<I16
>(((this->
getBuffAddr()[this->m_deserLoc + 1]) << 0) |
358 ((this->
getBuffAddr()[this->m_deserLoc + 0]) << 8));
363 #if FW_HAS_32_BIT == 1
374 val = (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 0) |
375 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 8) |
376 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 16) |
377 (
static_cast<U32
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 24);
392 val = (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 0) |
393 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 8) |
394 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 16) |
395 (
static_cast<I32
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 24);
401 #if FW_HAS_64_BIT == 1
413 val = (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 7]) << 0) |
414 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 6]) << 8) |
415 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 5]) << 16) |
416 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 4]) << 24) |
417 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 32) |
418 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 40) |
419 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 48) |
420 (
static_cast<U64>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 56);
436 val = (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 7]) << 0) |
437 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 6]) << 8) |
438 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 5]) << 16) |
439 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 4]) << 24) |
440 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 3]) << 32) |
441 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 2]) << 40) |
442 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 1]) << 48) |
443 (
static_cast<I64
>(this->
getBuffAddr()[this->m_deserLoc + 0]) << 56);
459 (void)memcpy(&val, &tempVal,
sizeof(val));
492 val =
reinterpret_cast<void*
>(pointerCastVal);
504 (void)memcpy(&val, &tempVal,
sizeof(val));
537 if ((storedLength > this->
getBuffLeft()) or (storedLength > length)) {
541 (void)memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc], storedLength);
543 length =
static_cast<FwSizeType>(storedLength);
551 (void)memcpy(buff, &this->
getBuffAddr()[this->m_deserLoc], length);
589 this->m_deserLoc += storedLength;
604 this->m_deserLoc = 0;
609 this->m_deserLoc = 0;
615 const FwSizeType newSerLoc = this->m_serLoc + numBytesToSkip;
630 }
else if (this->
getBuffLength() - this->m_deserLoc < numBytesToSkip) {
652 return this->m_serLoc;
662 this->m_serLoc = length;
663 this->m_deserLoc = 0;
672 this->m_serLoc = length;
673 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)
Set the external buffer.
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.