/* Decode MQTT Packet Length in the MQTT fixed header.  */
static int packet_length_decode(struct buf_ctx *buf, uint32_t *length)
/* Decode MQTT Packet Length in the MQTT fixed header.  */
static int packet_length_decode(struct buf_ctx *buf, uint32_t *length)
{
	uint8_t shift = 0U;
	uint8_t bytes = 0U;
	*length = 0U;
	do {
		if (bytes >= MQTT_MAX_LENGTH_BYTES) {
			return -EINVAL;
		}
		if (buf->cur >= buf->end) {
			return -EAGAIN;
		}
		*length += ((uint32_t)*(buf->cur) & MQTT_LENGTH_VALUE_MASK)
								<< shift;
		shift += MQTT_LENGTH_SHIFT;
		bytes++;
	} while ((*(buf->cur++) & MQTT_LENGTH_CONTINUATION_BIT) != 0U);
	if (*length > MQTT_MAX_PAYLOAD_SIZE) {
		return -EINVAL;
	}
	NET_DBG("length:0x%08x", *length);
	return 0;
}