/* Encodes the message length according to the MQTT algorithm  */
int MQTTPacket_encode(unsigned char *buf, int length)
/* Encodes the message length according to the MQTT algorithm  */
int MQTTPacket_encode(unsigned char *buf, int length)
{
        char d = length % 128;
        length /= 128;
        if (length > 0)
            d |= 0x80;
        buf[rc++] = d;
    } while (length > 0);
    FUNC_EXIT_RC(rc);
    return rc;
}