coreMQTT v2.1.0
MQTT 3.1.1 Client Library
MQTT_GetUnsubscribePacketSize

Get packet size and Remaining Length of an MQTT UNSUBSCRIBE packet.

size_t subscriptionCount,
size_t * pRemainingLength,
size_t * pPacketSize );
MQTTStatus_t MQTT_GetUnsubscribePacketSize(const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, size_t *pRemainingLength, size_t *pPacketSize)
Get packet size and Remaining Length of an MQTT UNSUBSCRIBE packet.
Definition: core_mqtt_serializer.c:1982
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:99
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:192

This function must be called before MQTT_SerializeUnsubscribe in order to get the size of the MQTT UNSUBSCRIBE packet that is generated from the list of MQTTSubscribeInfo_t. The size of the MQTTFixedBuffer_t supplied to MQTT_SerializeUnsubscribe must be at least pPacketSize. The provided pSubscriptionList is valid for serialization with MQTT_SerializeUnsubscribe only if this function returns MQTTSuccess. The remaining length returned in pRemainingLength and the packet size returned in pPacketSize are valid only if this function returns MQTTSuccess.

Parameters
[in]pSubscriptionListList of MQTT subscription info.
[in]subscriptionCountThe number of elements in pSubscriptionList.
[out]pRemainingLengthThe Remaining Length of the MQTT UNSUBSCRIBE packet.
[out]pPacketSizeThe total size of the MQTT UNSUBSCRIBE packet.
Returns
MQTTBadParameter if the packet would exceed the size allowed by the MQTT spec; MQTTSuccess otherwise.

Example

// Variables used in this example.
MQTTStatus_t status;
MQTTSubscribeInfo_t subscriptionList[ NUMBER_OF_SUBSCRIPTIONS ] = { 0 };
size_t remainingLength = 0, packetSize = 0;
// Initialize the subscribe info. The details are out of scope for this example.
initializeSubscribeInfo( &subscriptionList[ 0 ] );
// Get the size requirement for the unsubscribe packet.
&subscriptionList[ 0 ], NUMBER_OF_SUBSCRIPTIONS, &remainingLength, &packetSize
);
if( status == MQTTSuccess )
{
// The application should allocate or use a static #MQTTFixedBuffer_t
// of size >= packetSize to serialize the unsubscribe request.
}
@ MQTTSuccess
Definition: core_mqtt_serializer.h:100