/* Serializes the supplied unsuback data into the supplied buffer, ready for sending  */
int MQTTSerialize_unsuback(unsigned char *buf, int buflen, unsigned short packetid)
/* Serializes the supplied unsuback data into the supplied buffer, ready for sending  */
int MQTTSerialize_unsuback(unsigned char *buf, int buflen, unsigned short packetid)
{
    MQTTHeader header = {0};
    int rc = 0;
    unsigned char* ptr = buf;
    FUNC_ENTRY;
    if (buflen < 2) {
        rc = MQTTPACKET_BUFFER_TOO_SHORT;
        goto exit;
    }
    header.byte = 0;
    header.bits.type = UNSUBACK;
    writeChar(&ptr, header.byte);
    ptr += MQTTPacket_encode(ptr, 2);
    writeInt(&ptr, packetid);
    rc = ptr - buf;
exit:
    FUNC_EXIT_RC(rc);
    return rc;
}