coreMQTT v5.0.0
MQTT 5.0 Client Library
 
Loading...
Searching...
No Matches
core_mqtt_prop_serializer.c File Reference

Implements the user-facing functions to serialize user-properties. More...

#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <inttypes.h>
#include "core_mqtt_serializer.h"
#include "private/core_mqtt_serializer_private.h"
#include "core_mqtt_config_defaults.h"

Functions

static bool isValidPropertyInPacketType (const uint8_t *mqttPacketType, uint8_t propBitLocation)
 Check whether the provided property is allowed for a packet type.
 
static MQTTStatus_t addPropUint8 (MQTTPropBuilder_t *pPropertyBuilder, uint8_t property, uint8_t propId, uint8_t fieldPosition, const uint8_t *pOptionalMqttPacketType)
 Add a uint8 property to the property builder.
 
static MQTTStatus_t addPropUint16 (MQTTPropBuilder_t *pPropertyBuilder, uint16_t property, uint8_t propId, uint8_t fieldPosition, const uint8_t *pOptionalMqttPacketType)
 Add a uint16 property to the property builder.
 
static MQTTStatus_t addPropUint32 (MQTTPropBuilder_t *pPropertyBuilder, uint32_t property, uint8_t propId, uint8_t fieldPosition, const uint8_t *pOptionalMqttPacketType)
 Add a uint32 property to the property builder.
 
static MQTTStatus_t addPropUtf8 (MQTTPropBuilder_t *pPropertyBuilder, const char *property, size_t propertyLength, uint8_t propId, uint8_t fieldPosition, const uint8_t *pOptionalMqttPacketType)
 Add a UTF-8 string property to the property builder.
 
MQTTStatus_t MQTTPropAdd_SubscriptionId (MQTTPropBuilder_t *pPropertyBuilder, uint32_t subscriptionId, const uint8_t *pOptionalMqttPacketType)
 Adds a Subscription Identifier property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_UserProp (MQTTPropBuilder_t *pPropertyBuilder, const MQTTUserProperty_t *userProperty, const uint8_t *pOptionalMqttPacketType)
 Adds User Property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_SessionExpiry (MQTTPropBuilder_t *pPropertyBuilder, uint32_t sessionExpiry, const uint8_t *pOptionalMqttPacketType)
 Adds Session Expiry Interval property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_ReceiveMax (MQTTPropBuilder_t *pPropertyBuilder, uint16_t receiveMax, const uint8_t *pOptionalMqttPacketType)
 Adds Receive Maximum property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_MaxPacketSize (MQTTPropBuilder_t *pPropertyBuilder, uint32_t maxPacketSize, const uint8_t *pOptionalMqttPacketType)
 Adds Maximum Packet Size property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_TopicAliasMax (MQTTPropBuilder_t *pPropertyBuilder, uint16_t topicAliasMax, const uint8_t *pOptionalMqttPacketType)
 Adds Topic Alias Maximum property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_RequestRespInfo (MQTTPropBuilder_t *pPropertyBuilder, bool requestResponseInfo, const uint8_t *pOptionalMqttPacketType)
 Adds Request Response Information property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_RequestProbInfo (MQTTPropBuilder_t *pPropertyBuilder, bool requestProblemInfo, const uint8_t *pOptionalMqttPacketType)
 Adds Request Problem Information property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_AuthMethod (MQTTPropBuilder_t *pPropertyBuilder, const char *authMethod, size_t authMethodLength, const uint8_t *pOptionalMqttPacketType)
 Adds Authentication Method property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_AuthData (MQTTPropBuilder_t *pPropertyBuilder, const char *authData, size_t authDataLength, const uint8_t *pOptionalMqttPacketType)
 Adds Authentication Data property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_PayloadFormat (MQTTPropBuilder_t *pPropertyBuilder, bool payloadFormat, const uint8_t *pOptionalMqttPacketType)
 Adds Payload Format Indicator property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_MessageExpiry (MQTTPropBuilder_t *pPropertyBuilder, uint32_t messageExpiry, const uint8_t *pOptionalMqttPacketType)
 Adds Message Expiry Interval property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_WillDelayInterval (MQTTPropBuilder_t *pPropertyBuilder, uint32_t willDelayInterval, const uint8_t *pOptionalMqttPacketType)
 Adds Will Delay Interval property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_TopicAlias (MQTTPropBuilder_t *pPropertyBuilder, uint16_t topicAlias, const uint8_t *pOptionalMqttPacketType)
 Adds Topic Alias property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_ResponseTopic (MQTTPropBuilder_t *pPropertyBuilder, const char *responseTopic, size_t responseTopicLength, const uint8_t *pOptionalMqttPacketType)
 Adds Response Topic property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_CorrelationData (MQTTPropBuilder_t *pPropertyBuilder, const void *pCorrelationData, size_t correlationLength, const uint8_t *pOptionalMqttPacketType)
 Adds Correlation Data property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_ContentType (MQTTPropBuilder_t *pPropertyBuilder, const char *contentType, size_t contentTypeLength, const uint8_t *pOptionalMqttPacketType)
 Adds Content Type property to the MQTT property builder.
 
MQTTStatus_t MQTTPropAdd_ReasonString (MQTTPropBuilder_t *pPropertyBuilder, const char *pReasonString, size_t reasonStringLength, const uint8_t *pOptionalMqttPacketType)
 Adds Reason String property to the MQTT property builder.
 

Detailed Description

Implements the user-facing functions to serialize user-properties.

Function Documentation

◆ isValidPropertyInPacketType()

static bool isValidPropertyInPacketType ( const uint8_t *  mqttPacketType,
uint8_t  propBitLocation 
)
static

Check whether the provided property is allowed for a packet type.

Parameters
[in]mqttPacketTypePacket type to check.
[in]propBitLocationBit location of the property.
Returns
Whether the property is allowed for the packet type.

◆ addPropUint8()

static MQTTStatus_t addPropUint8 ( MQTTPropBuilder_t pPropertyBuilder,
uint8_t  property,
uint8_t  propId,
uint8_t  fieldPosition,
const uint8_t *  pOptionalMqttPacketType 
)
static

Add a uint8 property to the property builder.

This function adds a uint8 property to the property builder with validation for packet type compatibility and buffer space.

Parameters
[in,out]pPropertyBuilderPointer to the property builder to add the property to.
[in]propertyThe uint8 property value to add.
[in]propIdThe property ID for this property.
[in]fieldPositionThe bit position in the fieldSet for duplicate checking.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for validation. Can be NULL to skip packet type validation.
Returns
MQTTSuccess if the property is successfully added; MQTTBadParameter if parameters are invalid; MQTTNoMemory if insufficient buffer space.

◆ addPropUint16()

static MQTTStatus_t addPropUint16 ( MQTTPropBuilder_t pPropertyBuilder,
uint16_t  property,
uint8_t  propId,
uint8_t  fieldPosition,
const uint8_t *  pOptionalMqttPacketType 
)
static

Add a uint16 property to the property builder.

This function adds a uint16 property to the property builder with validation for packet type compatibility and buffer space.

Parameters
[in,out]pPropertyBuilderPointer to the property builder to add the property to.
[in]propertyThe uint16 property value to add.
[in]propIdThe property ID for this property.
[in]fieldPositionThe bit position in the fieldSet for duplicate checking.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for validation. Can be NULL to skip packet type validation.
Returns
MQTTSuccess if the property is successfully added; MQTTBadParameter if parameters are invalid; MQTTNoMemory if insufficient buffer space.

◆ addPropUint32()

static MQTTStatus_t addPropUint32 ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  property,
uint8_t  propId,
uint8_t  fieldPosition,
const uint8_t *  pOptionalMqttPacketType 
)
static

Add a uint32 property to the property builder.

This function adds a uint32 property to the property builder with validation for packet type compatibility and buffer space.

Parameters
[in,out]pPropertyBuilderPointer to the property builder to add the property to.
[in]propertyThe uint32 property value to add.
[in]propIdThe property ID for this property.
[in]fieldPositionThe bit position in the fieldSet for duplicate checking.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for validation. Can be NULL to skip packet type validation.
Returns
MQTTSuccess if the property is successfully added; MQTTBadParameter if parameters are invalid; MQTTNoMemory if insufficient buffer space.

◆ addPropUtf8()

static MQTTStatus_t addPropUtf8 ( MQTTPropBuilder_t pPropertyBuilder,
const char *  property,
size_t  propertyLength,
uint8_t  propId,
uint8_t  fieldPosition,
const uint8_t *  pOptionalMqttPacketType 
)
static

Add a UTF-8 string property to the property builder.

This function adds a UTF-8 string property to the property builder with validation for packet type compatibility and buffer space.

Parameters
[in,out]pPropertyBuilderPointer to the property builder to add the property to.
[in]propertyThe UTF-8 string property value to add.
[in]propertyLengthThe length of the UTF-8 string property.
[in]propIdThe property ID for this property.
[in]fieldPositionThe bit position in the fieldSet for duplicate checking.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for validation. Can be NULL to skip packet type validation.
Returns
MQTTSuccess if the property is successfully added; MQTTBadParameter if parameters are invalid; MQTTNoMemory if insufficient buffer space.

◆ MQTTPropAdd_SubscriptionId()

MQTTStatus_t MQTTPropAdd_SubscriptionId ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  subscriptionId,
const uint8_t *  pOptionalMqttPacketType 
)

Adds a Subscription Identifier property to the MQTT property builder.

This function adds a Subscription Identifier property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure where the Subscription Identifier will be added. Must not be NULL.
[in]subscriptionIdThe Subscription Identifier value to be added. Must be greater than 0.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:
  • MQTTSuccess if the Subscription Identifier was successfully added
  • MQTTBadParameter if pPropertyBuilder is NULL or subscriptionId is 0
  • MQTTNoMemory if the property builder has insufficient space

Example

// Variables used in this example.
MQTTStatus_t status;
MQTTPropBuilder_t propertyBuilder ; // Assume this is initialized properly
uint32_t subscriptionId = 12345;
// Add Subscription Identifier to property builder
status = MQTTPropAdd_SubscriptionId(&propertyBuilder, subscriptionId, &(uint8_t){ MQTT_PACKET_TYPE_SUBSCRIBE });
if(status == MQTTSuccess)
{
// Subscription Identifier successfully added
}
MQTTStatus_t MQTTPropAdd_SubscriptionId(MQTTPropBuilder_t *pPropertyBuilder, uint32_t subscriptionId, const uint8_t *pOptionalMqttPacketType)
Adds a Subscription Identifier property to the MQTT property builder.
Definition: core_mqtt_prop_serializer.c:613
#define MQTT_PACKET_TYPE_SUBSCRIBE
SUBSCRIBE (client-to-server).
Definition: core_mqtt_serializer.h:60
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:239
@ MQTTSuccess
Definition: core_mqtt_serializer.h:240
Property builder for MQTT packets.
Definition: core_mqtt_serializer.h:470
Note
This property is only valid for MQTT v5.0 and above.
The Subscription Identifier can be used in SUBSCRIBE packets and will be returned in matched PUBLISH packets.

◆ MQTTPropAdd_UserProp()

MQTTStatus_t MQTTPropAdd_UserProp ( MQTTPropBuilder_t pPropertyBuilder,
const MQTTUserProperty_t userProperty,
const uint8_t *  pOptionalMqttPacketType 
)

Adds User Property to the MQTT property builder.

This function adds User Property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]userPropertyThe User Property to be added.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_SessionExpiry()

MQTTStatus_t MQTTPropAdd_SessionExpiry ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  sessionExpiry,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Session Expiry Interval property to the MQTT property builder.

This function adds Session Expiry Interval property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]sessionExpiryThe Session Expiry Interval in seconds.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for validation. Can be NULL to skip packet type validation.
Returns
Returns one of the following:

◆ MQTTPropAdd_ReceiveMax()

MQTTStatus_t MQTTPropAdd_ReceiveMax ( MQTTPropBuilder_t pPropertyBuilder,
uint16_t  receiveMax,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Receive Maximum property to the MQTT property builder.

This function adds Receive Maximum property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]receiveMaxThe maximum number of QoS 1 and QoS 2 messages allowed to be received simultaneously.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_MaxPacketSize()

MQTTStatus_t MQTTPropAdd_MaxPacketSize ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  maxPacketSize,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Maximum Packet Size property to the MQTT property builder.

This function adds Maximum Packet Size property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]maxPacketSizeThe maximum packet size the client is willing to accept.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_TopicAliasMax()

MQTTStatus_t MQTTPropAdd_TopicAliasMax ( MQTTPropBuilder_t pPropertyBuilder,
uint16_t  topicAliasMax,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Topic Alias Maximum property to the MQTT property builder.

This function adds Topic Alias Maximum property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]topicAliasMaxThe maximum value of topic alias accepted by the client.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_RequestRespInfo()

MQTTStatus_t MQTTPropAdd_RequestRespInfo ( MQTTPropBuilder_t pPropertyBuilder,
bool  requestResponseInfo,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Request Response Information property to the MQTT property builder.

This function adds Request Response Information property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]requestResponseInfoBoolean indicating whether response information is requested.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_RequestProbInfo()

MQTTStatus_t MQTTPropAdd_RequestProbInfo ( MQTTPropBuilder_t pPropertyBuilder,
bool  requestProblemInfo,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Request Problem Information property to the MQTT property builder.

This function adds Request Problem Information property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]requestProblemInfoBoolean indicating whether problem information is requested.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_AuthMethod()

MQTTStatus_t MQTTPropAdd_AuthMethod ( MQTTPropBuilder_t pPropertyBuilder,
const char *  authMethod,
size_t  authMethodLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Authentication Method property to the MQTT property builder.

This function adds Authentication Method property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]authMethodPointer to the authentication method string.
[in]authMethodLengthLength of the authentication method string (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_AuthData()

MQTTStatus_t MQTTPropAdd_AuthData ( MQTTPropBuilder_t pPropertyBuilder,
const char *  authData,
size_t  authDataLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Authentication Data property to the MQTT property builder.

This function adds Authentication Data property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]authDataPointer to the authentication data.
[in]authDataLengthLength of the authentication data (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_PayloadFormat()

MQTTStatus_t MQTTPropAdd_PayloadFormat ( MQTTPropBuilder_t pPropertyBuilder,
bool  payloadFormat,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Payload Format Indicator property to the MQTT property builder.

This function adds Payload Format Indicator property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]payloadFormatBoolean indicating the payload format (true for UTF-8, false for unspecified bytes).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_MessageExpiry()

MQTTStatus_t MQTTPropAdd_MessageExpiry ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  messageExpiry,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Message Expiry Interval property to the MQTT property builder.

This function adds Message Expiry Interval property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]messageExpiryThe message expiry interval in seconds.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_WillDelayInterval()

MQTTStatus_t MQTTPropAdd_WillDelayInterval ( MQTTPropBuilder_t pPropertyBuilder,
uint32_t  willDelayInterval,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Will Delay Interval property to the MQTT property builder.

This function adds Message Expiry Interval property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]willDelayIntervalWill Delay Interval in seconds.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_TopicAlias()

MQTTStatus_t MQTTPropAdd_TopicAlias ( MQTTPropBuilder_t pPropertyBuilder,
uint16_t  topicAlias,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Topic Alias property to the MQTT property builder.

This function adds Topic Alias property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]topicAliasThe topic alias value.
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_ResponseTopic()

MQTTStatus_t MQTTPropAdd_ResponseTopic ( MQTTPropBuilder_t pPropertyBuilder,
const char *  responseTopic,
size_t  responseTopicLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Response Topic property to the MQTT property builder.

This function adds Response Topic property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]responseTopicPointer to the response topic string.
[in]responseTopicLengthLength of the response topic string (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_CorrelationData()

MQTTStatus_t MQTTPropAdd_CorrelationData ( MQTTPropBuilder_t pPropertyBuilder,
const void *  pCorrelationData,
size_t  correlationLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Correlation Data property to the MQTT property builder.

This function adds Correlation Data property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]pCorrelationDataPointer to the correlation data.
[in]correlationLengthLength of the correlation data (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_ContentType()

MQTTStatus_t MQTTPropAdd_ContentType ( MQTTPropBuilder_t pPropertyBuilder,
const char *  contentType,
size_t  contentTypeLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Content Type property to the MQTT property builder.

This function adds Content Type property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]contentTypePointer to the content type string.
[in]contentTypeLengthLength of the content type string (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following:

◆ MQTTPropAdd_ReasonString()

MQTTStatus_t MQTTPropAdd_ReasonString ( MQTTPropBuilder_t pPropertyBuilder,
const char *  pReasonString,
size_t  reasonStringLength,
const uint8_t *  pOptionalMqttPacketType 
)

Adds Reason String property to the MQTT property builder.

This function adds Reason String property to the property builder.

Parameters
[out]pPropertyBuilderPointer to the property builder structure.
[in]pReasonStringPointer to the reason string.
[in]reasonStringLengthLength of the reason string (must be less than 65536).
[in]pOptionalMqttPacketTypeOptional MQTT packet type for which the property is being added. The function will check whether the given property can be added to the packet type if it is provided.
Returns
Returns one of the following: