/* Read the fixed header of a MQTT message from the server.  */
static int read_fixed_header(struct mqtt_client_t *self_p, int *type_p, int *flags_p, size_t *size_p)
/* Read the fixed header of a MQTT message from the server.  */
static int read_fixed_header(struct mqtt_client_t *self_p, int *type_p, int *flags_p, size_t *size_p)
{
    uint8_t byte;
    long multiplier;
    if (chan_read(self_p->transport.in_p, &byte, 1) != 1) {
        return (-EIO);
    }
    *type_p = ((byte >> 4) & 0xf);
    *flags_p = (byte & 0xf);
    multiplier = 1;
    *size_p = 0;
    do {
        if (chan_read(self_p->transport.in_p, &byte, 1) != 1) {
            return (-EIO);
        }
        *size_p += (byte & 0x7f) * multiplier;
        multiplier *= 128;
        if (multiplier > 128L * 128L * 128L) {
            return (-1);
        }
    } while ((byte & 0x80) != 0);
    return (0);
}