SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
SPSP::LocalLayers::ESPNOW::SerDes Class Reference

Serializer and deserializer of ESP-NOW packets. More...

#include <espnow_ser_des.hpp>

Public Member Functions

 SerDes (const Config &conf) noexcept
 Construct a new serializer/deserializer. More...
 
void serialize (const LocalMessageT &msg, std::string &data) const noexcept
 Serializes local message to raw data. More...
 
bool deserialize (const LocalAddrT &src, std::string &data, LocalMessageT &msg) const noexcept
 Deserializes raw data to local message. More...
 

Static Public Member Functions

static size_t getPacketLength (const LocalMessageT &msg) noexcept
 Calculates total packet length. More...
 

Protected Member Functions

void encryptRaw (uint8_t *data, size_t dataLen, const uint8_t *nonce) const noexcept
 Encryption provider for raw data (bytes) More...
 
bool validatePacketHeader (const Packet *p) const noexcept
 Validates packet's header. More...
 
bool decryptAndValidatePacketPayload (uint8_t *data, size_t dataLen) const noexcept
 Decrypts and validates packet's payload. More...
 

Static Protected Member Functions

static uint8_t checksumRaw (uint8_t *data, size_t dataLen, uint8_t existingChecksum=0) noexcept
 Checksums the given raw data (bytes) More...
 

Detailed Description

Serializer and deserializer of ESP-NOW packets.

Converts raw data to LocalMessage instances and back.

Definition at line 23 of file espnow_ser_des.hpp.

Constructor & Destructor Documentation

◆ SerDes()

SPSP::LocalLayers::ESPNOW::SerDes::SerDes ( const Config conf)
noexcept

Construct a new serializer/deserializer.

Parameters
confConfiguration

Member Function Documentation

◆ checksumRaw()

static uint8_t SPSP::LocalLayers::ESPNOW::SerDes::checksumRaw ( uint8_t *  data,
size_t  dataLen,
uint8_t  existingChecksum = 0 
)
staticprotectednoexcept

Checksums the given raw data (bytes)

Optionally subtracts existing checksum.

Parameters
dataData to encrypt/decrypt
dataLenLength of data
existingChecksumExisting checksum (to subtract)
Returns
Correct checksum

◆ decryptAndValidatePacketPayload()

bool SPSP::LocalLayers::ESPNOW::SerDes::decryptAndValidatePacketPayload ( uint8_t *  data,
size_t  dataLen 
) const
protectednoexcept

Decrypts and validates packet's payload.

Parameters
dataRaw packet data
dataLenLength of data
Returns
true Payload is valid
false Payload is invalid

◆ deserialize()

bool SPSP::LocalLayers::ESPNOW::SerDes::deserialize ( const LocalAddrT src,
std::string &  data,
LocalMessageT msg 
) const
noexcept

Deserializes raw data to local message.

Parameters
srcSource address
dataRaw data input
msgMessage output
Returns
true Deserialization successful
false Deserialization failed

◆ encryptRaw()

void SPSP::LocalLayers::ESPNOW::SerDes::encryptRaw ( uint8_t *  data,
size_t  dataLen,
const uint8_t *  nonce 
) const
protectednoexcept

Encryption provider for raw data (bytes)

Wraps ChaCha20 encryption. This function is used for both encryption and decryption. Data are encrypted/decrypted in-place.

Parameters
dataData to encrypt/decrypt
dataLenLength of data
nonceEncryption nonce

◆ getPacketLength()

static size_t SPSP::LocalLayers::ESPNOW::SerDes::getPacketLength ( const LocalMessageT msg)
staticnoexcept

Calculates total packet length.

Useful for checking whether packet size is within limits.

Parameters
msgMessage
Returns
Length

◆ serialize()

void SPSP::LocalLayers::ESPNOW::SerDes::serialize ( const LocalMessageT msg,
std::string &  data 
) const
noexcept

Serializes local message to raw data.

Total message length is not checked!

Parameters
msgMessage input
dataRaw data output

◆ validatePacketHeader()

bool SPSP::LocalLayers::ESPNOW::SerDes::validatePacketHeader ( const Packet p) const
protectednoexcept

Validates packet's header.

Parameters
pPacket
Returns
true Header is valid
false Header is invalid

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