MQTT-C
Data Structures | Enumerations | Functions
Control Packet Deserialization

Developer documentation of the functions and datastructures used for deserializing MQTT control packets. More...

Data Structures

struct  mqtt_fixed_header
 The fixed header of an MQTT control packet. More...
 
struct  mqtt_response_connack
 A connection response datastructure. More...
 
struct  mqtt_response_publish
 A publish packet received from the broker.A publish packet is received from the broker when a client publishes to a topic that the {local client} is subscribed to. More...
 
struct  mqtt_response_puback
 A publish acknowledgement for messages that were published with QoS level 1. More...
 
struct  mqtt_response_pubrec
 The response packet to a PUBLISH packet with QoS level 2. More...
 
struct  mqtt_response_pubrel
 The response to a PUBREC packet. More...
 
struct  mqtt_response_pubcomp
 The response to a PUBREL packet. More...
 
struct  mqtt_response_suback
 The response to a subscription request. More...
 
struct  mqtt_response_unsuback
 The brokers response to a UNSUBSCRIBE request. More...
 
struct  mqtt_response_pingresp
 The response to a ping request. More...
 
struct  mqtt_response
 A struct used to deserialize/interpret an incoming packet from the broker. More...
 

Enumerations

enum  MQTTControlPacketType {
  MQTT_CONTROL_CONNECT =1u, MQTT_CONTROL_CONNACK =2u, MQTT_CONTROL_PUBLISH =3u, MQTT_CONTROL_PUBACK =4u,
  MQTT_CONTROL_PUBREC =5u, MQTT_CONTROL_PUBREL =6u, MQTT_CONTROL_PUBCOMP =7u, MQTT_CONTROL_SUBSCRIBE =8u,
  MQTT_CONTROL_SUBACK =9u, MQTT_CONTROL_UNSUBSCRIBE =10u, MQTT_CONTROL_UNSUBACK =11u, MQTT_CONTROL_PINGREQ =12u,
  MQTT_CONTROL_PINGRESP =13u, MQTT_CONTROL_DISCONNECT =14u
}
 An enumeration of the MQTT control packet types. More...
 
enum  MQTTConnackReturnCode {
  MQTT_CONNACK_ACCEPTED = 0u, MQTT_CONNACK_REFUSED_PROTOCOL_VERSION = 1u, MQTT_CONNACK_REFUSED_IDENTIFIER_REJECTED = 2u, MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE = 3u,
  MQTT_CONNACK_REFUSED_BAD_USER_NAME_OR_PASSWORD = 4u, MQTT_CONNACK_REFUSED_NOT_AUTHORIZED = 5u
}
 An enumeration of the return codes returned in a CONNACK packet. More...
 
enum  MQTTSubackReturnCodes { MQTT_SUBACK_SUCCESS_MAX_QOS_0 = 0u, MQTT_SUBACK_SUCCESS_MAX_QOS_1 = 1u, MQTT_SUBACK_SUCCESS_MAX_QOS_2 = 2u, MQTT_SUBACK_FAILURE = 128u }
 An enumeration of subscription acknowledgement return codes. More...
 

Functions

ssize_t mqtt_unpack_fixed_header (struct mqtt_response *response, const uint8_t *buf, size_t bufsz)
 Deserialize the contents of buf into an mqtt_fixed_header object. More...
 
ssize_t mqtt_unpack_connack_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 Deserialize a CONNACK response from buf. More...
 
ssize_t mqtt_unpack_publish_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 Deserialize a publish response from buf. More...
 
ssize_t mqtt_unpack_pubxxx_response (struct mqtt_response *mqtt_response, const uint8_t *buf)
 Deserialize a PUBACK/PUBREC/PUBREL/PUBCOMP packet from buf. More...
 
ssize_t mqtt_unpack_response (struct mqtt_response *response, const uint8_t *buf, size_t bufsz)
 Deserialize a packet from the broker. More...
 

Detailed Description

Developer documentation of the functions and datastructures used for deserializing MQTT control packets.

Enumeration Type Documentation

◆ MQTTConnackReturnCode

An enumeration of the return codes returned in a CONNACK packet.

See also
MQTT v3.1.1: CONNACK return codes.

◆ MQTTControlPacketType

An enumeration of the MQTT control packet types.

See also
MQTT v3.1.1: MQTT Control Packet Types

◆ MQTTSubackReturnCodes

An enumeration of subscription acknowledgement return codes.

See also
MQTT v3.1.1: SUBACK Return Codes.

Function Documentation

◆ mqtt_unpack_connack_response()

ssize_t mqtt_unpack_connack_response ( struct mqtt_response mqtt_response,
const uint8_t *  buf 
)
related

Deserialize a CONNACK response from buf.

Precondition
mqtt_unpack_fixed_header must have returned a positive value and the control packet type must be MQTT_CONTROL_CONNACK.
Parameters
[out]mqtt_responsethe mqtt_response that will be initialized.
[in]bufthe buffer that contains the variable header and payload of the packet. The first byte of buf should be the first byte of the variable header.
Returns
The number of bytes that were consumed, or 0 if the buffer does not contain enough bytes to parse the packet, or a negative value if there was a protocol violation.

◆ mqtt_unpack_fixed_header()

ssize_t mqtt_unpack_fixed_header ( struct mqtt_response response,
const uint8_t *  buf,
size_t  bufsz 
)

Deserialize the contents of buf into an mqtt_fixed_header object.

Note
This function performs complete error checking and a positive return value means the entire mqtt_response can be deserialized from buf.
Parameters
[out]responsethe response who's mqtt_response::fixed_header will be initialized.
[in]bufthe buffer.
[in]bufszthe total number of bytes in the buffer.
Returns
The number of bytes that were consumed, or 0 if the buffer does not contain enough bytes to parse the packet, or a negative value if there was a protocol violation.

◆ mqtt_unpack_publish_response()

ssize_t mqtt_unpack_publish_response ( struct mqtt_response mqtt_response,
const uint8_t *  buf 
)
related

Deserialize a publish response from buf.

Precondition
mqtt_unpack_fixed_header must have returned a positive value and the mqtt_response must have a control type of MQTT_CONTROL_PUBLISH.
Parameters
[out]mqtt_responsethe response that is initialized from the contents of buf.
[in]bufthe buffer with the incoming data.
Returns
The number of bytes that were consumed, or 0 if the buffer does not contain enough bytes to parse the packet, or a negative value if there was a protocol violation.

◆ mqtt_unpack_pubxxx_response()

ssize_t mqtt_unpack_pubxxx_response ( struct mqtt_response mqtt_response,
const uint8_t *  buf 
)
related

Deserialize a PUBACK/PUBREC/PUBREL/PUBCOMP packet from buf.

Precondition
mqtt_unpack_fixed_header must have returned a positive value and the mqtt_response must have a control type of MQTT_CONTROL_PUBACK, MQTT_CONTROL_PUBREC, MQTT_CONTROL_PUBREL or MQTT_CONTROL_PUBCOMP.
Parameters
[out]mqtt_responsethe response that is initialized from the contents of buf.
[in]bufthe buffer with the incoming data.

mqtt_response_pubrec mqtt_response_pubrel mqtt_response_pubcomp

Returns
The number of bytes that were consumed, or 0 if the buffer does not contain enough bytes to parse the packet, or a negative value if there was a protocol violation.

◆ mqtt_unpack_response()

ssize_t mqtt_unpack_response ( struct mqtt_response response,
const uint8_t *  buf,
size_t  bufsz 
)
related

Deserialize a packet from the broker.

Parameters
[out]responsethe mqtt_response that will be initialize from buf.
[in]bufthe incoming data buffer.
[in]bufszthe number of bytes available in the buffer.
Returns
The number of bytes consumed on success, zero buf does not contain enough bytes to deserialize the packet, a negative value if a protocol violation was encountered.