Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more
MQTTPacket.h
00001 /******************************************************************************* 00002 * Copyright (c) 2014 IBM Corp. 00003 * 00004 * All rights reserved. This program and the accompanying materials 00005 * are made available under the terms of the Eclipse Public License v1.0 00006 * and Eclipse Distribution License v1.0 which accompany this distribution. 00007 * 00008 * The Eclipse Public License is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * and the Eclipse Distribution License is available at 00011 * http://www.eclipse.org/org/documents/edl-v10.php. 00012 * 00013 * Contributors: 00014 * Ian Craggs - initial API and implementation and/or initial documentation 00015 * Xiang Rong - 442039 Add makefile to Embedded C client 00016 *******************************************************************************/ 00017 00018 #ifndef MQTTPACKET_H_ 00019 #define MQTTPACKET_H_ 00020 00021 #include <stddef.h> 00022 00023 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 00024 extern "C" { 00025 #endif 00026 00027 #if defined(WIN32_DLL) || defined(WIN64_DLL) 00028 #define DLLImport __declspec(dllimport) 00029 #define DLLExport __declspec(dllexport) 00030 #elif defined(LINUX_SO) 00031 #define DLLImport extern 00032 #define DLLExport __attribute__ ((visibility ("default"))) 00033 #else 00034 #define DLLImport 00035 #define DLLExport 00036 #endif 00037 00038 enum errors 00039 { 00040 MQTTPACKET_BUFFER_TOO_SHORT = -2, 00041 MQTTPACKET_READ_ERROR = -1, 00042 MQTTPACKET_READ_COMPLETE 00043 }; 00044 00045 enum msgTypes 00046 { 00047 CONNECT_MSG = 1, CONNACK_MSG, PUBLISH_MSG, PUBACK_MSG, PUBREC_MSG, PUBREL_MSG, 00048 PUBCOMP_MSG, SUBSCRIBE_MSG, SUBACK_MSG, UNSUBSCRIBE_MSG, UNSUBACK_MSG, 00049 PINGREQ_MSG, PINGRESP_MSG, DISCONNECT_MSG 00050 }; 00051 00052 /** 00053 * Bitfields for the MQTT header byte. 00054 */ 00055 typedef union 00056 { 00057 unsigned char byte; /**< the whole byte */ 00058 #if defined(REVERSED) 00059 struct 00060 { 00061 unsigned int type : 4; /**< message type nibble */ 00062 unsigned int dup : 1; /**< DUP flag bit */ 00063 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 00064 unsigned int retain : 1; /**< retained flag bit */ 00065 } bits; 00066 #else 00067 struct 00068 { 00069 unsigned int retain : 1; /**< retained flag bit */ 00070 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 00071 unsigned int dup : 1; /**< DUP flag bit */ 00072 unsigned int type : 4; /**< message type nibble */ 00073 } bits; 00074 #endif 00075 } MQTTHeader; 00076 00077 typedef struct 00078 { 00079 size_t len; 00080 char* data; 00081 } MQTTLenString; 00082 00083 typedef struct 00084 { 00085 char* cstring; 00086 MQTTLenString lenstring; 00087 } MQTTString; 00088 00089 #define MQTTString_initializer {NULL, {0, NULL}} 00090 00091 size_t MQTTstrlen(MQTTString mqttstring); 00092 00093 #include "MQTTConnect.h" 00094 #include "MQTTPublish.h" 00095 #include "MQTTSubscribe.h" 00096 #include "MQTTUnsubscribe.h" 00097 00098 int MQTTSerialize_ack(unsigned char* buf, size_t buflen, unsigned char type, unsigned char dup, unsigned short packetid); 00099 int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, size_t buflen); 00100 00101 size_t MQTTPacket_len(size_t rem_len); 00102 int MQTTPacket_equals(MQTTString* a, char* b); 00103 00104 int MQTTPacket_encode(unsigned char* buf, size_t length); 00105 int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); 00106 int MQTTPacket_decodeBuf(unsigned char* buf, int* value); 00107 00108 int readInt(unsigned char** pptr); 00109 char readChar(unsigned char** pptr); 00110 void writeChar(unsigned char** pptr, char c); 00111 void writeInt(unsigned char** pptr, int anInt); 00112 int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); 00113 void writeCString(unsigned char** pptr, const char* string); 00114 void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); 00115 00116 DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); 00117 00118 typedef struct { 00119 int (*getfn)(void *, unsigned char*, int); /* must return -1 for error, 0 for call again, or the number of bytes read */ 00120 void *sck; /* pointer to whatever the system may use to identify the transport */ 00121 int multiplier; 00122 int rem_len; 00123 int len; 00124 char state; 00125 }MQTTTransport; 00126 00127 int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp); 00128 00129 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ 00130 } 00131 #endif 00132 00133 00134 #endif /* MQTTPACKET_H_ */
Generated on Wed Jul 13 2022 15:49:28 by
1.7.2