AZ_NODISCARD az_result az_iot_hub_client_twin_patch_get_publish_topic()

in sdk/src/azure/iot/az_iot_hub_client_twin.c [70:108]


AZ_NODISCARD az_result az_iot_hub_client_twin_patch_get_publish_topic(
    az_iot_hub_client const* client,
    az_span request_id,
    char* mqtt_topic,
    size_t mqtt_topic_size,
    size_t* out_mqtt_topic_length)
{
  _az_PRECONDITION_NOT_NULL(client);
  _az_PRECONDITION_VALID_SPAN(client->_internal.iot_hub_hostname, 1, false);
  _az_PRECONDITION_VALID_SPAN(request_id, 1, false);
  _az_PRECONDITION_NOT_NULL(mqtt_topic);
  _az_PRECONDITION(mqtt_topic_size > 0);
  (void)client;

  az_span mqtt_topic_span = az_span_create((uint8_t*)mqtt_topic, (int32_t)mqtt_topic_size);
  int32_t required_length = az_span_size(az_iot_hub_twin_topic_prefix)
      + az_span_size(az_iot_hub_twin_patch_pub_topic)
      + (int32_t)sizeof(az_iot_hub_client_twin_question)
      + az_span_size(az_iot_hub_client_request_id_span)
      + (int32_t)sizeof(az_iot_hub_client_twin_equals) + az_span_size(request_id);

  _az_RETURN_IF_NOT_ENOUGH_SIZE(
      mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator));

  az_span remainder = az_span_copy(mqtt_topic_span, az_iot_hub_twin_topic_prefix);
  remainder = az_span_copy(remainder, az_iot_hub_twin_patch_pub_topic);
  remainder = az_span_copy_u8(remainder, az_iot_hub_client_twin_question);
  remainder = az_span_copy(remainder, az_iot_hub_client_request_id_span);
  remainder = az_span_copy_u8(remainder, az_iot_hub_client_twin_equals);
  remainder = az_span_copy(remainder, request_id);
  az_span_copy_u8(remainder, null_terminator);

  if (out_mqtt_topic_length)
  {
    *out_mqtt_topic_length = (size_t)required_length;
  }

  return AZ_OK;
}