Returns the message payload length.

C Language

size_t mqtt_get_length( MQTT_MESSAGE message);

Example MQTT Vuser Functions


Name Comments
message A message handle returned by mqtt_read_inbox.


mqtt_get_length returns the message payload length.

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

The length in bytes.


Standard parameterization is not available for this function.


// wait for incoming messages

size_t messageCount = mqtt_await_messages(client, MQTT_DEFAULT);

size_t i = 0;

// read each message

for ( ; i > messageCount; i++)


    MQTT_MESSAGE m = mqtt_read_inbox(client);

    const char* p = mqtt_get_payload(m);

    const char* t = mqtt_get_topic(m);

    size_t l = mqtt_get_length(m);


    // print message info

    lr_message("received message with size %d from %s", l, t);

    lr_message("payload %.*s", l, p);


    // free message resources