#include "MQTTConnect.h"
#include "MQTTPublish.h"
#include "MQTTSubscribe.h"
#include "MQTTUnsubscribe.h"
#include "MQTTFormat.h"
Data Structures | |
union | MQTTHeader |
Bitfields for the MQTT header byte. More... | |
struct | MQTTLenString |
struct | MQTTString |
struct | MQTTTransport |
Macros | |
#define | DLLExport |
#define | DLLImport |
#define | MQTTString_initializer {NULL, {0, NULL}} |
Enumerations | |
enum | errors { MQTTPACKET_BUFFER_TOO_SHORT = -2, MQTTPACKET_READ_ERROR = -1, MQTTPACKET_READ_COMPLETE } |
enum | msgTypes { CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ, PINGRESP, DISCONNECT } |
Functions | |
int | MQTTDeserialize_ack (unsigned char *packettype, unsigned char *dup, unsigned short *packetid, unsigned char *buf, int buflen) |
Deserializes the supplied (wire) buffer into an ack. More... | |
int | MQTTPacket_decode (int(*getcharfn)(unsigned char *, int), int *value) |
Decodes the message length according to the MQTT algorithm. More... | |
int | MQTTPacket_decodeBuf (unsigned char *buf, int *value) |
int | MQTTPacket_encode (unsigned char *buf, int length) |
Encodes the message length according to the MQTT algorithm. More... | |
int | MQTTPacket_equals (MQTTString *a, char *b) |
Compares an MQTTString to a C string. More... | |
int | MQTTPacket_len (int rem_len) |
DLLExport int | MQTTPacket_read (unsigned char *buf, int buflen, int(*getfn)(unsigned char *, int)) |
Helper function to read packet data from some source into a buffer. More... | |
int | MQTTPacket_readnb (unsigned char *buf, int buflen, MQTTTransport *trp) |
Helper function to read packet data from some source into a buffer, non-blocking. More... | |
int | MQTTSerialize_ack (unsigned char *buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid) |
Serializes the ack packet into the supplied buffer. More... | |
int | MQTTstrlen (MQTTString mqttstring) |
Return the length of the MQTTstring - C string if there is one, otherwise the length delimited string. More... | |
char | readChar (unsigned char **pptr) |
Reads one character from the input buffer. More... | |
int | readInt (unsigned char **pptr) |
Calculates an integer from two bytes read from the input buffer. More... | |
int | readMQTTLenString (MQTTString *mqttstring, unsigned char **pptr, unsigned char *enddata) |
void | writeChar (unsigned char **pptr, char c) |
Writes one character to an output buffer. More... | |
void | writeCString (unsigned char **pptr, const char *string) |
Writes a "UTF" string to an output buffer. More... | |
void | writeInt (unsigned char **pptr, int anInt) |
Writes an integer as 2 bytes to an output buffer. More... | |
void | writeMQTTString (unsigned char **pptr, MQTTString mqttstring) |
#define DLLExport |
#define DLLImport |
Referenced by MQTTFormat_toClientString(), MQTTFormat_toServerString(), MQTTPublish(), MQTTSubscribe(), and MQTTUnsubscribe().
enum errors |
enum msgTypes |
int MQTTDeserialize_ack | ( | unsigned char * | packettype, |
unsigned char * | dup, | ||
unsigned short * | packetid, | ||
unsigned char * | buf, | ||
int | buflen | ||
) |
Deserializes the supplied (wire) buffer into an ack.
packettype | returned integer - the MQTT packet type |
dup | returned integer - the MQTT dup flag |
packetid | returned integer - the MQTT packet identifier |
buf | the raw buffer data, of the correct length determined by the remaining length field |
buflen | the length in bytes of the data in the supplied buffer |
References MQTTHeader::bits, MQTTHeader::byte, MQTTHeader::dup, FUNC_ENTRY, FUNC_EXIT_RC, header, MQTTPacket_decodeBuf(), NULL, readChar(), readInt(), and MQTTHeader::type.
Referenced by cycle(), MQTTDeserialize_unsuback(), MQTTFormat_toClientString(), MQTTFormat_toServerString(), and MQTTPublish().
int MQTTPacket_decode | ( | int(*)(unsigned char *, int) | getcharfn, |
int * | value | ||
) |
Decodes the message length according to the MQTT algorithm.
getcharfn | pointer to function to read the next character from the data source |
value | the decoded length returned |
References FUNC_ENTRY, FUNC_EXIT_RC, MAX_NO_OF_REMAINING_LENGTH_BYTES, and MQTTPACKET_READ_ERROR.
Referenced by MQTTPacket_decodeBuf(), and MQTTPacket_read().
int MQTTPacket_decodeBuf | ( | unsigned char * | buf, |
int * | value | ||
) |
References bufchar(), and MQTTPacket_decode().
Referenced by MQTTDeserialize_ack(), MQTTDeserialize_connack(), MQTTDeserialize_connect(), MQTTDeserialize_publish(), MQTTDeserialize_suback(), MQTTDeserialize_subscribe(), MQTTDeserialize_unsubscribe(), MQTTFormat_toClientString(), and MQTTFormat_toServerString().
int MQTTPacket_encode | ( | unsigned char * | buf, |
int | length | ||
) |
Encodes the message length according to the MQTT algorithm.
buf | the buffer into which the encoded data is written |
length | the length to be encoded |
References FUNC_ENTRY, and FUNC_EXIT_RC.
Referenced by MQTTPacket_read(), MQTTPacket_readnb(), MQTTSerialize_ack(), MQTTSerialize_connack(), MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_suback(), MQTTSerialize_subscribe(), MQTTSerialize_unsuback(), MQTTSerialize_unsubscribe(), MQTTSerialize_zero(), and readPacket().
int MQTTPacket_equals | ( | MQTTString * | a, |
char * | bptr | ||
) |
Compares an MQTTString to a C string.
a | the MQTTString to compare |
bptr | the C string to compare |
References MQTTString::cstring, MQTTLenString::data, MQTTLenString::len, and MQTTString::lenstring.
Referenced by deliverMessage().
int MQTTPacket_len | ( | int | rem_len | ) |
Referenced by MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_subscribe(), and MQTTSerialize_unsubscribe().
DLLExport int MQTTPacket_read | ( | unsigned char * | buf, |
int | buflen, | ||
int(*)(unsigned char *, int) | getfn | ||
) |
Helper function to read packet data from some source into a buffer.
buf | the buffer into which the packet will be serialized |
buflen | the length in bytes of the supplied buffer |
getfn | pointer to a function which will read any number of bytes from the needed source |
References MQTTHeader::bits, MQTTHeader::byte, header, MQTTPacket_decode(), MQTTPacket_encode(), and MQTTHeader::type.
int MQTTPacket_readnb | ( | unsigned char * | buf, |
int | buflen, | ||
MQTTTransport * | trp | ||
) |
Helper function to read packet data from some source into a buffer, non-blocking.
buf | the buffer into which the packet will be serialized |
buflen | the length in bytes of the supplied buffer |
trp | pointer to a transport structure holding what is needed to solve getting data from it |
References MQTTHeader::bits, MQTTHeader::byte, MQTTTransport::getfn, header, MQTTTransport::len, MQTTPacket_decodenb(), MQTTPacket_encode(), MQTTPACKET_READ_ERROR, MQTTTransport::rem_len, MQTTTransport::sck, MQTTTransport::state, and MQTTHeader::type.
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.
buf | the buffer into which the packet will be serialized |
buflen | the length in bytes of the supplied buffer |
type | the MQTT packet type |
dup | the MQTT dup flag |
packetid | the MQTT packet identifier |
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 MQTTstrlen | ( | MQTTString | mqttstring | ) |
Return the length of the MQTTstring - C string if there is one, otherwise the length delimited string.
mqttstring | the string to return the length of |
References MQTTString::cstring, MQTTLenString::len, and MQTTString::lenstring.
Referenced by MQTTSerialize_connectLength(), MQTTSerialize_publishLength(), MQTTSerialize_subscribeLength(), and MQTTSerialize_unsubscribeLength().
char readChar | ( | unsigned char ** | pptr | ) |
Reads one character from the input buffer.
pptr | pointer to the input buffer - incremented by the number of bytes used & returned |
Referenced by MQTTDeserialize_ack(), MQTTDeserialize_connack(), MQTTDeserialize_connect(), MQTTDeserialize_publish(), MQTTDeserialize_suback(), MQTTDeserialize_subscribe(), and MQTTDeserialize_unsubscribe().
int readInt | ( | unsigned char ** | pptr | ) |
Calculates an integer from two bytes read from the input buffer.
pptr | pointer to the input buffer - incremented by the number of bytes used & returned |
References ptr.
Referenced by MQTTDeserialize_ack(), MQTTDeserialize_connect(), MQTTDeserialize_publish(), MQTTDeserialize_suback(), MQTTDeserialize_subscribe(), MQTTDeserialize_unsubscribe(), and readMQTTLenString().
int readMQTTLenString | ( | MQTTString * | mqttstring, |
unsigned char ** | pptr, | ||
unsigned char * | enddata | ||
) |
mqttstring | the MQTTString structure into which the data is to be read |
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
enddata | pointer to the end of the data: do not read beyond |
References MQTTString::cstring, MQTTLenString::data, FUNC_ENTRY, FUNC_EXIT_RC, MQTTLenString::len, MQTTString::lenstring, NULL, and readInt().
Referenced by MQTTDeserialize_connect(), MQTTDeserialize_publish(), MQTTDeserialize_subscribe(), and MQTTDeserialize_unsubscribe().
void writeChar | ( | unsigned char ** | pptr, |
char | c | ||
) |
Writes one character to an output buffer.
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
c | the character to write |
Referenced by MQTTSerialize_ack(), MQTTSerialize_connack(), MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_suback(), MQTTSerialize_subscribe(), MQTTSerialize_unsuback(), MQTTSerialize_unsubscribe(), and MQTTSerialize_zero().
void writeCString | ( | unsigned char ** | pptr, |
const char * | string | ||
) |
Writes a "UTF" string to an output buffer.
Converts C string to length-delimited.
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
string | the C string to write |
References writeInt().
Referenced by MQTTSerialize_connect(), and writeMQTTString().
void writeInt | ( | unsigned char ** | pptr, |
int | anInt | ||
) |
Writes an integer as 2 bytes to an output buffer.
pptr | pointer to the output buffer - incremented by the number of bytes used & returned |
anInt | the integer to write |
Referenced by MQTTSerialize_ack(), MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_suback(), MQTTSerialize_subscribe(), MQTTSerialize_unsuback(), MQTTSerialize_unsubscribe(), writeCString(), and writeMQTTString().
void writeMQTTString | ( | unsigned char ** | pptr, |
MQTTString | mqttstring | ||
) |
References MQTTString::cstring, MQTTLenString::data, MQTTLenString::len, MQTTString::lenstring, writeCString(), and writeInt().
Referenced by MQTTSerialize_connect(), MQTTSerialize_publish(), MQTTSerialize_subscribe(), and MQTTSerialize_unsubscribe().