Microchip® Advanced Software Framework

AWS_SDK/AWS_SDK/aws_mqtt_embedded_client_lib/MQTTPacket/src/MQTTSerializePublish.c File Reference
#include "MQTTPacket.h"
#include "StackTrace.h"
#include <string.h>

Functions

MQTTReturnCode MQTTSerialize_ack (unsigned char *buf, size_t buflen, unsigned char type, uint8_t dup, uint16_t packetid, uint32_t *serialized_len)
 Serializes the ack packet into the supplied buffer. More...
 
size_t MQTTSerialize_GetPublishLength (uint8_t qos, MQTTString topicName, size_t payloadlen)
 Determines the length of the MQTT publish packet that would be produced using the supplied parameters. More...
 
MQTTReturnCode MQTTSerialize_puback (unsigned char *buf, size_t buflen, uint16_t packetid, uint32_t *serialized_len)
 Serializes a puback packet into the supplied buffer. More...
 
MQTTReturnCode MQTTSerialize_pubcomp (unsigned char *buf, size_t buflen, uint16_t packetid, uint32_t *serialized_len)
 Serializes a pubrel packet into the supplied buffer. More...
 
MQTTReturnCode MQTTSerialize_publish (unsigned char *buf, size_t buflen, uint8_t dup, QoS qos, uint8_t retained, uint16_t packetid, MQTTString topicName, unsigned char *payload, size_t payloadlen, uint32_t *serialized_len)
 Serializes the supplied publish data into the supplied buffer, ready for sending. More...
 
MQTTReturnCode MQTTSerialize_pubrel (unsigned char *buf, size_t buflen, unsigned char dup, uint16_t packetid, uint32_t *serialized_len)
 Serializes a pubrel packet into the supplied buffer. More...
 

MQTTReturnCode MQTTSerialize_ack ( unsigned char *  buf,
size_t  buflen,
unsigned char  type,
uint8_t  dup,
uint16_t  packetid,
uint32_t *  serialized_len 
)

Serializes the ack packet into the supplied buffer.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer
typethe MQTT packet type
dupthe MQTT dup flag
packetidthe MQTT packet identifier
Returns
serialized length, or error if 0

References buf, MQTTHeader::byte, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTT_NULL_VALUE_ERROR, MQTTPACKET_BUFFER_TOO_SHORT, MQTTPacket_encode(), MQTTPacket_InitHeader(), NULL, ptr, PUBREL, QOS0, QOS1, SUCCESS, writeChar(), and writePacketId().

size_t MQTTSerialize_GetPublishLength ( uint8_t  qos,
MQTTString  topicName,
size_t  payloadlen 
)

Determines the length of the MQTT publish packet that would be produced using the supplied parameters.

Parameters
qosthe MQTT QoS of the publish (packetid is omitted for QoS 0)
topicNamethe topic name to be used in the publish
payloadlenthe length of the payload to be sent
Returns
the length of buffer needed to contain the serialized version of the packet

References len, and MQTTstrlen().

Referenced by MQTTSerialize_publish().

MQTTReturnCode MQTTSerialize_puback ( unsigned char *  buf,
size_t  buflen,
uint16_t  packetid,
uint32_t *  serialized_len 
)

Serializes a puback packet into the supplied buffer.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer
packetidinteger - the MQTT packet identifier
Returns
serialized length, or error if 0

References MQTTSerialize_ack(), and PUBACK.

MQTTReturnCode MQTTSerialize_pubcomp ( unsigned char *  buf,
size_t  buflen,
uint16_t  packetid,
uint32_t *  serialized_len 
)

Serializes a pubrel packet into the supplied buffer.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer
packetidinteger - the MQTT packet identifier
Returns
serialized length, or error if 0

References MQTTSerialize_ack(), and PUBCOMP.

MQTTReturnCode MQTTSerialize_publish ( unsigned char *  buf,
size_t  buflen,
uint8_t  dup,
QoS  qos,
uint8_t  retained,
uint16_t  packetid,
MQTTString  topicName,
unsigned char *  payload,
size_t  payloadlen,
uint32_t *  serialized_len 
)

Serializes the supplied publish data into the supplied buffer, ready for sending.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer
dupinteger - the MQTT dup flag
qosinteger - the MQTT QoS value
retainedinteger - the MQTT retained flag
packetidinteger - the MQTT packet identifier
topicNameMQTTString - the MQTT topic in the publish
payloadbyte buffer - the MQTT publish payload
payloadleninteger - the length of the MQTT payload
Returns
the length of the serialized data. <= 0 indicates error

References buf, MQTTHeader::byte, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTT_NULL_VALUE_ERROR, MQTTPACKET_BUFFER_TOO_SHORT, MQTTPacket_encode(), MQTTPacket_InitHeader(), MQTTPacket_len(), MQTTSerialize_GetPublishLength(), NULL, ptr, PUBLISH, SUCCESS, writeChar(), writeInt(), and writeMQTTString().

MQTTReturnCode MQTTSerialize_pubrel ( unsigned char *  buf,
size_t  buflen,
unsigned char  dup,
uint16_t  packetid,
uint32_t *  serialized_len 
)

Serializes a pubrel packet into the supplied buffer.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer
dupinteger - the MQTT dup flag
packetidinteger - the MQTT packet identifier
Returns
serialized length, or error if 0

References MQTTSerialize_ack(), and PUBREL.