MQTT API Reference
MQTT 3.1.1 client library
IotMqtt_GetConnectPacketSize

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

size_t * pRemainingLength,
size_t * pPacketSize );
Parameters
[in]pConnectInfoUser-provided CONNECT 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_GetConnectPacketSize() should be used to calculate
// the size of connect request.
IotMqttConnectInfo_t xConnectInfo;
size_t xRemainingLength = 0;
size_t xPacketSize = 0;
// start with everything set to zero
memset( ( void * ) &xConnectInfo, 0x00, sizeof( xConnectInfo ) );
// Initialize connection info, details are out of scope for this example.
_initializeConnectInfo( &xConnectInfo );
// Get size requirement for the connect packet
xResult = IotMqtt_GetConnectPacketSize( &xConnectInfo, &xRemainingLength, &xPacketSize );
// Application should allocate buffer with size == xPacketSize or use static buffer
// with size >= xPacketSize to serialize connect request.
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_GetConnectPacketSize
IotMqttError_t IotMqtt_GetConnectPacketSize(const IotMqttConnectInfo_t *pConnectInfo, size_t *pRemainingLength, size_t *pPacketSize)
Calculate the size and "Remaining length" of a CONNECT packet generated from the given parameters.
Definition: iot_mqtt_serialize.c:2134
IotMqtt_Assert
#define IotMqtt_Assert(expression)
Assertion macro for the MQTT library.
Definition: iot_mqtt_internal.h:62
IotMqttConnectInfo_t
MQTT connection details.
Definition: iot_mqtt_types.h:576