coreMQTT v5.0.0
MQTT 5.0 Client Library
 
Loading...
Searching...
No Matches
MQTT_SerializeConnect
const MQTTPublishInfo_t * pWillInfo,
const MQTTPropBuilder_t * pConnectProperties,
const MQTTPropBuilder_t * pWillProperties,
uint32_t remainingLength,
const MQTTFixedBuffer_t * pFixedBuffer );
MQTTStatus_t MQTT_SerializeConnect(const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, const MQTTPropBuilder_t *pConnectProperties, const MQTTPropBuilder_t *pWillProperties, uint32_t remainingLength, const MQTTFixedBuffer_t *pFixedBuffer)
Serialize an MQTT CONNECT packet in the given fixed buffer pFixedBuffer.
Definition: core_mqtt_serializer.c:3428
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:239
MQTT CONNECT packet parameters.
Definition: core_mqtt_serializer.h:294
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:284
Property builder for MQTT packets.
Definition: core_mqtt_serializer.h:470
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:395

Serialize an MQTT CONNECT packet in the given fixed buffer pFixedBuffer.

MQTT_GetConnectPacketSize should be called with pConnectInfo, pWillInfo, pConnectProperties, and pWillProperties 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_GetConnectPacketSize. The MQTTFixedBuffer_t must be at least as large as the size returned by MQTT_GetConnectPacketSize.

Parameters
[in]pConnectInfoMQTT CONNECT packet parameters.
[in]pWillInfoLast Will and Testament. Pass NULL if not used.
[in]pConnectPropertiesMQTT CONNECT properties builder. Pass NULL if not used.
[in]pWillPropertiesMQTT Will properties builder. Pass NULL if not used.
[in]remainingLengthRemaining Length provided by MQTT_GetConnectPacketSize.
[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;
MQTTConnectInfo_t connectInfo = { 0 };
MQTTPublishInfo_t willInfo = { 0 };
MQTTPropBuilder_t connectionProperties = { 0 };
MQTTPropBuilder_t willProperties = { 0 };
MQTTFixedBuffer_t fixedBuffer;
uint8_t buffer[ BUFFER_SIZE ];
size_t remainingLength = 0, packetSize = 0;
fixedBuffer.pBuffer = buffer;
fixedBuffer.size = BUFFER_SIZE;
// Assume connectInfo, willInfo, and properties are initialized.
// Get the size requirement for the connect packet.
&connectInfo, &willInfo, &connectionProperties, &willProperties,
&remainingLength, &packetSize
);
assert( status == MQTTSuccess );
assert( packetSize <= BUFFER_SIZE );
// Serialize the connect packet into the fixed buffer.
&connectInfo,
&willInfo,
&connectionProperties,
&willProperties,
remainingLength,
&fixedBuffer
);
if( status == MQTTSuccess )
{
// The connect packet can now be sent to the broker.
}
MQTTStatus_t MQTT_GetConnectPacketSize(const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, const MQTTPropBuilder_t *pConnectProperties, const MQTTPropBuilder_t *pWillProperties, uint32_t *pRemainingLength, uint32_t *pPacketSize)
Get the size and Remaining Length of an MQTT Version 5 CONNECT packet.
Definition: core_mqtt_serializer.c:3097
@ MQTTSuccess
Definition: core_mqtt_serializer.h:240
size_t size
Size of buffer.
Definition: core_mqtt_serializer.h:286
uint8_t * pBuffer
Pointer to buffer.
Definition: core_mqtt_serializer.h:285