Implements private functions used by serializer and deserializer. DO NOT use these functions in your application. More...
#include <string.h>#include <assert.h>#include <stdbool.h>#include <inttypes.h>#include "core_mqtt_serializer.h"#include "private/core_mqtt_serializer_private.h"#include "core_mqtt_config_defaults.h"Macros | |
| #define | MQTT_VERSION_5 ( 5U ) |
| Version 5 has the value 5. | |
Functions | |
| uint32_t | variableLengthEncodedSize (uint32_t length) |
| Retrieve the size of the remaining length if it were to be encoded. | |
| uint8_t * | encodeString (uint8_t *pDestination, const char *pSource, uint16_t sourceLength) |
| Encode a string whose size is at maximum 16 bits in length. | |
| 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. | |
| MQTTStatus_t | decodeUint32t (uint32_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex) |
| Validate the length and decode a 4 byte value. | |
| MQTTStatus_t | decodeUint16t (uint16_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex) |
| Validate the length and decode a 2 byte value. | |
| MQTTStatus_t | decodeUint8t (uint8_t *pProperty, uint32_t *pPropertyLength, bool *pUsed, uint8_t **pIndex) |
| Validate the length and decode a 1 byte value. | |
| 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. | |
| 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. | |
| 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 MQTT 5.0 specification. | |
| 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. | |
| 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. | |
| uint8_t * | serializeSubscribeHeader (uint32_t remainingLength, uint8_t *pIndex, uint16_t packetId) |
| Serialize the fixed part of the subscribe packet header. | |
| uint8_t * | serializeUnsubscribeHeader (uint32_t remainingLength, uint8_t *pIndex, uint16_t packetId) |
| Serialize the fixed part of the unsubscribe packet header. | |
| uint8_t * | serializeDisconnectFixed (uint8_t *pIndex, const MQTTSuccessFailReasonCode_t *pReasonCode, uint32_t remainingLength) |
| Serialize the fixed size part of the disconnect packet header. | |
| MQTTStatus_t | decodeSubackPropertyLength (const uint8_t *pIndex, uint32_t remainingLength, uint32_t *subackPropertyLength) |
| Decodes the property length field in a SUBACK packet. | |
Implements private functions used by serializer and deserializer. DO NOT use these functions in your application.
| uint32_t variableLengthEncodedSize | ( | uint32_t | length | ) |
Retrieve the size of the remaining length if it were to be encoded.
| [in] | length | The remaining length to be encoded. |
| uint8_t * encodeString | ( | uint8_t * | pDestination, |
| const char * | pSource, | ||
| uint16_t | sourceLength | ||
| ) |
Encode a string whose size is at maximum 16 bits in length.
| [out] | pDestination | Destination buffer for the encoding. |
| [in] | pSource | The source string to encode. |
| [in] | sourceLength | The length of the source string to encode. |
| 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.
| [out] | pPropertyKey | To store the decoded key. |
| [out] | pPropertyKeyLen | To store the decoded key length. |
| [out] | pPropertyValue | To store the decoded value. |
| [out] | pPropertyValueLen | To store the decoded value length. |
| [in,out] | pPropertyLength | Value of the remaining property length. |
| [in,out] | pIndex | Pointer to the current index of the buffer. |
| MQTTStatus_t decodeUint32t | ( | uint32_t * | pProperty, |
| uint32_t * | pPropertyLength, | ||
| bool * | pUsed, | ||
| uint8_t ** | pIndex | ||
| ) |
Validate the length and decode a 4 byte value.
| [out] | pProperty | To store the decoded property. |
| [in,out] | pPropertyLength | Value of the remaining property length. |
| [in,out] | pUsed | Whether the property is decoded before. |
| [in,out] | pIndex | Pointer to the current index of the buffer. |
| MQTTStatus_t decodeUint16t | ( | uint16_t * | pProperty, |
| uint32_t * | pPropertyLength, | ||
| bool * | pUsed, | ||
| uint8_t ** | pIndex | ||
| ) |
Validate the length and decode a 2 byte value.
| [out] | pProperty | To store the decoded property. |
| [in,out] | pPropertyLength | Value of the remaining property length. |
| [in,out] | pUsed | Whether the property is decoded before. |
| [in,out] | pIndex | Pointer to the current index of the buffer. |
| MQTTStatus_t decodeUint8t | ( | uint8_t * | pProperty, |
| uint32_t * | pPropertyLength, | ||
| bool * | pUsed, | ||
| uint8_t ** | pIndex | ||
| ) |
Validate the length and decode a 1 byte value.
| [out] | pProperty | To store the decoded property. |
| [in,out] | pPropertyLength | Value of the remaining property length. |
| [in,out] | pUsed | Whether the property is decoded before. |
| [in,out] | pIndex | Pointer to the current index of the buffer. |
| 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.
| [out] | pProperty | To store the decoded string. |
| [out] | pLength | Size of the decoded utf-8 string. |
| [in,out] | pPropertyLength | Value of the remaining property length. |
| [in,out] | pUsed | Whether the property is decoded before. |
| [in,out] | pIndex | Pointer to the current index of the buffer. |
| 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.
Uses the algorithm provided in the spec.
| [in] | pBuffer | Pointer to the buffer. |
| [in] | bufferLength | Length of the remaining buffer. |
| [out] | pLength | Decoded variable length |
| 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 MQTT 5.0 specification.
| [out] | pDestination | The destination buffer to store the encoded remaining length. |
| [in] | length | The remaining length to encode. |
| 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.
| [out] | pIndex | Pointer to the buffer where the header is to be serialized. |
| [in] | packetType | Type of publish ack |
| [in] | packetId | Packed identifier of the ack packet. |
| [in] | remainingLength | Remaining length of the ack packet. |
| [in] | reasonCode | Reason code for the ack packet. |
| 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.
| [out] | pIndex | Pointer to the buffer where the header is to be serialized. |
| [in] | pConnectInfo | The connect information. |
| [in] | pWillInfo | The last will and testament information. |
| [in] | remainingLength | The remaining length of the packet to be serialized. |
| uint8_t * serializeSubscribeHeader | ( | uint32_t | remainingLength, |
| uint8_t * | pIndex, | ||
| uint16_t | packetId | ||
| ) |
Serialize the fixed part of the subscribe packet header.
| [in] | remainingLength | The remaining length of the packet to be serialized. |
| [in] | pIndex | Pointer to the buffer where the header is to be serialized. |
| [in] | packetId | The packet ID to be serialized. |
| uint8_t * serializeUnsubscribeHeader | ( | uint32_t | remainingLength, |
| uint8_t * | pIndex, | ||
| uint16_t | packetId | ||
| ) |
Serialize the fixed part of the unsubscribe packet header.
| [in] | remainingLength | The remaining length of the packet to be serialized. |
| [in] | pIndex | Pointer to the buffer where the header is to be serialized. |
| [in] | packetId | The packet ID to be serialized. |
| uint8_t * serializeDisconnectFixed | ( | uint8_t * | pIndex, |
| const MQTTSuccessFailReasonCode_t * | pReasonCode, | ||
| uint32_t | remainingLength | ||
| ) |
Serialize the fixed size part of the disconnect packet header.
| [out] | pIndex | Pointer to the buffer where the header is to be serialized. |
| [in] | pReasonCode | Reason code for the disconnect packet. |
| [in] | remainingLength | Remaining length of the disconnect packet. |
| MQTTStatus_t decodeSubackPropertyLength | ( | const uint8_t * | pIndex, |
| uint32_t | remainingLength, | ||
| uint32_t * | subackPropertyLength | ||
| ) |
Decodes the property length field in a SUBACK packet.
| [in] | pIndex | Pointer to the start of the properties in the SUBACK packet. |
| [in] | remainingLength | The remaining length of the MQTT packet being parsed, without Packet ID. |
| [out] | subackPropertyLength | The decoded property length including the size of its encoded representation. |