MQTT API Reference
MQTT 3.1.1 client library
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
{
}
}
IotMqttPacketInfo_t::type
uint8_t type
(Input) A value identifying the packet type.
Definition: iot_mqtt_types.h:699
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
IotMqttPublishInfo_t::pPayload
const void * pPayload
Payload of PUBLISH.
Definition: iot_mqtt_types.h:396
IotMqttPacketInfo_t::pRemainingData
uint8_t * pRemainingData
(Input) The remaining data in MQTT packet.
Definition: iot_mqtt_types.h:696
IOT_MQTT_SUCCESS
MQTT operation completed successfully.
Definition: iot_mqtt_types.h:119
IotMqttPublishInfo_t::topicNameLength
uint16_t topicNameLength
Length of IotMqttPublishInfo_t.pTopicName.
Definition: iot_mqtt_types.h:394
IotMqtt_GetIncomingMQTTPacketTypeAndLength
IotMqttError_t IotMqtt_GetIncomingMQTTPacketTypeAndLength(IotMqttPacketInfo_t *pIncomingPacket, IotMqttGetNextByte_t getNextByte, void *pNetworkConnection)
Extract MQTT packet type and length from incoming packet.
Definition: iot_mqtt_network.c:847
IotMqttPublishInfo_t::pTopicName
const char * pTopicName
Topic name of PUBLISH.
Definition: iot_mqtt_types.h:393
IotMqttPacketInfo_t
MQTT packet details.
Definition: iot_mqtt_types.h:694
IotLogInfo
#define IotLogInfo(...)
IotMqttPublishInfo_t::qos
IotMqttQos_t qos
QoS of message. Must be 0 or 1.
Definition: iot_mqtt_types.h:390
IotMqttPacketInfo_t::remainingLength
size_t remainingLength
(Input) Length of the remaining data in the MQTT packet.
Definition: iot_mqtt_types.h:697
IOT_MQTT_NETWORK_ERROR
MQTT operation failed because the network was unusable.
Definition: iot_mqtt_types.h:177
MQTT_PACKET_TYPE_PUBLISH
#define MQTT_PACKET_TYPE_PUBLISH
PUBLISH (bi-directional).
Definition: iot_mqtt_internal.h:264
IotMqttPacketInfo_t::pubInfo
IotMqttPublishInfo_t pubInfo
(Output) Publish info in case of deserializing PUBLISH.
Definition: iot_mqtt_types.h:700
IotMqttPublishInfo_t::payloadLength
size_t payloadLength
Length of IotMqttPublishInfo_t.pPayload. For LWT messages, this is limited to 65535.
Definition: iot_mqtt_types.h:397
IotMqtt_DeserializePublish
IotMqttError_t IotMqtt_DeserializePublish(IotMqttPacketInfo_t *pMqttPacket)
Deserialize incoming publish packet.
Definition: iot_mqtt_serialize.c:2500
IOT_MQTT_BAD_RESPONSE
MQTT response packet received from the network is malformed.
Definition: iot_mqtt_types.h:205
IotMqtt_Assert
#define IotMqtt_Assert(expression)
Assertion macro for the MQTT library.
Definition: iot_mqtt_internal.h:62