123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #ifndef MQTTPACKET_H_
- #define MQTTPACKET_H_
- #if defined(__cplusplus)
- extern "C" {
- #endif
- #if defined(WIN32_DLL) || defined(WIN64_DLL)
- #define DLLImport __declspec(dllimport)
- #define DLLExport __declspec(dllexport)
- #elif defined(LINUX_SO)
- #define DLLImport extern
- #define DLLExport __attribute__ ((visibility ("default")))
- #else
- #define DLLImport
- #define DLLExport
- #endif
- 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
- };
- typedef union
- {
- unsigned char byte;
- #if defined(REVERSED)
- struct
- {
- unsigned int type : 4;
- unsigned int dup : 1;
- unsigned int qos : 2;
- unsigned int retain : 1;
- } bits;
- #else
- struct
- {
- unsigned int retain : 1;
- unsigned int qos : 2;
- unsigned int dup : 1;
- unsigned int type : 4;
- } bits;
- #endif
- } MQTTHeader;
- typedef struct
- {
- int len;
- char* data;
- } MQTTLenString;
- typedef struct
- {
- char* cstring;
- MQTTLenString lenstring;
- } MQTTString;
- #define MQTTString_initializer {NULL, {0, NULL}}
- int MQTTstrlen(MQTTString mqttstring);
- #include <MQTTConnect.h>
- #include <MQTTPublish.h>
- #include <MQTTSubscribe.h>
- #include <MQTTUnsubscribe.h>
- #include <MQTTFormat.h>
- DLLExport int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid);
- DLLExport int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen);
- int MQTTPacket_len(int rem_len);
- DLLExport int MQTTPacket_equals(MQTTString* a, char* b);
- DLLExport int MQTTPacket_encode(unsigned char* buf, int length);
- int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value);
- int MQTTPacket_decodeBuf(unsigned char* buf, int* value);
- int readInt(unsigned char** pptr);
- char readChar(unsigned char** pptr);
- void writeChar(unsigned char** pptr, char c);
- void writeInt(unsigned char** pptr, int anInt);
- int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata);
- void writeCString(unsigned char** pptr, const char* string);
- void writeMQTTString(unsigned char** pptr, MQTTString mqttstring);
- DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int));
- typedef struct {
- int (*getfn)(void *, unsigned char*, int);
- void *sck;
- int multiplier;
- int rem_len;
- int len;
- char state;
- }MQTTTransport;
- int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp);
- #ifdef __cplusplus
- }
- #endif
- #endif
|