coreMQTT v2.1.1
MQTT 3.1.1 Client Library
MQTT_SerializeUnsubscribe

Serialize an MQTT UNSUBSCRIBE packet in the given buffer.

size_t subscriptionCount,
uint16_t packetId,
size_t remainingLength,
const MQTTFixedBuffer_t * pFixedBuffer );
MQTTStatus_t MQTT_SerializeUnsubscribe(const MQTTSubscribeInfo_t *pSubscriptionList, size_t subscriptionCount, uint16_t packetId, size_t remainingLength, const MQTTFixedBuffer_t *pFixedBuffer)
Serialize an MQTT UNSUBSCRIBE packet in the given buffer.
Definition: core_mqtt_serializer.c:2020
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:99
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:135
MQTT SUBSCRIBE packet parameters.
Definition: core_mqtt_serializer.h:192

MQTT_GetUnsubscribePacketSize should be called with pSubscriptionList before invoking this function to get the size of the required MQTTFixedBuffer_t and remainingLength. The remainingLength must be the same as returned by MQTT_GetUnsubscribePacketSize. The MQTTFixedBuffer_t must be at least as large as the size returned by MQTT_GetUnsubscribePacketSize.

Parameters
[in]pSubscriptionListList of MQTT subscription info.
[in]subscriptionCountThe number of elements in pSubscriptionList.
[in]packetIdpacket ID generated by MQTT_GetPacketId.
[in]remainingLengthRemaining Length provided by MQTT_GetUnsubscribePacketSize.
[out]pFixedBufferBuffer for packet serialization.
Returns
MQTTNoMemory if pFixedBuffer is too small to hold the MQTT packet; MQTTBadParameter if invalid parameters are passed; MQTTSuccess otherwise.

Example

// Variables used in this example.
MQTTStatus_t status;
MQTTSubscribeInfo_t subscriptionList[ NUMBER_OF_SUBSCRIPTIONS ] = { 0 };
MQTTFixedBuffer_t fixedBuffer;
uint8_t buffer[ BUFFER_SIZE ];
size_t remainingLength = 0, packetSize = 0;
uint16_t packetId;
fixedBuffer.pBuffer = buffer;
fixedBuffer.size = BUFFER_SIZE;
// Function to return a valid, unused packet identifier. The details are out of
// scope for this example.
packetId = getNewPacketId();
// Assume subscriptionList has been initialized. Get the unsubscribe packet size.
&subscriptionList[ 0 ], NUMBER_OF_SUBSCRIPTIONS, &remainingLength, &packetSize
);
assert( status == MQTTSuccess );
assert( packetSize <= BUFFER_SIZE );
// Serialize the unsubscribe packet into the fixed buffer.
&subscriptionList[ 0 ],
NUMBER_OF_SUBSCRIPTIONS,
packetId,
remainingLength,
&fixedBuffer
);
if( status == MQTTSuccess )
{
// The unsubscribe packet can now be sent to the broker.
}
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
@ MQTTSuccess
Definition: core_mqtt_serializer.h:100
size_t size
Size of buffer.
Definition: core_mqtt_serializer.h:137
uint8_t * pBuffer
Pointer to buffer.
Definition: core_mqtt_serializer.h:136