123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "MQTTPacket.h"
- #include "StackTrace.h"
- #include <string.h>
- int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[],
- int requestedQoSs[], unsigned char* buf, int buflen)
- {
- MQTTHeader header = {0};
- unsigned char* curdata = buf;
- unsigned char* enddata = NULL;
- int rc = -1;
- int mylen = 0;
- FUNC_ENTRY;
- header.byte = readChar(&curdata);
- if (header.bits.type != SUBSCRIBE)
- goto exit;
- *dup = header.bits.dup;
- curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen));
- enddata = curdata + mylen;
- *packetid = readInt(&curdata);
- *count = 0;
- while (curdata < enddata)
- {
- if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata))
- goto exit;
- if (curdata >= enddata)
- goto exit;
- requestedQoSs[*count] = readChar(&curdata);
- (*count)++;
- }
- rc = 1;
- exit:
- FUNC_EXIT_RC(rc);
- return rc;
- }
- int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs)
- {
- MQTTHeader header = {0};
- int rc = -1;
- unsigned char *ptr = buf;
- int i;
- FUNC_ENTRY;
- if (buflen < 2 + count)
- {
- rc = MQTTPACKET_BUFFER_TOO_SHORT;
- goto exit;
- }
- header.byte = 0;
- header.bits.type = SUBACK;
- writeChar(&ptr, header.byte);
- ptr += MQTTPacket_encode(ptr, 2 + count);
- writeInt(&ptr, packetid);
- for (i = 0; i < count; ++i)
- writeChar(&ptr, grantedQoSs[i]);
- rc = ptr - buf;
- exit:
- FUNC_EXIT_RC(rc);
- return rc;
- }
|