22#if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || 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;
189#if FW_HAS_F64 && FW_HAS_64_BIT
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;
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);
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;
PlatformPointerCastType POINTER_CAST
int8_t I8
8-bit signed integer
float F32
32-bit floating point
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
#define FW_SERIALIZE_TRUE_VALUE
Value encoded during serialization for boolean true.
#define FW_SERIALIZE_FALSE_VALUE
Value encoded during serialization for boolean false.
C++-compatible configuration header for fprime configuration.
Declares ISF string base class.
NATIVE_UINT_TYPE getBuffCapacity() const
returns capacity, not current size, of buffer
U8 * getBuffAddr()
gets buffer address for data filling
void setExtBuffer(U8 *buffPtr, NATIVE_UINT_TYPE size)
Set the external buffer.
void clear()
clear external buffer
ExternalSerializeBuffer()
default constructor
Serializable()
Default constructor.
virtual ~Serializable()
destructor
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)=0
deserialize to contents
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const =0
serialize contents
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
void resetDeser()
reset deserialization to beginning
SerializeStatus setBuffLen(NATIVE_UINT_TYPE length)
sets buffer length manually after filling with data
const U8 * getBuffAddrLeft() const
gets address of remaining non-deserialized data.
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeBufferBase()
default constructor
SerializeStatus setBuff(const U8 *src, NATIVE_UINT_TYPE length)
sets buffer contents and size
SerializeStatus deserializeSkip(NATIVE_UINT_TYPE numBytesToSkip)
Skips the number of specified bytes for deserialization.
SerializeBufferBase & operator=(const SerializeBufferBase &src)
equal operator
virtual NATIVE_UINT_TYPE getBuffCapacity() const =0
returns capacity, not current size, of buffer
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
virtual ~SerializeBufferBase()
destructor
U8 * getBuffAddrSer()
gets address of end of serialization. DANGEROUS! Need to know max buffer size and adjust when done
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
SerializeStatus copyRawOffset(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
SerializeStatus copyRaw(SerializeBufferBase &dest, NATIVE_UINT_TYPE size)
directly copies buffer without looking for a size in the stream.
virtual U8 * getBuffAddr()=0
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
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_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.