21 #if FW_SERIALIZABLE_TO_STRING || FW_ENABLE_TEXT_LOGGING || BUILD_UT 23 void Serializable::toString(
StringBase& text)
const {
30 std::ostream& operator<<(std::ostream& os,
const Serializable& val) {
53 static_cast<FwAssertArgType>(this->
getSize()));
67 if (this->
m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getCapacity()) {
82 #if FW_HAS_16_BIT == 1 84 if (this->
m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getCapacity()) {
112 #if FW_HAS_32_BIT == 1 114 if (this->
m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getCapacity()) {
147 #if FW_HAS_64_BIT == 1 149 if (this->
m_serLoc + static_cast<Serializable::SizeType>(
sizeof(val)) - 1 >= this->
getCapacity()) {
193 (void)memcpy(&u64Val, &val,
sizeof(val));
200 (void)memcpy(&u32Val, &val,
sizeof(val));
222 if (this->
m_serLoc + static_cast<Serializable::SizeType>(
sizeof(
void*)) - 1 >= this->
getCapacity()) {
226 return this->
serializeFrom(reinterpret_cast<PlatformPointerCastType>(val), mode);
239 stat = this->
serializeFrom(static_cast<FwSizeStoreType>(length), endianMode);
290 status = this->
serializeFrom(static_cast<FwSizeStoreType>(size), mode);
301 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
315 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
325 #if FW_HAS_16_BIT == 1 330 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
358 val =
static_cast<I16
>(unsignVal);
363 #if FW_HAS_32_BIT == 1 368 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
400 val =
static_cast<I32
>(unsignVal);
406 #if FW_HAS_64_BIT == 1 412 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(val))) {
452 val =
static_cast<I64
>(unsignVal);
466 (void)memcpy(&val, &tempVal,
sizeof(val));
475 }
else if (this->
getSize() - this->
m_deserLoc < static_cast<Serializable::SizeType>(
sizeof(
U8))) {
494 PlatformPointerCastType pointerCastVal = 0;
497 val =
reinterpret_cast<void*
>(pointerCastVal);
509 (void)memcpy(&val, &tempVal,
sizeof(val));
543 length =
static_cast<FwSizeType>(storedLength);
661 (void)memcpy(this->
getBuffAddr(), src,
static_cast<size_t>(length));
680 static_cast<FwAssertArgType>(this->
m_deserLoc));
749 if (us[byte] != them[byte]) {
757 std::ostream& operator<<(std::ostream& os,
const LinearBufferBase& buff) {
758 const U8* us = buff.getBuffAddr();
763 os <<
"[" << std::setw(2) << std::hex << std::setfill(
'0') << us[byte] <<
"]" << std::dec;
822 #if FW_HAS_16_BIT == 1 830 #if FW_HAS_32_BIT == 1 838 #if FW_HAS_64_BIT == 1 874 SerializeStatus LinearBufferBase::serialize(
const LinearBufferBase& val) {
884 #if FW_HAS_16_BIT == 1 892 #if FW_HAS_32_BIT == 1 900 #if FW_HAS_64_BIT == 1 Serialization/Deserialization operation was successful.
void clear()
Clear external buffer.
void copyFrom(const LinearBufferBase &src)
Copy data from source buffer.
virtual Serializable::SizeType getCapacity() const =0
Get buffer capacity.
Deserialization buffer was empty when trying to read more data.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
PlatformSizeType FwSizeType
SerializeStatus deserializeSize(FwSizeType &size, Endianness mode=Endianness::BIG) override
Deserialize a size value.
virtual SerializeStatus serializeTo(SerialBufferBase &buffer, Endianness mode=Endianness::BIG) const =0
Serialize the contents of this object to a buffer.
const U8 * getBuffAddrLeft() const
Get address of remaining non-deserialized data.
Serializable::SizeType getSize() const override
Get current buffer size.
Serializable::SizeType m_deserLoc
current offset for deserialization
int8_t I8
8-bit signed integer
No room left in the buffer to serialize data.
virtual U8 * getBuffAddr()=0
Get buffer address for data filling (non-const version)
Serializable::SizeType m_buffSize
size of external buffer
virtual SerializeStatus deserializeFrom(SerialBufferBase &buffer, Endianness mode=Endianness::BIG)=0
Deserialize the contents of this object from a buffer.
LinearBufferBase & operator=(const LinearBufferBase &src)
Copy assignment operator.
Deserialization data had incorrect values (unexpected data types)
SerializeStatus serializeSkip(FwSizeType numBytesToSkip) override
Skip specified number of bytes during serialization.
SerializeStatus copyRaw(SerialBufferBase &dest, Serializable::SizeType size) override
Copy raw bytes from this buffer to destination and advance source offset.
virtual SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG)=0
Serialize an 8-bit unsigned integer value.
SerializeStatus copyRawOffset(SerialBufferBase &dest, Serializable::SizeType size) override
Append raw bytes to destination from this buffer and advance source offset.
SerializeStatus serializeSize(const FwSizeType size, Endianness mode=Endianness::BIG) override
Serialize a size value.
ExternalSerializeBuffer()
Default constructor.
SerializeStatus
forward declaration for string
float F32
32-bit floating point
SerializeStatus deserializeSkip(FwSizeType numBytesToSkip) override
Skip specified number of bytes during deserialization.
U16 FwSizeStoreType
The type used to serialize a size value.
LinearBufferBase()
Default constructor.
virtual ~SerialBufferBase()
Virtual destructor.
Serializable::SizeType getCapacity() const
Get buffer capacity.
Data was the wrong format (e.g. wrong packet type)
U8 * m_buff
pointer to external buffer
Omit length from serialization.
Serializable::SizeType m_serLoc
current offset in buffer of serialized data
Data was left in the buffer, but not enough to deserialize.
Serializable::SizeType getDeserializeSizeLeft() const override
Get remaining deserialization buffer size.
Serializable()
Default constructor.
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length) override
Set buffer contents from external source.
void resetDeser() override
Reset deserialization pointer to beginning of buffer.
void resetSer() override
Reset serialization pointer to beginning of buffer.
Serializable::SizeType getCapacity() const override=0
Get buffer capacity.
virtual SerializeStatus setBuff(const U8 *src, Serializable::SizeType length)=0
Set buffer contents from external source.
uint8_t U8
8-bit unsigned integer
SerializeStatus moveSerToOffset(FwSizeType offset) override
Move serialization pointer to specified offset.
static U32 min(const U32 a, const U32 b)
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
Set the external buffer.
virtual ~Serializable()
Virtual destructor.
SerializeStatus moveDeserToOffset(FwSizeType offset) override
Move deserialization pointer to specified offset.
double F64
64-bit floating point (double). Required for compiler-supplied double promotion.
Include length as first token in serialization.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
Little endian serialization.
SerializeStatus setBuffLen(Serializable::SizeType length) override
Set buffer length manually.
Implementation of malloc based allocator.
virtual Serializable::SizeType getSize() const =0
Get current buffer size.
Serializable::SizeType getSerializeSizeLeft() const override
Get remaining serialization buffer size.
U8 * getBuffAddrSer()
Get address of end of serialization (DANGEROUS!)
virtual ~LinearBufferBase()
Destructor.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
Big endian serialization.
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)