uint16_t packetId,
uint32_t remainingLength,
MQTTStatus_t MQTT_SerializePublish(const MQTTPublishInfo_t *pPublishInfo, const MQTTPropBuilder_t *pPublishProperties, uint16_t packetId, uint32_t remainingLength, const MQTTFixedBuffer_t *pFixedBuffer)
Serialize an MQTT PUBLISH packet in the given buffer.
Definition: core_mqtt_serializer.c:3949
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:239
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:284
Property builder for MQTT packets.
Definition: core_mqtt_serializer.h:470
MQTT PUBLISH packet parameters.
Definition: core_mqtt_serializer.h:395
Serialize an MQTT PUBLISH packet in the given buffer.
This function will serialize complete MQTT PUBLISH packet into the given buffer. If the PUBLISH payload can be sent separately, consider using MQTT_SerializePublishHeader, which will serialize only the PUBLISH header into the buffer.
MQTT_GetPublishPacketSize should be called with pPublishInfo before invoking this function to get the size of the required MQTTFixedBuffer_t and remainingLength. The remainingLength must be the same as returned by MQTT_GetPublishPacketSize. The MQTTFixedBuffer_t must be at least as large as the size returned by MQTT_GetPublishPacketSize.
- Parameters
-
| [in] | pPublishInfo | MQTT PUBLISH packet parameters. |
| [in] | pPublishProperties | MQTT v5.0 properties for the PUBLISH packet. Can be NULL if no properties are needed. |
| [in] | packetId | packet ID generated by MQTT_GetPacketId. |
| [in] | remainingLength | Remaining Length provided by MQTT_GetPublishPacketSize. |
| [out] | pFixedBuffer | Buffer for packet serialization. |
- Returns
- MQTTNoMemory if pFixedBuffer is too small to hold the MQTT packet; MQTTBadParameter if invalid parameters are passed; MQTTSuccess otherwise.
Example
uint8_t buffer[ BUFFER_SIZE ];
size_t remainingLength = 0, packetSize = 0;
uint16_t packetId;
fixedBuffer.
size = BUFFER_SIZE;
packetId = 0;
&publishInfo, &publishProperties, &remainingLength, &packetSize
);
assert( packetSize <= BUFFER_SIZE );
&publishInfo,
&publishProperties,
packetId,
remainingLength,
&fixedBuffer
);
{
}
MQTTStatus_t MQTT_GetPublishPacketSize(const MQTTPublishInfo_t *pPublishInfo, const MQTTPropBuilder_t *pPublishProperties, uint32_t *pRemainingLength, uint32_t *pPacketSize, uint32_t maxPacketSize)
Get the packet size and remaining length of an MQTT PUBLISH packet.
Definition: core_mqtt_serializer.c:3889
@ MQTTSuccess
Definition: core_mqtt_serializer.h:240
size_t size
Size of buffer.
Definition: core_mqtt_serializer.h:286
uint8_t * pBuffer
Pointer to buffer.
Definition: core_mqtt_serializer.h:285