_detail::UniquePropertiesHandle _detail::MessagePropertiesFactory::ToImplementation()

in sdk/core/azure-core-amqp/src/models/amqp_properties.cpp [163:378]


  _detail::UniquePropertiesHandle _detail::MessagePropertiesFactory::ToImplementation(
      MessageProperties const& properties)
  {
    UniquePropertiesHandle returnValue(properties_create());
#if ENABLE_UAMQP
    if (!properties.MessageId.IsNull())
    {
      if (properties_set_message_id(
              returnValue.get(), _detail::AmqpValueFactory::ToImplementation(properties.MessageId)))
      {
        throw std::runtime_error("Could not set message id");
      }
    }
    if (!properties.CorrelationId.IsNull())
    {
      if (properties_set_correlation_id(
              returnValue.get(),
              _detail::AmqpValueFactory::ToImplementation(properties.CorrelationId)))
      {
        throw std::runtime_error("Could not set correlation id");
      }
    }

    if (properties.UserId.HasValue())
    {
      amqp_binary value{
          properties.UserId.Value().data(),
          static_cast<uint32_t>(properties.UserId.Value().size())};
      if (properties_set_user_id(returnValue.get(), value))
      {
        throw std::runtime_error("Could not set user id");
      }
    }

    if (!properties.To.IsNull())
    {
      if (properties_set_to(
              returnValue.get(), _detail::AmqpValueFactory::ToImplementation(properties.To)))
      {
        throw std::runtime_error("Could not set to");
      }
    }

    if (properties.Subject.HasValue())
    {
      if (properties_set_subject(returnValue.get(), properties.Subject.Value().data()))
      {
        throw std::runtime_error("Could not set subject");
      }
    }

    if (!properties.ReplyTo.IsNull())
    {
      if (properties_set_reply_to(
              returnValue.get(), _detail::AmqpValueFactory::ToImplementation(properties.ReplyTo)))
      {
        throw std::runtime_error("Could not set reply to");
      }
    }

    if (properties.ContentType.HasValue())
    {
      if (properties_set_content_type(returnValue.get(), properties.ContentType.Value().data()))
      {
        throw std::runtime_error("Could not set content type");
      }
    }

    if (properties.ContentEncoding.HasValue())
    {
      if (properties_set_content_encoding(
              returnValue.get(), properties.ContentEncoding.Value().data()))
      {
        throw std::runtime_error("Could not set content type");
      }
    }

    if (properties.AbsoluteExpiryTime.HasValue())
    {
      auto timeStamp{std::chrono::duration_cast<std::chrono::milliseconds>(
          properties.AbsoluteExpiryTime.Value().time_since_epoch())};

      if (properties_set_absolute_expiry_time(returnValue.get(), timeStamp.count()))
      {
        throw std::runtime_error("Could not set absolute expiry time");
      }
    }

    if (properties.CreationTime.HasValue())
    {
      auto timeStamp{std::chrono::duration_cast<std::chrono::milliseconds>(
          properties.CreationTime.Value().time_since_epoch())};

      if (properties_set_creation_time(returnValue.get(), timeStamp.count()))
      {
        throw std::runtime_error("Could not set absolute expiry time");
      }
    }

    if (properties.GroupId.HasValue())
    {
      if (properties_set_group_id(returnValue.get(), properties.GroupId.Value().data()))
      {
        throw std::runtime_error("Could not set group id");
      }
    }

    if (properties.GroupSequence.HasValue())
    {
      if (properties_set_group_sequence(returnValue.get(), properties.GroupSequence.Value()))
      {
        throw std::runtime_error("Could not set group sequence");
      }
    }

    if (properties.ReplyToGroupId.HasValue())
    {
      if (properties_set_reply_to_group_id(
              returnValue.get(), properties.ReplyToGroupId.Value().data()))
      {
        throw std::runtime_error("Could not set reply-to group id");
      }
    }
#elif ENABLE_RUST_AMQP

    if (!properties.MessageId.IsNull())
    {
      InvokeAmqpApi(
          properties_set_message_id,
          returnValue,
          _detail::AmqpValueFactory::ToImplementation(properties.MessageId));
    }
    if (!properties.CorrelationId.IsNull())
    {
      InvokeAmqpApi(
          properties_set_correlation_id,
          returnValue,
          _detail::AmqpValueFactory::ToImplementation(properties.CorrelationId));
    }

    if (properties.UserId.HasValue())
    {
      InvokeAmqpApi(
          properties_set_user_id,
          returnValue,
          properties.UserId.Value().data(),
          static_cast<uint32_t>(properties.UserId.Value().size()));
    }

    if (!properties.To.IsNull())
    {
      InvokeAmqpApi(
          properties_set_to, returnValue, static_cast<std::string>(properties.To).c_str());
    }

    if (properties.Subject.HasValue())
    {
      InvokeAmqpApi(properties_set_subject, returnValue, properties.Subject.Value().data());
    }

    if (!properties.ReplyTo.IsNull())
    {
      InvokeAmqpApi(
          properties_set_reply_to,
          returnValue,
          _detail::AmqpValueFactory::ToImplementation(properties.ReplyTo));
    }

    if (properties.ContentType.HasValue())
    {
      InvokeAmqpApi(
          properties_set_content_type, returnValue, properties.ContentType.Value().data());
    }

    if (properties.ContentEncoding.HasValue())
    {
      InvokeAmqpApi(
          properties_set_content_encoding, returnValue, properties.ContentEncoding.Value().data());
    }

    if (properties.AbsoluteExpiryTime.HasValue())
    {
      auto timeStamp{std::chrono::duration_cast<std::chrono::milliseconds>(
          properties.AbsoluteExpiryTime.Value().time_since_epoch())};

      InvokeAmqpApi(properties_set_absolute_expiry_time, returnValue, timeStamp.count());
    }

    if (properties.CreationTime.HasValue())
    {
      auto timeStamp{std::chrono::duration_cast<std::chrono::milliseconds>(
          properties.CreationTime.Value().time_since_epoch())};

      InvokeAmqpApi(properties_set_creation_time, returnValue, timeStamp.count());
    }

    if (properties.GroupId.HasValue())
    {
      InvokeAmqpApi(properties_set_group_id, returnValue, properties.GroupId.Value().data());
    }

    if (properties.GroupSequence.HasValue())
    {
      InvokeAmqpApi(properties_set_group_sequence, returnValue, properties.GroupSequence.Value());
    }

    if (properties.ReplyToGroupId.HasValue())
    {
      InvokeAmqpApi(
          properties_set_reply_to_group_id, returnValue, properties.ReplyToGroupId.Value().data());
    }

#endif

    return returnValue;
  }