Midnight Sun Firmware
Loading...
Searching...
No Matches
SerializationHelpers

Serialization helper library. More...

Functions

template<typename T >
void serializeInteger (std::string &target, T value)
 Serialize an integer value. More...
 
void serializeString (std::string &target, const std::string &str)
 Serialize a string value. More...
 
template<typename T >
deserializeInteger (const std::string &source, size_t &offset)
 Deserialize an integer value. More...
 
std::string deserializeString (std::string &source, size_t &offset)
 Deserialize a string value. More...
 

Detailed Description

Serialization helper library.

Function Documentation

◆ deserializeInteger()

T deserializeInteger ( const std::string &  source,
size_t &  offset 
)

Deserialize an integer value.

The offset will automatically be incremented in this function

Parameters
sourceMessage payload to be decoded
offsetByte offset from the start of the message payload
Returns
Deserialized integer value

◆ deserializeString()

std::string deserializeString ( std::string &  source,
size_t &  offset 
)

Deserialize a string value.

This will fetch the string value based on the stored length The offset will automatically be incremented in this function

Parameters
sourceMessage payload to be decoded
offsetByte offset from the start of the message payload
Returns
Deserialized string value

◆ serializeInteger()

void serializeInteger ( std::string &  target,
value 
)

Serialize an integer value.

The integer will be converted to a string of size T. Size T is dependent on the type of integer. The stringified-integer is appended to the target.

Parameters
targetExisting message payload
valueValue to be appended

◆ serializeString()

void serializeString ( std::string &  target,
const std::string &  str 
)

Serialize a string value.

The string will be pre-fixed with a 16-bit size to indicate the size The string is appended to the target. The final packet follows as such: | target | 16-bit length | str |

Parameters
targetExisting message payload
strString to be appended