35#ifndef CORE_MQTT_SERIALIZER_PRIVATE_H
36#define CORE_MQTT_SERIALIZER_PRIVATE_H
57#define MQTT_SUBSCRIPTION_ID_POS ( 1 )
63#define MQTT_SESSION_EXPIRY_INTERVAL_POS ( 2 )
69#define MQTT_RECEIVE_MAXIMUM_POS ( 3 )
75#define MQTT_MAX_PACKET_SIZE_POS ( 4 )
81#define MQTT_TOPIC_ALIAS_MAX_POS ( 5 )
87#define MQTT_REQUEST_RESPONSE_INFO_POS ( 6 )
93#define MQTT_REQUEST_PROBLEM_INFO_POS ( 7 )
99#define MQTT_AUTHENTICATION_METHOD_POS ( 9 )
105#define MQTT_AUTHENTICATION_DATA_POS ( 10 )
111#define MQTT_PAYLOAD_FORMAT_INDICATOR_POS ( 11 )
117#define MQTT_MESSAGE_EXPIRY_INTERVAL_POS ( 12 )
123#define MQTT_TOPIC_ALIAS_POS ( 13 )
129#define MQTT_RESPONSE_TOPIC_POS ( 14 )
135#define MQTT_CORRELATION_DATA_POS ( 15 )
141#define MQTT_CONTENT_TYPE_POS ( 16 )
147#define MQTT_REASON_STRING_POS ( 17 )
153#define MQTT_WILL_DELAY_POS ( 18 )
159#define MQTT_ASSIGNED_CLIENT_ID_POS ( 19 )
165#define MQTT_SERVER_KEEP_ALIVE_POS ( 20 )
171#define MQTT_RESPONSE_INFORMATION_POS ( 21 )
177#define MQTT_SERVER_REFERENCE_POS ( 22 )
183#define MQTT_MAX_QOS_POS ( 23 )
189#define MQTT_RETAIN_AVAILABLE_POS ( 24 )
195#define MQTT_WILDCARD_SUBSCRIPTION_AVAILABLE_POS ( 25 )
201#define MQTT_SUBSCRIPTION_ID_AVAILABLE_POS ( 26 )
207#define MQTT_SHARED_SUBSCRIPTION_AVAILABLE_POS ( 27 )
213#define MQTT_USER_PROP_POS ( 28 )
216#define MQTT_CONNECT_FLAG_CLEAN ( 1 )
217#define MQTT_CONNECT_FLAG_WILL ( 2 )
218#define MQTT_CONNECT_FLAG_WILL_QOS1 ( 3 )
219#define MQTT_CONNECT_FLAG_WILL_QOS2 ( 4 )
220#define MQTT_CONNECT_FLAG_WILL_RETAIN ( 5 )
221#define MQTT_CONNECT_FLAG_PASSWORD ( 6 )
222#define MQTT_CONNECT_FLAG_USERNAME ( 7 )
229#define UINT32_DECODE( ptr ) \
230 ( uint32_t ) ( ( ( ( uint32_t ) ptr[ 0 ] ) << 24 ) | \
231 ( ( ( uint32_t ) ptr[ 1 ] ) << 16 ) | \
232 ( ( ( uint32_t ) ptr[ 2 ] ) << 8 ) | \
233 ( ( uint32_t ) ptr[ 3 ] ) )
239#define WRITE_UINT32( addr, val ) \
241 ( addr )[ 3 ] = ( uint8_t ) ( ( ( val ) >> 0 ) & 0xFFU ); \
242 ( addr )[ 2 ] = ( uint8_t ) ( ( ( val ) >> 8 ) & 0xFFU ); \
243 ( addr )[ 1 ] = ( uint8_t ) ( ( ( val ) >> 16 ) & 0xFFU ); \
244 ( addr )[ 0 ] = ( uint8_t ) ( ( ( val ) >> 24 ) & 0xFFU ); \
250#define UINT8_SET_BIT( x, position ) ( ( x ) = ( uint8_t ) ( ( x ) | ( 0x01U << ( position ) ) ) )
255#define UINT8_CLEAR_BIT( x, position ) ( ( x ) = ( uint8_t ) ( ( x ) & ( ~( 0x01U << ( position ) ) ) ) )
263#define UINT8_CHECK_BIT( x, position ) ( ( ( x ) & ( 0x01U << ( position ) ) ) == ( 0x01U << ( position ) ) )
268#define UINT16_HIGH_BYTE( x ) ( ( uint8_t ) ( ( x ) >> 8 ) )
273#define UINT16_LOW_BYTE( x ) ( ( uint8_t ) ( ( x ) & 0x00ffU ) )
280#define UINT16_DECODE( ptr ) \
281 ( uint16_t ) ( ( ( ( uint16_t ) ptr[ 0 ] ) << 8 ) | \
282 ( ( uint16_t ) ptr[ 1 ] ) )
287#define UINT32_SET_BIT( x, position ) \
288 ( ( x ) = ( uint32_t ) ( ( x ) | ( ( uint32_t ) 0x01U << ( position ) ) ) )
296#define UINT32_CHECK_BIT( x, position ) \
297 ( ( ( uint32_t ) ( x ) & ( ( uint32_t ) 0x01U << ( position ) ) ) == ( ( uint32_t ) 0x01U << ( position ) ) )
303#define MQTT_MAX_REMAINING_LENGTH ( 268435455U )
310#define MQTT_REMAINING_LENGTH_INVALID ( ( uint32_t ) MQTT_MAX_REMAINING_LENGTH + 1U )
318#define MQTT_MAX_PACKET_SIZE ( MQTT_MAX_REMAINING_LENGTH + 5U )
323#define MQTT_MAX_UTF8_STR_LENGTH ( ( uint32_t ) 65535 )
329#define MAX_VARIABLE_LENGTH_INT_VALUE ( ( uint32_t ) 268435455U )
337#if ( SIZE_MAX >= UINT32_MAX )
338 #define CHECK_U32T_OVERFLOWS_SIZE_T( x ) false
340 #define CHECK_U32T_OVERFLOWS_SIZE_T( x ) ( ( x ) > SIZE_MAX )
349#if ( 65535U >= SIZE_MAX )
350 #define CHECK_SIZE_T_OVERFLOWS_16BIT( x ) false
352 #define CHECK_SIZE_T_OVERFLOWS_16BIT( x ) ( ( x ) > 65535U )
361#if ( 0xFFFFFFFFU >= SIZE_MAX )
362 #define CHECK_SIZE_T_OVERFLOWS_32BIT( x ) false
364 #define CHECK_SIZE_T_OVERFLOWS_32BIT( x ) ( ( x ) > 0xFFFFFFFFU )
372#define ADDITION_WILL_OVERFLOW_U32( x, y ) \
373 ( ( x ) > ( UINT32_MAX - ( y ) ) )
380#define ADDITION_WILL_OVERFLOW_SIZE_T( x, y ) \
381 ( ( x ) > ( SIZE_MAX - ( y ) ) )
419 const char * pSource,
420 uint16_t sourceLength );
443 size_t * pPropertyKeyLen,
444 const char ** pPropertyValue,
445 size_t * pPropertyValueLen,
446 uint32_t * pPropertyLength,
468 uint32_t * pPropertyLength,
491 uint32_t * pPropertyLength,
514 uint32_t * pPropertyLength,
560 uint32_t * pPropertyLength,
585 uint32_t * pLength );
610 uint32_t remainingLength,
632 uint32_t remainingLength,
633 uint32_t * subackPropertyLength );
654 uint32_t remainingLength );
678 uint32_t remainingLength );
User-facing functions for serializing and deserializing MQTT 5.0 packets. This header should be inclu...
uint8_t * encodeVariableLength(uint8_t *pDestination, uint32_t length)
Encodes the remaining length of the packet using the variable length encoding scheme provided in the ...
Definition: core_mqtt_serializer_private.c:415
uint8_t * serializeUnsubscribeHeader(uint32_t remainingLength, uint8_t *pIndex, uint16_t packetId)
Serialize the fixed part of the unsubscribe packet header.
Definition: core_mqtt_serializer_private.c:580
MQTTStatus_t decodeUint32t(uint32_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex)
Validate the length and decode a 4 byte value.
Definition: core_mqtt_serializer_private.c:164
MQTTStatus_t decodeUtf8(const char **pProperty, size_t *pLength, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex)
Validate the length and decode a utf 8 string.
Definition: core_mqtt_serializer_private.c:287
MQTTStatus_t decodeUint16t(uint16_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex)
Validate the length and decode a 2 byte value.
Definition: core_mqtt_serializer_private.c:205
uint32_t variableLengthEncodedSize(uint32_t length)
Retrieve the size of the remaining length if it were to be encoded.
Definition: core_mqtt_serializer_private.c:52
uint8_t * serializeSubscribeHeader(uint32_t remainingLength, uint8_t *pIndex, uint16_t packetId)
Serialize the fixed part of the subscribe packet header.
Definition: core_mqtt_serializer_private.c:556
MQTTStatus_t decodeUint8t(uint8_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex)
Validate the length and decode a 1 byte value.
Definition: core_mqtt_serializer_private.c:246
uint8_t * serializeDisconnectFixed(uint8_t *pIndex, const MQTTSuccessFailReasonCode_t *pReasonCode, uint32_t remainingLength)
Serialize the fixed size part of the disconnect packet header.
Definition: core_mqtt_serializer_private.c:604
uint8_t * encodeString(uint8_t *pDestination, const char *pSource, uint16_t sourceLength)
Encode a string whose size is at maximum 16 bits in length.
Definition: core_mqtt_serializer_private.c:91
uint8_t * serializeAckFixed(uint8_t *pIndex, uint8_t packetType, uint16_t packetId, uint32_t remainingLength, MQTTSuccessFailReasonCode_t reasonCode)
Serialize the fixed size part of the ack packet header.
Definition: core_mqtt_serializer_private.c:449
uint8_t * serializeConnectFixedHeader(uint8_t *pIndex, const MQTTConnectInfo_t *pConnectInfo, const MQTTPublishInfo_t *pWillInfo, uint32_t remainingLength)
Serialize the fixed part of the connect packet header.
Definition: core_mqtt_serializer_private.c:474
MQTTStatus_t decodeVariableLength(const uint8_t *pBuffer, size_t bufferLength, uint32_t *pLength)
Decodes the variable length by reading a single byte at a time.
Definition: core_mqtt_serializer_private.c:341
MQTTStatus_t decodeSubackPropertyLength(const uint8_t *pIndex, uint32_t remainingLength, uint32_t *subackPropertyLength)
Decodes the property length field in a SUBACK packet.
Definition: core_mqtt_serializer_private.c:630
MQTTStatus_t decodeUserProp(const char **pPropertyKey, size_t *pPropertyKeyLen, const char **pPropertyValue, size_t *pPropertyValueLen, uint32_t *pPropertyLength, uint8_t **pIndex)
Validate the length and decode a user property.
Definition: core_mqtt_serializer_private.c:123
MQTTSuccessFailReasonCode_t
MQTT reason codes.
Definition: core_mqtt_serializer.h:583
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:239
MQTT CONNECT packet parameters.
Definition: core_mqtt_serializer.h:294
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:395