AWS IoT C++ SDK
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes
awsiotsdk::mqtt::PublishPacket Class Reference

Publish Message Packet Type. More...

#include <Publish.hpp>

Inheritance diagram for awsiotsdk::mqtt::PublishPacket:
awsiotsdk::mqtt::Packet awsiotsdk::ActionData

Public Member Functions

 PublishPacket (const PublishPacket &)=delete
 
 PublishPacket (PublishPacket &&)=delete
 
PublishPacketoperator= (const PublishPacket &) &=delete
 
PublishPacketoperator= (PublishPacket &&) &=delete
 
 PublishPacket (std::unique_ptr< Utf8String > p_topic_name, bool is_retained, bool is_duplicate, QoS qos, const util::String &payload)
 Constructor, Individual data. More...
 
 PublishPacket (const util::Vector< unsigned char > &buf, bool is_retained, bool is_duplicate, QoS qos)
 Constructor, Deserializes data from buffer. More...
 
bool IsRetained ()
 Get the value of the Is Retained flag. More...
 
bool IsDuplicate ()
 Get the value of the Is Duplicate message flag. More...
 
util::String GetTopicName ()
 Get String containing topic name for this message. More...
 
util::String GetPayload ()
 Get string containing Payload. More...
 
size_t GetPayloadLen ()
 Get length of the payload. More...
 
util::String ToString ()
 Serialize this packet into a String. More...
 
QoS GetQoS ()
 
- Public Member Functions inherited from awsiotsdk::mqtt::Packet
 Packet (const Packet &)=delete
 
 Packet (Packet &&)=delete
 
Packetoperator= (const Packet &) &=delete
 
Packetoperator= (Packet &&) &=delete
 
uint16_t GetActionId ()
 Get ID of the current run of this Action. More...
 
void SetActionId (uint16_t action_id)
 Set the Action ID for this run of the Action. More...
 
bool isPacketDataValid ()
 
uint16_t GetPacketId ()
 
void SetPacketId (uint16_t packet_id)
 
size_t Size ()
 
virtual util::String ToString ()=0
 
- Public Member Functions inherited from awsiotsdk::ActionData
 ActionData (const ActionData &)=default
 
 ActionData (ActionData &&)=default
 
ActionDataoperator= (const ActionData &) &=default
 
ActionDataoperator= (ActionData &&) &=default
 
virtual uint16_t GetActionId ()=0
 Get ID of the current run of this Action. More...
 
virtual void SetActionId (uint16_t action_id)=0
 Set the Action ID for this run of the Action. More...
 

Static Public Member Functions

static std::shared_ptr< PublishPacketCreate (std::unique_ptr< Utf8String > p_topic_name, bool is_retained, bool is_duplicate, QoS qos, const util::String &payload)
 Create Factory method using Individual data. More...
 
static std::shared_ptr< PublishPacketCreate (const util::Vector< unsigned char > &buf, bool is_retained, bool is_duplicate, QoS qos)
 Create Factory method which deserializes data from a buffer. More...
 
- Static Public Member Functions inherited from awsiotsdk::mqtt::Packet
static void AppendUInt16ToBuffer (util::String &buf, uint16_t value)
 
static void AppendUtf8StringToBuffer (util::String &buf, std::unique_ptr< Utf8String > &utf8_str)
 
static void AppendUtf8StringToBuffer (util::String &buf, std::shared_ptr< Utf8String > &utf8_str)
 
static uint16_t ReadUInt16FromBuffer (const util::Vector< unsigned char > &buf, size_t &extract_index)
 
static std::unique_ptr< Utf8StringReadUtf8StringFromBuffer (const util::Vector< unsigned char > &buf, size_t &extract_index)
 

Protected Attributes

bool is_retained_
 Retained messages are NOT supported by the AWS IoT Service at the time of this SDK release.
 
bool is_duplicate_
 Is this message a duplicate QoS > 0 message? Handled automatically by the MQTT client.
 
QoS qos_
 Message Quality of Service.
 
std::unique_ptr< Utf8Stringp_topic_name_
 Topic Name this packet was published to.
 
util::String payload_
 MQTT message payload.
 
- Protected Attributes inherited from awsiotsdk::mqtt::Packet
PacketFixedHeader fixed_header_
 Fixed header for this packet instance.
 
size_t packet_size_
 Size of the packet.
 
size_t serialized_packet_length_
 Serialized length of the entire packet including fixed header.
 
std::atomic_uint_fast16_t packet_id_
 Message sequence identifier. Handled automatically by the MQTT client.
 

Additional Inherited Members

- Public Types inherited from awsiotsdk::ActionData
typedef std::function< void(uint16_t action_id, ResponseCode rc)> AsyncAckNotificationHandlerPtr
 
- Data Fields inherited from awsiotsdk::ActionData
AsyncAckNotificationHandlerPtr p_async_ack_handler_
 Handler to call when response is received for this action.
 

Detailed Description

Defines a type for MQTT Publish messages. Used for both incoming and out going messages

Constructor & Destructor Documentation

◆ PublishPacket() [1/2]

awsiotsdk::mqtt::PublishPacket::PublishPacket ( std::unique_ptr< Utf8String p_topic_name,
bool  is_retained,
bool  is_duplicate,
QoS  qos,
const util::String &  payload 
)
Warning
This constructor can throw exceptions, it is recommended to use Factory create method Constructor is kept public to not restrict usage possibilities (eg. make_shared)
Parameters
p_topic_nameTopic name on which message is to be published
is_retainedIs retained flag
is_duplicateIs duplicate message flag
qosQoS to use for this message, QoS2 is not supported currently
payloadString containing payload to send with message. Can be zero length.

◆ PublishPacket() [2/2]

awsiotsdk::mqtt::PublishPacket::PublishPacket ( const util::Vector< unsigned char > &  buf,
bool  is_retained,
bool  is_duplicate,
QoS  qos 
)
Warning
This constructor can throw exceptions, it is recommended to use Factory create method Constructor is kept public to not restrict usage possibilities (eg. make_shared)
Parameters
bufBuffer containing packet data
is_retainedIs retained flag
is_duplicateIs duplicate message flag
qosQoS used by this message

Member Function Documentation

◆ Create() [1/2]

std::shared_ptr< PublishPacket > awsiotsdk::mqtt::PublishPacket::Create ( const util::Vector< unsigned char > &  buf,
bool  is_retained,
bool  is_duplicate,
QoS  qos 
)
static
Parameters
bufBuffer containing packet data
is_retainedIs retained flag
is_duplicateIs duplicate message flag
qosQoS used by this message
Returns
nullptr on error, shared_ptr pointing to a created PublishPacket instance if successful

◆ Create() [2/2]

std::shared_ptr< PublishPacket > awsiotsdk::mqtt::PublishPacket::Create ( std::unique_ptr< Utf8String p_topic_name,
bool  is_retained,
bool  is_duplicate,
QoS  qos,
const util::String &  payload 
)
static
Parameters
p_topic_nameTopic name on which message is to be published
is_retainedIs retained flag
is_duplicateIs duplicate message flag
qosQoS to use for this message, QoS2 is not supported currently
payloadString containing payload to send with message. Can be zero length
Returns
nullptr on error, shared_ptr pointing to a created PublishPacket instance if successful

◆ GetPayload()

util::String awsiotsdk::mqtt::PublishPacket::GetPayload ( )
inline
Returns
util::String with payload

◆ GetPayloadLen()

size_t awsiotsdk::mqtt::PublishPacket::GetPayloadLen ( )
inline
Returns
util::String with payload length

◆ GetTopicName()

util::String awsiotsdk::mqtt::PublishPacket::GetTopicName ( )
inline
Returns
util::String with topic name

◆ IsDuplicate()

bool awsiotsdk::mqtt::PublishPacket::IsDuplicate ( )
inline
Returns
boolean indicating the value of the Is Duplicate message flag

◆ IsRetained()

bool awsiotsdk::mqtt::PublishPacket::IsRetained ( )
inline
Returns
boolean indicating the value of the Is Retained flag

◆ ToString()

util::String awsiotsdk::mqtt::PublishPacket::ToString ( )
virtual
Returns
String containing serialized packet

Implements awsiotsdk::mqtt::Packet.