AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqtt_GetPublishPacketSize

Calculate the size and "Remaining length" of a PUBLISH packet generated from the given parameters.

size_t * pRemainingLength,
size_t * pPacketSize );
Parameters
[in]pPublishInfoUser-provided PUBLISH information struct.
[out]pRemainingLengthOutput for calculated "Remaining length" field.
[out]pPacketSizeOutput for calculated total packet size.
Returns
IOT_MQTT_SUCCESS if the packet is within the length allowed by MQTT 3.1.1 spec; IOT_MQTT_BAD_PARAMETER otherwise. If this function returns IOT_MQTT_BAD_PARAMETER, the output parameters should be ignored.
Note
This call is part of serializer API used for implementing light-weight MQTT client.

Example

// Example code below shows how IotMqtt_GetPublishPacketSize() should be used to calculate
// the size of MQTT publish request.
IotMqttPublishInfo_t xMQTTPublishInfo;
size_t xRemainingLength = 0;
size_t xPacketSize = 0;
// Initialize Publish parameters. Details are out of scope for this example.
// It will involve setting QOS, topic filter, topic filter length, payload
// payload length
_initializePublish( &xMQTTPublishInfo );
// Find out length of Publish packet size.
xResult = IotMqtt_GetPublishPacketSize( &xMQTTPublishInfo, &xRemainingLength, &xPacketSize );
// Application should allocate buffer with size == xPacketSize or use static buffer
// with size >= xPacketSize to serialize connect request.