coreMQTT  v1.0.0
MQTT 3.1.1 Client Library

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

size_t subscriptionCount,
size_t * pRemainingLength,
size_t * pPacketSize );

This function must be called before MQTT_SerializeSubscribe in order to get the size of the MQTT SUBSCRIBE packet that is generated from the list of MQTTSubscribeInfo_t. The size of the MQTTFixedBuffer_t supplied to MQTT_SerializeSubscribe must be at least pPacketSize. The provided pSubscriptionList is valid for serialization with MQTT_SerializeSubscribe 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.

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


// Variables used in this example.
MQTTStatus_t status;
MQTTSubscribeInfo_t subscriptionList[ NUMBER_OF_SUBSCRIPTIONS ] = { 0 };
size_t remainingLength = 0, packetSize = 0;
// This is assumed to be a list of filters we want to subscribe to.
const char * filters[ NUMBER_OF_SUBSCRIPTIONS ];
// Set each subscription.
for( int i = 0; i < NUMBER_OF_SUBSCRIPTIONS; i++ )
subscriptionList[ i ].qos = MQTTQoS0;
// Each subscription needs a topic filter.
subscriptionList[ i ].pTopicFilter = filters[ i ];
subscriptionList[ i ].topicFilterLength = strlen( filters[ i ] );
// Get the size requirement for the subscribe 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 subscribe request.
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:195
const char * pTopicFilter
Topic filter to subscribe to.
Definition: core_mqtt_serializer.h:204
MQTTStatus_t MQTT_GetSubscribePacketSize(const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, size_t *pRemainingLength, size_t *pPacketSize)
Get packet size and Remaining Length of an MQTT SUBSCRIBE packet.
Definition: core_mqtt_serializer.c:1640
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:105
uint16_t topicFilterLength
Length of subscription topic filter.
Definition: core_mqtt_serializer.h:209
MQTTQoS_t qos
Quality of Service for subscription.
Definition: core_mqtt_serializer.h:199
@ MQTTSuccess
Definition: core_mqtt_serializer.h:106
Definition: core_mqtt_serializer.h:125