/* Write a single variable length string with header to the server.  */
static int write_mqtt_string(struct mqtt_client_t *self_p, struct mqtt_string_t *mqtt_string)
/* Write a single variable length string with header to the server.  */
static int write_mqtt_string(struct mqtt_client_t *self_p, struct mqtt_string_t *mqtt_string)
{
    int res;
    uint8_t buf[2];
    if (mqtt_string->size == 0 || mqtt_string->buf_p == NULL) {
        return (-EINVAL);
    }
    if (mqtt_string->size > 0xffff) {
        return (-EINVAL);
    }
    buf[0] = MSB(mqtt_string->size);
    buf[1] = LSB(mqtt_string->size);
    if (chan_write(self_p->transport.out_p, &buf[0], 2) != 2) {
        return (-EIO);
    }
    res = chan_write(self_p->transport.out_p,
                     mqtt_string->buf_p,
                     mqtt_string->size);
    if (res != mqtt_string->size) {
        return (-EIO);
    }
    return (0);
}