AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqtt_DeserializePublish

Deserialize incoming publish packet.

Parameters
[in,out]pMqttPacketThe caller of this API sets type, remainingLength and pRemainingData. On success, packetIdentifier and pubInfo will be set by the function.
Returns
One of the following:
Note
This call is part of serializer API used for implementing light-weight MQTT client.

Example

// Example below shows how IotMqtt_DeserializePublish() used to extract contents of incoming
// Publish. xMQTTSocket here is posix socket created and connected to MQTT broker outside of this function.
void processIncomingPublish( int xMQTTSocket )
{
IotMqttError_t xResult;
IotMqttPacketInfo_t xIncomingPacket;
xResult = IotMqtt_GetIncomingMQTTPacketTypeAndLength( &xIncomingPacket, getNextByte, ( void * ) xMQTTSocket );
IotMqtt_Assert( ( xIncomingPacket.type & 0xf0 ) == MQTT_PACKET_TYPE_PUBLISH );
IotMqtt_Assert( xIncomingPacket.remainingLength <= mqttexampleSHARED_BUFFER_SIZE );
// Receive the remaining bytes.
if( recv( xMQTTSocket, ( void * ) ucSharedBuffer, xIncomingPacket.remainingLength, 0 ) == xIncomingPacket.remainingLength )
{
xIncomingPacket.pRemainingData = ucSharedBuffer;
if( IotMqtt_DeserializePublish( &xIncomingPacket ) != IOT_MQTT_SUCCESS )
{
}
else
{
// Process incoming Publish.
IotLogInfo( "Incoming QOS : %d\n", xIncomingPacket.pubInfo.qos );
IotLogInfo( "Incoming Publish Topic Name: %.*s\n", xIncomingPacket.pubInfo.topicNameLength, xIncomingPacket.pubInfo.pTopicName );
IotLogInfo( "Incoming Publish Message : %.*s\n", xIncomingPacket.pubInfo.payloadLength, xIncomingPacket.pubInfo.pPayload );
}
}
else
{
}
}