Template Class serializer#

Class Documentation#

template<sdv::EEndian eTargetEndianess = GetPlatformEndianess(), typename TCRC = crcCCITT_FALSE>
class serializer#

Serializer class implementing the serialization of basic types and memory management.

The serialization into the buffer is aligned to the size of the value to store. For example, bytes can be stored at any position. 16-bit words can be stored at 2 bytes boundary. 32-bits can be stored at 4 bytes boundary and 64-bits can be stored at 8 bytes boundary. The buffer allocation occurs in 1024 bytes at the time. The buffer is readjusted to the correct size just before detaching the buffer.

Template Parameters:
  • eTargetEndianess – The targeendiannessss determines whether to swap the bytes before storing them into the buffer.

  • TCRC – The CRC type to use for the checksum calculation.

Public Functions

serializer() noexcept#

Constructor.

template<typename T>
void push_back(T tValue)#

Push value into the serializer.

Template Parameters:

T – Type of the value. Only arithmic and boolean types can be added. All other types need to be decomposed before they can be added.

Parameters:

tValue[in] The value to add.

void attach(pointer<uint8_t> &&rptrBuffer, size_t nOffset = 0, typename TCRC::TCRCType uiChecksum = 0u)#

Attach a buffer to serialize into.

Parameters:
  • rptrBuffer[in] Reference to the buffer.

  • nOffset[in] Offset to start serializing.

  • uiChecksum[in] Current checksum value to continue with in the CRC calculation.

void detach(pointer<uint8_t> &rptrBuffer)#

Detach the internal buffer and assign this buffer to the supplied pointer.

Parameters:

rptrBuffer[out] Reference to the pointer to assign this buffer to.

void reserve(size_t nSize)#

Reserve space for a large amount of data.

Reserving space for data is done automatically, but only in small chunks. If large data is serialized, it is more efficient to reserve the space at once before the serialization process takes place. This will prevent many smaller reallocations taking place.

Parameters:

nSize[in] The size of new data to reserve space for.

pointer<uint8_t> buffer() const#

Get a copy of the buffer pointer.

Returns:

Smart pointer to the contained buffer.

TCRC::TCRCType checksum() const noexcept#

Return the calculated checksum value of the serialized data.

Returns:

Checksum value.

size_t offset() const#

Return the current offset.

Returns:

The offset from the start of the stream.