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:
parent
c58d8fcb79
commit
accef325a2
1 changed files with 12 additions and 0 deletions
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue