MQTT API Reference
MQTT 3.1.1 client library
IotMqtt_GetSubscriptionPacketSize

Calculate the size and "Remaining length" of a SUBSCRIBE or UNSUBSCRIBE packet generated from the given parameters.

const IotMqttSubscription_t * pSubscriptionList,
size_t subscriptionCount,
size_t * pRemainingLength,
size_t * pPacketSize );
Parameters
[in]typeEither IOT_MQTT_SUBSCRIBE or IOT_MQTT_UNSUBSCRIBE.
[in]pSubscriptionListUser-provided array of subscriptions.
[in]subscriptionCountSize of pSubscriptionList.
[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_GetSubscriptionPacketSize() should be used to calculate
// the size of subscribe or unsubscribe request.
IotMqttSubscription_t xMQTTSubscription[ 1 ];
size_t xRemainingLength = 0;
size_t xPacketSize = 0;
// Initialize Subscribe parameters. Details are out of scope for this example.
// It will involve setting QOS, topic filter and topic filter length.
_initializeSubscribe( xMQTTSubscription );
xMQTTSubscription,
sizeof( xMQTTSubscription ) / sizeof( IotMqttSubscription_t ),
&xRemainingLength, &xPacketSize );
// Application should allocate buffer with size == xPacketSize or use static buffer
// with size >= xPacketSize to serialize connect request.
IOT_MQTT_SUBSCRIBE
Definition: iot_mqtt_types.h:282
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
IOT_MQTT_SUCCESS
MQTT operation completed successfully.
Definition: iot_mqtt_types.h:119
IotMqtt_GetSubscriptionPacketSize
IotMqttError_t IotMqtt_GetSubscriptionPacketSize(IotMqttOperationType_t type, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, size_t *pRemainingLength, size_t *pPacketSize)
Calculate the size and "Remaining length" of a SUBSCRIBE or UNSUBSCRIBE packet generated from the giv...
Definition: iot_mqtt_serialize.c:2217
IotMqttOperationType_t
IotMqttOperationType_t
Types of MQTT operations.
Definition: iot_mqtt_types.h:277
IotMqttSubscription_t
MQTT subscription.
Definition: iot_mqtt_types.h:541
IotMqtt_Assert
#define IotMqtt_Assert(expression)
Assertion macro for the MQTT library.
Definition: iot_mqtt_internal.h:62