in src/mqtt_message.c [46:76]
MQTT_MESSAGE_HANDLE mqttmessage_create_in_place(uint16_t packetId, const char* topicName, QOS_VALUE qosValue, const uint8_t* appMsg, size_t appMsgLength)
{
/* Codes_SRS_MQTTMESSAGE_07_026: [If the parameters topicName is NULL then mqttmessage_create_in_place shall return NULL.].] */
MQTT_MESSAGE* result;
if (topicName == NULL)
{
LogError("Invalid Parameter topicName: %p, packetId: %d.", topicName, packetId);
result = NULL;
}
else
{
result = create_msg_object(packetId, qosValue);
if (result == NULL)
{
/* Codes_SRS_MQTTMESSAGE_07_028: [If any memory allocation fails mqttmessage_create_in_place shall free any allocated memory and return NULL.] */
LogError("Failure creating message object");
}
else
{
/* Codes_SRS_MQTTMESSAGE_07_027: [mqttmessage_create_in_place shall use the a pointer to topicName or appMsg .] */
result->const_topic_name = topicName;
result->const_payload.length = appMsgLength;
if (result->const_payload.length > 0)
{
result->const_payload.message = (uint8_t*)appMsg;
}
}
}
/* Codes_SRS_MQTTMESSAGE_07_029: [ Upon success, mqttmessage_create_in_place shall return a NON-NULL MQTT_MESSAGE_HANDLE value.] */
return (MQTT_MESSAGE_HANDLE)result;
}