kmMqtt 0.0.1
MQTT Client Library
Loading...
Searching...
No Matches
kmMqtt::mqtt::BasePacket Class Referenceabstract

Base class for all MQTT packets. More...

#include <BasePacket.h>

Inheritance diagram for kmMqtt::mqtt::BasePacket:
kmMqtt::mqtt::Connect kmMqtt::mqtt::ConnectAck kmMqtt::mqtt::Disconnect kmMqtt::mqtt::PingReq kmMqtt::mqtt::PingResp kmMqtt::mqtt::Publish kmMqtt::mqtt::PublishAck kmMqtt::mqtt::PublishComp kmMqtt::mqtt::PublishRec kmMqtt::mqtt::PublishRel kmMqtt::mqtt::Subscribe kmMqtt::mqtt::SubscribeAck kmMqtt::mqtt::UnSubscribe kmMqtt::mqtt::UnSubscribeAck

Public Member Functions

virtual PacketType getPacketType () const noexcept=0
 Gets the packet type of the MQTT packet.
EncodeResult encode ()
 Encodes the MQTT packet into a ByteBuffer.
DecodeResult decode ()
 Decodes the MQTT packet from the internal data buffer.
const FixedHeadergetFixedHeader () const
 Gets the fixed header of the MQTT packet.
const ByteBuffergetDataBuffer () const
 Gets the data buffer of the MQTT packet.
ByteBuffer && extractDataBuffer () noexcept
 Extracts the data buffer, transferring ownership to the caller.

Protected Member Functions

std::size_t calculateFixedHeaderRemainingLength () const
 Calculates the remaining length for the fixed header based on other headers.
virtual void onFixedHeaderDecoded () const
 Callback invoked after the fixed header has been decoded.
void addEncodeHeader (const IEncodeHeader *header)
 Adds an encode header to the packet.
void addDecodeHeader (IDecodeHeader *header)
 Adds a decode header to the packet.

Detailed Description

Base class for all MQTT packets.

Provides common functionality for encoding and decoding packets, managing fixed headers, and handling data buffers.

Member Function Documentation

◆ addDecodeHeader()

void kmMqtt::mqtt::BasePacket::addDecodeHeader ( IDecodeHeader * header)
protected

Adds a decode header to the packet.

The base packet does not take ownership of the header. Addition order matters! These are decoded in the order they are added.

Parameters
headerPointer to the IDecodeHeader to add.

◆ addEncodeHeader()

void kmMqtt::mqtt::BasePacket::addEncodeHeader ( const IEncodeHeader * header)
protected

Adds an encode header to the packet.

The base packet does not take ownership of the header. Addition order matters! These are encoded in the order they are added.

Parameters
headerPointer to the IEncodeHeader to add.

◆ calculateFixedHeaderRemainingLength()

std::size_t kmMqtt::mqtt::BasePacket::calculateFixedHeaderRemainingLength ( ) const
protected

Calculates the remaining length for the fixed header based on other headers.

Returns
The calculated remaining length as a size_t.

◆ decode()

DecodeResult kmMqtt::mqtt::BasePacket::decode ( )

Decodes the MQTT packet from the internal data buffer.

Returns
A DecodeResult indicating success or failure of the decoding process.

◆ encode()

EncodeResult kmMqtt::mqtt::BasePacket::encode ( )

Encodes the MQTT packet into a ByteBuffer.

Returns
An EncodeResult indicating success or failure of the encoding process.

◆ extractDataBuffer()

ByteBuffer && kmMqtt::mqtt::BasePacket::extractDataBuffer ( )
noexcept

Extracts the data buffer, transferring ownership to the caller.

Returns
A ByteBuffer containing the packet data.

◆ getDataBuffer()

const ByteBuffer & kmMqtt::mqtt::BasePacket::getDataBuffer ( ) const

Gets the data buffer of the MQTT packet.

Returns
A constant reference to the ByteBuffer containing the packet data.

◆ getFixedHeader()

const FixedHeader & kmMqtt::mqtt::BasePacket::getFixedHeader ( ) const

Gets the fixed header of the MQTT packet.

Returns
A constant reference to the FixedHeader.

◆ getPacketType()

virtual PacketType kmMqtt::mqtt::BasePacket::getPacketType ( ) const
pure virtualnoexcept

◆ onFixedHeaderDecoded()

virtual void kmMqtt::mqtt::BasePacket::onFixedHeaderDecoded ( ) const
protectedvirtual

Callback invoked after the fixed header has been decoded.

Can be overridden by derived classes for additional processing thats required post fixed header decoding.

Reimplemented in kmMqtt::mqtt::Publish, kmMqtt::mqtt::PublishAck, kmMqtt::mqtt::PublishComp, kmMqtt::mqtt::PublishRec, and kmMqtt::mqtt::PublishRel.


The documentation for this class was generated from the following file:
  • D:/Dev/Repos/kmMqtt/include/public/kmMqtt/Mqtt/Packets/BasePacket.h