Microchip® Advanced Software Framework

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

Functions

int MQTTDeserialize_connack (unsigned char *sessionPresent, unsigned char *connack_rc, unsigned char *buf, int buflen)
 Deserializes the supplied (wire) buffer into connack data - return code. More...
 
int MQTTSerialize_connect (unsigned char *buf, int buflen, MQTTPacket_connectData *options)
 Serializes the connect options into the buffer. More...
 
int MQTTSerialize_connectLength (MQTTPacket_connectData *options)
 Determines the length of the MQTT connect packet that would be produced using the supplied connect options. More...
 
int MQTTSerialize_disconnect (unsigned char *buf, int buflen)
 Serializes a disconnect packet into the supplied buffer, ready for writing to a socket. More...
 
int MQTTSerialize_pingreq (unsigned char *buf, int buflen)
 Serializes a disconnect packet into the supplied buffer, ready for writing to a socket. More...
 
int MQTTSerialize_zero (unsigned char *buf, int buflen, unsigned char packettype)
 Serializes a 0-length packet into the supplied buffer, ready for writing to a socket. More...
 

int MQTTDeserialize_connack ( unsigned char *  sessionPresent,
unsigned char *  connack_rc,
unsigned char *  buf,
int  buflen 
)

Deserializes the supplied (wire) buffer into connack data - return code.

Parameters
sessionPresentthe session present flag returned (only for MQTT 3.1.1)
connack_rcreturned integer value of the connack return code
bufthe raw buffer data, of the correct length determined by the remaining length field
lenthe length in bytes of the data in the supplied buffer
Returns
error code. 1 is success, 0 is failure

References MQTTConnackFlags::all, MQTTHeader::bits, MQTTConnackFlags::bits, MQTTHeader::byte, CONNACK, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTTPacket_decodeBuf(), NULL, readChar(), MQTTConnackFlags::sessionpresent, and MQTTHeader::type.

Referenced by MQTTConnect(), and MQTTFormat_toClientString().

int MQTTSerialize_connectLength ( MQTTPacket_connectData options)

Determines the length of the MQTT connect packet that would be produced using the supplied connect options.

Parameters
optionsthe options to be used to build the connect packet
Returns
the length of buffer needed to contain the serialized version of the packet

References MQTTPacket_connectData::clientID, MQTTString::cstring, MQTTLenString::data, FUNC_ENTRY, FUNC_EXIT_RC, MQTTString::lenstring, MQTTPacket_willOptions::message, MQTTstrlen(), MQTTPacket_connectData::MQTTVersion, MQTTPacket_connectData::password, MQTTPacket_willOptions::topicName, MQTTPacket_connectData::username, MQTTPacket_connectData::will, and MQTTPacket_connectData::willFlag.

Referenced by MQTTSerialize_connect().

int MQTTSerialize_disconnect ( unsigned char *  buf,
int  buflen 
)

Serializes a disconnect packet into the supplied buffer, ready for writing to a socket.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer, to avoid overruns
Returns
serialized length, or error if 0

References DISCONNECT, and MQTTSerialize_zero().

Referenced by MQTTDisconnect().

int MQTTSerialize_pingreq ( unsigned char *  buf,
int  buflen 
)

Serializes a disconnect packet into the supplied buffer, ready for writing to a socket.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer, to avoid overruns
Returns
serialized length, or error if 0

References MQTTSerialize_zero(), and PINGREQ.

Referenced by keepalive().

int MQTTSerialize_zero ( unsigned char *  buf,
int  buflen,
unsigned char  packettype 
)

Serializes a 0-length packet into the supplied buffer, ready for writing to a socket.

Parameters
bufthe buffer into which the packet will be serialized
buflenthe length in bytes of the supplied buffer, to avoid overruns
packettypethe message type
Returns
serialized length, or error if 0

References MQTTHeader::bits, MQTTHeader::byte, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTTPACKET_BUFFER_TOO_SHORT, MQTTPacket_encode(), ptr, MQTTHeader::type, and writeChar().

Referenced by MQTTSerialize_disconnect(), and MQTTSerialize_pingreq().