MQTT API Reference
MQTT 3.1.1 client library
IotMqtt_GetIncomingMQTTPacketTypeAndLength

Extract MQTT packet type and length from incoming packet.

IotMqttGetNextByte_t getNextByte,
void * pNetworkConnection );
Parameters
[in,out]pIncomingPacketPointer to IotMqttPacketInfo_t structure where type, remaining length and packet identifier are stored.
[in]getNextBytePointer to platform specific function which is used to extract type and length from incoming received stream (see example ).
[in]pNetworkConnectionPointer to platform specific network connection which is used by getNextByte to receive network data
Returns
IOT_MQTT_SUCCESS on successful extraction of type and length, IOT_MQTT_BAD_RESPONSE on failure.
Note
This call is part of serializer API used for implementing light-weight MQTT client.

Example

// Example code below shows how to implement getNetxByte function with posix sockets.
// Note: IotMqttGetNextByte_t typedef IotMqttError_t (* IotMqttGetNextByte_t)( void * pNetworkContext,
// uint8_t * pNextByte );
// Note: It is assumed that socket is already created and connected,
IotMqttError_t getNextByte( void * pContext,
uint8_t * pNextByte )
{
int socket = ( int ) ( *pvContext );
int receivedBytes;
receivedBytes = recv( socket, ( void * ) pNextByte, sizeof( uint8_t ), 0 );
if( receivedBytes == sizeof( uint8_t ) )
{
result = IOT_MQTT_SUCCESS;
}
else
{
result = IOT_MQTT_TIMEOUT;
}
return result;
}
// Example below shows how IotMqtt_GetIncomingMQTTPacketTypeAndLength() is used to extract type
// and length from incoming ping response.
// xMQTTSocket here is posix socket created and connected to MQTT broker outside of this function.
void getTypeAndLengthFromIncomingMQTTPingResponse( int xMQTTSocket )
{
IotMqttPacketInfo_t xIncomingPacket;
IotMqttError_t xResult = IotMqtt_GetIncomingMQTTPacketTypeAndLength( &xIncomingPacket, getNextByte, ( void * ) xMQTTSocket );
}
IotMqttPacketInfo_t::type
uint8_t type
(Input) A value identifying the packet type.
Definition: iot_mqtt_types.h:699
IOT_MQTT_TIMEOUT
A blocking MQTT operation timed out.
Definition: iot_mqtt_types.h:217
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
MQTT_PACKET_TYPE_PINGRESP
#define MQTT_PACKET_TYPE_PINGRESP
PINGRESP (server-to-client).
Definition: iot_mqtt_internal.h:271
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
IotMqttPacketInfo_t
MQTT packet details.
Definition: iot_mqtt_types.h:694
IotMqttGetNextByte_t
IotMqttError_t(* IotMqttGetNextByte_t)(void *pNetworkContext, uint8_t *pNextByte)
Function pointer to read the next available byte on a network connection.
Definition: iot_mqtt_types.h:826
IotMqtt_Assert
#define IotMqtt_Assert(expression)
Assertion macro for the MQTT library.
Definition: iot_mqtt_internal.h:62