Imt.Base C++ API V4.1.1.0
Loading...
Searching...
No Matches
imt::base::core::serialization::Serializer Class Referencefinal

Serializes various data types into the given byte buffer. More...

#include <Imt.Base.Core.Serialization/inc/Imt.Base.Core.Serialization/Serializer.h>

Inheritance diagram for imt::base::core::serialization::Serializer:
imt::base::core::platform::Nonmovable

Public Types

using AssertDebugFunctionPtr = void(*)(bool const condition, char_t const *const pMessage)
 Alias for ASSERT_DEBUG function pointer type (as raw function pointer)
 

Public Member Functions

 Serializer ()=delete
 
 Serializer (uint8_t buffer[], uint32_t const bufferSize) noexcept
 Constructor.
 
uint32_t getBufferPos () const
 Returns the write position within the byte buffer.
 
void setBufferPos (uint32_t const newPos)
 Sets the write position to the given position.
 
uint32_t getBufferSize () const
 Returns the size of the byte buffer in number of bytes.
 
uint8_t const * getBuffer () const
 Returns the pointer to the byte buffer.
 
uint32_t getUnusedBufferSize () const
 Returns the remaining data to write from the current position until the buffer is full.
 
bool isReset () const
 States if the serializer is reset (getBufferPos == 0).
 
uint8_t const & getBufferByte (uint32_t const indexOfByte) const
 Returns the byte of the byte buffer at the given index.
 
void reset ()
 Resets the Serializer.
 
bool hasOverflow () const
 Query if an overflow happend during serialization.
 
Serializeroperator<< (bool const data)
 Puts a bool into the Serializer.
 
Serializeroperator<< (uint8_t const data)
 Puts a uint8_t into the Serializer.
 
Serializeroperator<< (char_t const data)
 Puts a character into the Serializer.
 
Serializeroperator<< (char_t const *pData)
 Puts a null terminated string into the Serializer.
 
Serializeroperator<< (int8_t const data)
 Puts a int8_t into the Serializer.
 
Serializeroperator<< (uint16_t const data)
 Puts a uint16_t into the Serializer.
 
Serializeroperator<< (int16_t const data)
 Puts a int16_t into the Serializer.
 
Serializeroperator<< (uint32_t const data)
 Puts a uint32_t into the Serializer.
 
Serializeroperator<< (int32_t const data)
 Puts a int32_t into the Serializer.
 
Serializeroperator<< (uint64_t const data)
 Puts a uint64_t into the Serializer.
 
Serializeroperator<< (int64_t const data)
 Puts a int64_t into the Serializer.
 
Serializeroperator<< (float32_t const data)
 Puts a float into the Serializer.
 
Serializeroperator<< (float64_t const data)
 Puts a double into the Serializer.
 
SerializerpushData (void const *const pDataSrc, uint32_t const bytes)
 Puts data into the Serializer.
 
Serializeroperator<< (SerializableIfc const &data)
 Puts data into the Serializer.
 

Static Public Member Functions

static void setAssertDebugFunction (AssertDebugFunctionPtr const funcPtr)
 Set and replace the default assert-debug function.
 

Detailed Description

Serializes various data types into the given byte buffer.

The read position can be set to the beginning by calling reset. Important: The byte buffer passed with the constructor is storing the actual result.

Definition at line 58 of file Serializer.h.

Member Typedef Documentation

◆ AssertDebugFunctionPtr

using imt::base::core::serialization::Serializer::AssertDebugFunctionPtr = void (*)(bool const condition, char_t const* const pMessage)

Alias for ASSERT_DEBUG function pointer type (as raw function pointer)

Definition at line 262 of file Serializer.h.

Constructor & Destructor Documentation

◆ Serializer() [1/2]

imt::base::core::serialization::Serializer::Serializer ( )
delete

◆ Serializer() [2/2]

imt::base::core::serialization::Serializer::Serializer ( uint8_t  buffer[],
uint32_t const  bufferSize 
)
noexcept

Constructor.

Parameters
buffer[]Byte buffer array to where the data should be written. Must be valid (!= nullptr)!
bufferSizeSize of the byte buffer in number of bytes.

Member Function Documentation

◆ getBuffer()

uint8_t const * imt::base::core::serialization::Serializer::getBuffer ( ) const

Returns the pointer to the byte buffer.

Returns
Pointer to the write buffer.

◆ getBufferByte()

uint8_t const & imt::base::core::serialization::Serializer::getBufferByte ( uint32_t const  indexOfByte) const

Returns the byte of the byte buffer at the given index.

Note
If the given index is out of bounds, the value at the last position will be returned.
Parameters
indexOfByteIndex of the byte to return.
Returns
Byte at the given index of the buffer.

◆ getBufferPos()

uint32_t imt::base::core::serialization::Serializer::getBufferPos ( ) const

Returns the write position within the byte buffer.

Returns
Write position within the byte buffer.

◆ getBufferSize()

uint32_t imt::base::core::serialization::Serializer::getBufferSize ( ) const

Returns the size of the byte buffer in number of bytes.

Returns
Buffer size in bytes.

◆ getUnusedBufferSize()

uint32_t imt::base::core::serialization::Serializer::getUnusedBufferSize ( ) const

Returns the remaining data to write from the current position until the buffer is full.

Returns
Remaining buffer size in bytes.

◆ hasOverflow()

bool imt::base::core::serialization::Serializer::hasOverflow ( ) const

Query if an overflow happend during serialization.

Methods reset and setBufferPos (called with valid arguments) will reset the the overflow state to false.

Returns
True if in overflow state.

◆ isReset()

bool imt::base::core::serialization::Serializer::isReset ( ) const

States if the serializer is reset (getBufferPos == 0).

Returns
True if the write position is at the beginning.

◆ operator<<() [1/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( bool const  data)

Puts a bool into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [2/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( char_t const *  pData)

Puts a null terminated string into the Serializer.

Parameters
pDataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [3/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( char_t const  data)

Puts a character into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [4/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( float32_t const  data)

Puts a float into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [5/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( float64_t const  data)

Puts a double into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [6/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( int16_t const  data)

Puts a int16_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [7/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( int32_t const  data)

Puts a int32_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [8/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( int64_t const  data)

Puts a int64_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [9/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( int8_t const  data)

Puts a int8_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [10/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( SerializableIfc const &  data)

Puts data into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [11/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( uint16_t const  data)

Puts a uint16_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [12/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( uint32_t const  data)

Puts a uint32_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [13/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( uint64_t const  data)

Puts a uint64_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ operator<<() [14/14]

Serializer & imt::base::core::serialization::Serializer::operator<< ( uint8_t const  data)

Puts a uint8_t into the Serializer.

Parameters
dataData to put into the serializer.
Returns
Reference to this serializer.

◆ pushData()

Serializer & imt::base::core::serialization::Serializer::pushData ( void const *const  pDataSrc,
uint32_t const  bytes 
)

Puts data into the Serializer.

Parameters
pDataSrcPointer to the data source.
bytesNumber of bytes to put into the serializer.
Returns
Reference to this serializer.

◆ reset()

void imt::base::core::serialization::Serializer::reset ( )

Resets the Serializer.

◆ setAssertDebugFunction()

static void imt::base::core::serialization::Serializer::setAssertDebugFunction ( AssertDebugFunctionPtr const  funcPtr)
static

Set and replace the default assert-debug function.

Parameters
funcPtrThe function pointer to use for assert-debug checks

◆ setBufferPos()

void imt::base::core::serialization::Serializer::setBufferPos ( uint32_t const  newPos)

Sets the write position to the given position.

Parameters
newPosNew write position.

The documentation for this class was generated from the following file: