/* Decodes the message length according to the MQTT algorithm  */
int MQTTPacket_decode(int(*getcharfn)(unsigned char *, int), int *value)
/* Decodes the message length according to the MQTT algorithm  */
int MQTTPacket_decode(int(*getcharfn)(unsigned char *, int), int *value)
{
        int rc = MQTTPACKET_READ_ERROR;
        if (++len > MAX_NO_OF_REMAINING_LENGTH_BYTES) {
            rc = MQTTPACKET_READ_ERROR;
            goto exit;
        }
        rc = (*getcharfn)(&c, 1);
        if (rc != 1)
            goto exit;
        *value += (c & 127) * multiplier;
        multiplier *= 128;
    } while ((c & 128) != 0);
exit:
    FUNC_EXIT_RC(len);
    return len;
}