coreMQTT  v1.0.0
MQTT 3.1.1 Client Library
MQTT_DeserializePublish

Deserialize an MQTT PUBLISH packet.

uint16_t * pPacketId,
MQTTPublishInfo_t * pPublishInfo );
Parameters
[in]pIncomingPacketMQTTPacketInfo_t containing the buffer.
[out]pPacketIdThe packet ID obtained from the buffer.
[out]pPublishInfoStruct containing information about the publish.
Returns
MQTTBadParameter, MQTTBadResponse, or MQTTSuccess.

Example

// TransportRecv_t function for reading from the network.
int32_t socket_recv(
NetworkContext_t * pNetworkContext,
void * pBuffer,
size_t bytesToRecv
);
// Some context to be used with the above transport receive function.
NetworkContext_t networkContext;
// Other variables used in this example.
MQTTStatus_t status;
MQTTPacketInfo_t incomingPacket;
MQTTPublishInfo_t publishInfo = { 0 };
uint16_t packetId;
int32_t bytesRecvd;
// A buffer to hold remaining data of the incoming packet.
uint8_t buffer[ BUFFER_SIZE ];
// Populate all fields of the incoming packet.
socket_recv,
&networkContext,
&incomingPacket
);
assert( status == MQTTSuccess );
assert( incomingPacket.remainingLength <= BUFFER_SIZE );
bytesRecvd = socket_recv(
&networkContext,
( void * ) buffer,
incomingPacket.remainingLength
);
incomingPacket.pRemainingData = buffer;
// Deserialize the publish information if the incoming packet is a publish.
if( ( incomingPacket.type & 0xF0 ) == MQTT_PACKET_TYPE_PUBLISH )
{
status = MQTT_DeserializePublish( &incomingPacket, &packetId, &publishInfo );
if( status == MQTTSuccess )
{
// The deserialized publish information can now be used from `publishInfo`.
}
}
MQTTPacketInfo_t::pRemainingData
uint8_t * pRemainingData
Remaining serialized data in the MQTT packet.
Definition: core_mqtt_serializer.h:268
MQTTPacketInfo_t
MQTT incoming packet parameters.
Definition: core_mqtt_serializer.h:259
NetworkContext_t
struct NetworkContext NetworkContext_t
The NetworkContext is an incomplete type. An implementation of this interface must define struct Netw...
Definition: transport_interface.h:155
MQTTStatus_t
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:105
MQTT_PACKET_TYPE_PUBLISH
#define MQTT_PACKET_TYPE_PUBLISH
PUBLISH (bidirectional).
Definition: core_mqtt_serializer.h:73
MQTT_DeserializePublish
MQTTStatus_t MQTT_DeserializePublish(const MQTTPacketInfo_t *pIncomingPacket, uint16_t *pPacketId, MQTTPublishInfo_t *pPublishInfo)
Deserialize an MQTT PUBLISH packet.
Definition: core_mqtt_serializer.c:2225
MQTTPacketInfo_t::type
uint8_t type
Type of incoming MQTT packet.
Definition: core_mqtt_serializer.h:263
MQTTSuccess
@ MQTTSuccess
Definition: core_mqtt_serializer.h:106
MQTTPublishInfo_t
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:217
MQTTPacketInfo_t::remainingLength
size_t remainingLength
Length of remaining serialized data.
Definition: core_mqtt_serializer.h:273
MQTT_GetIncomingPacketTypeAndLength
MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength(TransportRecv_t readFunc, const NetworkContext_t *pNetworkContext, MQTTPacketInfo_t *pIncomingPacket)
Extract the MQTT packet type and length from incoming packet.
Definition: core_mqtt_serializer.c:2338