/* Encodes fixed header for the MQTT message and provides pointer to start of the header.  */
static uint32_t mqtt_encode_fixed_header(uint8_t message_type, uint8_t *start, struct buf_ctx *buf)
/* Encodes fixed header for the MQTT message and provides pointer to start of the header.  */
static uint32_t mqtt_encode_fixed_header(uint8_t message_type, uint8_t *start, struct buf_ctx *buf)
{
	uint32_t length = buf->cur - start;
	uint8_t fixed_header_length;
	if (length > MQTT_MAX_PAYLOAD_SIZE) {
		return -EMSGSIZE;
	}
	NET_DBG("<< msg type:0x%02x length:0x%08x", message_type, length);
	fixed_header_length = packet_length_encode(length, NULL);
	fixed_header_length += sizeof(uint8_t);
	NET_DBG("Fixed header length = %02x", fixed_header_length);
	buf->cur = start - fixed_header_length;
	(void)pack_uint8(message_type, buf);
	(void)packet_length_encode(length, buf);
	buf->cur = buf->cur - fixed_header_length;
	buf->end = buf->cur + length + fixed_header_length;
	return 0;
}