Byte Array Serialization
Public Member Functions | List of all members
bas::SerializedObject Class Reference

The SerializedObject contains and manages the payload of your serializations. More...

#include <bas.hpp>

Public Member Functions

 SerializedObject ()
 
 SerializedObject (const char *data)
 Construct object from payload. More...
 
 SerializedObject (const SerializedObject &other)
 Copy-construct object from another SerializedObject. More...
 
 ~SerializedObject ()=default
 Default destructor. More...
 
template<typename T >
void pushData (const T &data)
 Pushes data into the payload. More...
 
template<typename T >
void pushData (const T *data, size_t array_size)
 Pushes an array of data into the object payload. More...
 
template<typename T >
popData (void)
 Pop the next data in the payload. More...
 
template<typename T >
PoppedArray< T > popDataArray (void)
 Pop the next array in the payload and returns a PoppedArray. More...
 
const char * payload (void) const
 Returns a pointer to the payload of the object. More...
 
std::vector< char > & vector (void)
 Returns a reference to the std::vector containing the payload. More...
 
size_t size (void) const
 Returns the size of the payload in Bytes. More...
 
void clear ()
 Clear the SerializedObject and resets it to its default values. More...
 
SerializedObjectoperator= (const SerializedObject &other)
 Assign values to the SerializedObject. More...
 
SerializedObjectoperator= (const char *data)
 Assign a copy of data to the payload. More...
 
void removeChecksum (void)
 Remove Checksum at the beggining of payload. More...
 
void addChecksum (void)
 Add Checksum at the beggining of payload. More...
 

Detailed Description

The SerializedObject contains and manages the payload of your serializations.

This class is the result of a Serializable::serialization.

Examples
intrication.cpp, pushpoparray.cpp, pushpopsimple.cpp, and serialization.cpp.

Constructor & Destructor Documentation

◆ SerializedObject() [1/3]

bas::SerializedObject::SerializedObject ( )
inline

◆ SerializedObject() [2/3]

bas::SerializedObject::SerializedObject ( const char *  data)
inline

Construct object from payload.

This operation makes a copy of data.

Parameters
datapayload the SerializedObject will be assigned.

◆ SerializedObject() [3/3]

bas::SerializedObject::SerializedObject ( const SerializedObject other)
inline

Copy-construct object from another SerializedObject.

Parameters
otherThe SerializedObject to be copied from.

◆ ~SerializedObject()

bas::SerializedObject::~SerializedObject ( )
default

Default destructor.

Member Function Documentation

◆ addChecksum()

void bas::SerializedObject::addChecksum ( void  )
inline

Add Checksum at the beggining of payload.

If checksum has already been added, nothing is done.
This function should not be used by user end, except for extremely rare case.

◆ clear()

void bas::SerializedObject::clear ( )
inline

Clear the SerializedObject and resets it to its default values.

◆ operator=() [1/2]

SerializedObject& bas::SerializedObject::operator= ( const SerializedObject other)
inline

Assign values to the SerializedObject.

Parameters
otherSerializedObject to be copied from

◆ operator=() [2/2]

SerializedObject& bas::SerializedObject::operator= ( const char *  data)
inline

Assign a copy of data to the payload.

This function erase the current payload.
If data is not a payload extracted with SerializedObject::payload(), behaviour might be undefined.

Parameters
datapayload the SerializedObject will be assigned.

◆ payload()

const char* bas::SerializedObject::payload ( void  ) const
inline

Returns a pointer to the payload of the object.

This function is the go-to to get the 'finished product' of your serialization.

Returns
Pointer to the payload of the SerializedObject

◆ popData()

template<typename T >
T bas::SerializedObject::popData ( void  )
inline

Pop the next data in the payload.

Returns
The popped value from the payload.
Examples
intrication.cpp, pushpopsimple.cpp, and serialization.cpp.

◆ popDataArray()

template<typename T >
PoppedArray<T> bas::SerializedObject::popDataArray ( void  )
inline

Pop the next array in the payload and returns a PoppedArray.

The PoppedArray contains the popped data along with the size of the popped data.

See also
PoppedArray
Examples
pushpoparray.cpp.

◆ pushData() [1/2]

template<typename T >
void bas::SerializedObject::pushData ( const T &  data)
inline

Pushes data into the payload.

To retreive data pushed by this variant of pushData(), use popData<T>() where T is the type of the data pushed.

Parameters
dataData to be pushed.
See also
popData<>()
Examples
intrication.cpp, pushpoparray.cpp, pushpopsimple.cpp, and serialization.cpp.

◆ pushData() [2/2]

template<typename T >
void bas::SerializedObject::pushData ( const T *  data,
size_t  array_size 
)
inline

Pushes an array of data into the object payload.

To retreive data pushed by this variant of pushData(), use popDataArray<T>() where T is the type of the data pushed.

Parameters
dataA pointer to the data to be pushed.
array_sizeThe size of the array to be pushed.
See also
popDataArray<>()

◆ removeChecksum()

void bas::SerializedObject::removeChecksum ( void  )
inline

Remove Checksum at the beggining of payload.

If checksum has already been removed, nothing is done.
This function should not be used by user end, except for extremely rare case.

◆ size()

size_t bas::SerializedObject::size ( void  ) const
inline

Returns the size of the payload in Bytes.

This size include all the metadata that is added by the SerializedObject to the payload.

Returns
The size of the payload.

◆ vector()

std::vector<char>& bas::SerializedObject::vector ( void  )
inline

Returns a reference to the std::vector containing the payload.

User-end should use this function only in rare case, manually modifying the payload may end up in undefined behaviours.


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