Microchip® Advanced Software Framework

MQTTSerializePublish.c File Reference
#include "MQTTPacket.h"
#include "StackTrace.h"
#include <string.h>

Functions

int MQTTSerialize_ack (unsigned char *buf, int buflen, unsigned char packettype, unsigned char dup, unsigned short packetid)
 Serializes the ack packet into the supplied buffer. More...
 
int MQTTSerialize_puback (unsigned char *buf, int buflen, unsigned short packetid)
 Serializes a puback packet into the supplied buffer. More...
 
int MQTTSerialize_pubcomp (unsigned char *buf, int buflen, unsigned short packetid)
 Serializes a pubrel packet into the supplied buffer. More...
 
int MQTTSerialize_publish (unsigned char *buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, MQTTString topicName, unsigned char *payload, int payloadlen)
 Serializes the supplied publish data into the supplied buffer, ready for sending. More...
 
int MQTTSerialize_publishLength (int qos, MQTTString topicName, int payloadlen)
 Determines the length of the MQTT publish packet that would be produced using the supplied parameters. More...
 
int MQTTSerialize_pubrel (unsigned char *buf, int buflen, unsigned char dup, unsigned short packetid)
 Serializes a pubrel packet into the supplied buffer. More...
 

int MQTTSerialize_ack ( unsigned char *  buf,
int  buflen,
unsigned char  packettype,
unsigned char  dup,
unsigned short  packetid 
)

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 MQTTHeader::bits, MQTTHeader::byte, MQTTHeader::dup, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTTPACKET_BUFFER_TOO_SHORT, MQTTPacket_encode(), ptr, PUBREL, MQTTHeader::qos, MQTTHeader::type, writeChar(), and writeInt().

Referenced by cycle(), MQTTSerialize_puback(), MQTTSerialize_pubcomp(), and MQTTSerialize_pubrel().

int MQTTSerialize_puback ( unsigned char *  buf,
int  buflen,
unsigned short  packetid 
)

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.

int MQTTSerialize_pubcomp ( unsigned char *  buf,
int  buflen,
unsigned short  packetid 
)

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.

int MQTTSerialize_publish ( unsigned char *  buf,
int  buflen,
unsigned char  dup,
int  qos,
unsigned char  retained,
unsigned short  packetid,
MQTTString  topicName,
unsigned char *  payload,
int  payloadlen 
)

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 MQTTHeader::bits, MQTTHeader::byte, MQTTHeader::dup, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTTPACKET_BUFFER_TOO_SHORT, MQTTPacket_encode(), MQTTPacket_len(), MQTTSerialize_publishLength(), ptr, PUBLISH, MQTTHeader::qos, MQTTHeader::retain, MQTTHeader::type, writeChar(), writeInt(), and writeMQTTString().

Referenced by MQTTPublish().

int MQTTSerialize_publishLength ( int  qos,
MQTTString  topicName,
int  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 MQTTstrlen().

Referenced by MQTTSerialize_publish().

int MQTTSerialize_pubrel ( unsigned char *  buf,
int  buflen,
unsigned char  dup,
unsigned short  packetid 
)

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.