net: mqtt: add MQTT_UTF8_LITERAL() helper macro

This macro allows to easily initialize utf8 strings (struct mqtt_utf8)
from C literals, as it automatically calculates string length.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2020-03-12 17:41:14 +01:00 committed by Jukka Rissanen
commit accef325a2

View file

@ -154,6 +154,18 @@ struct mqtt_utf8 {
u32_t size; /**< Size of UTF string, in bytes. */
};
/**
* @brief Initialize UTF-8 encoded string from C literal string.
*
* Use it as follows:
*
* struct mqtt_utf8 password = MQTT_UTF8_LITERAL("my_pass");
*
* @param[in] literal Literal string from which to generate mqtt_utf8 object.
*/
#define MQTT_UTF8_LITERAL(literal) \
((struct mqtt_utf8) {literal, sizeof(literal) - 1})
/** @brief Abstracts binary strings. */
struct mqtt_binstr {
u8_t *data; /**< Pointer to binary stream. */