// third_party/blink/public/mojom/ai/ai_semantic_embedder.mojom-shared.h is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_PUBLIC_MOJOM_AI_AI_SEMANTIC_EMBEDDER_MOJOM_SHARED_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_AI_AI_SEMANTIC_EMBEDDER_MOJOM_SHARED_H_

#include <stdint.h>

#include <functional>
#include <iosfwd>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/array_data_view.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/system/message_pipe.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "third_party/blink/public/mojom/ai/ai_semantic_embedder.mojom-shared-internal.h"
#include "third_party/blink/public/mojom/ai/ai_common.mojom-shared.h"
#include "mojo/public/cpp/bindings/lib/interface_serialization.h"
#include "mojo/public/cpp/system/data_pipe.h"



#include "third_party/blink/public/mojom/ai/ai_semantic_embedder.mojom-data-view.h"  // IWYU pragma: export
#include "base/component_export.h"




namespace std {

template <>
struct hash<::blink::mojom::AISemanticEmbedderTaskType>
    : public mojo::internal::EnumHashImpl<::blink::mojom::AISemanticEmbedderTaskType> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::AISemanticEmbedderTaskType, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::blink::mojom::AISemanticEmbedderTaskType, UserType>;

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    auto known_value = ::mojo::internal::ToKnownEnumValueHelper(
        static_cast<::blink::mojom::AISemanticEmbedderTaskType>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::blink::mojom::AISemanticEmbedderTaskType, UserType> ||
                        HasInfallibleConversion(::blink::mojom::AISemanticEmbedderTaskType()),
                    "::blink::mojom::AISemanticEmbedderTaskType does not have an infallible conversion, "
                    "use an optional return type.");
      *output = Traits::FromMojom(known_value);
      return true;
    } else {
      static_assert(
          requires {
            {
              Traits::FromMojom(known_value)
            } -> std::same_as<std::optional<UserType>>;
          }, "FromMojom must return by value or optional.");
      std::optional<UserType> from_mojom = Traits::FromMojom(known_value);
      if (from_mojom) {
        *output = *from_mojom;
      }
      return from_mojom.has_value();
    }
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::AISemanticEmbedderEmbedOptionsDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::blink::mojom::AISemanticEmbedderEmbedOptionsDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::blink::mojom::internal::AISemanticEmbedderEmbedOptions_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();
    fragment->task_type_$flag = Traits::task_type(input).has_value();
    if (Traits::task_type(input).has_value()) {
      
      mojo::internal::Serialize<::blink::mojom::AISemanticEmbedderTaskType>(
        Traits::task_type(input).value(),
        &fragment->task_type_$value);
    } else {
      fragment->task_type_$value =
          static_cast<int32_t>(::blink::mojom::AISemanticEmbedderTaskType::kMinValue);
    }
  }

  static bool Deserialize(::blink::mojom::internal::AISemanticEmbedderEmbedOptions_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::blink::mojom::AISemanticEmbedderEmbedOptionsDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::ContentEmbeddingDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::blink::mojom::ContentEmbeddingDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::blink::mojom::internal::ContentEmbedding_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();

    decltype(Traits::values(input)) in_values = Traits::values(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->values)::BaseType>
        values_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& values_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<float>>(
      in_values,
      values_fragment,
      &values_validate_params);

    fragment->values.Set(
        values_fragment.is_null() ? nullptr : values_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->values.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null values in ContentEmbedding struct");
  }

  static bool Deserialize(::blink::mojom::internal::ContentEmbedding_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::blink::mojom::ContentEmbeddingDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::blink::mojom::SemanticEmbedderResultDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::blink::mojom::SemanticEmbedderResultDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::blink::mojom::internal::SemanticEmbedderResult_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();

    decltype(Traits::embeddings(input)) in_embeddings = Traits::embeddings(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->embeddings)::BaseType>
        embeddings_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& embeddings_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<::blink::mojom::ContentEmbeddingDataView>>(
      in_embeddings,
      embeddings_fragment,
      &embeddings_validate_params);

    fragment->embeddings.Set(
        embeddings_fragment.is_null() ? nullptr : embeddings_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->embeddings.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null embeddings in SemanticEmbedderResult struct");
  }

  static bool Deserialize(::blink::mojom::internal::SemanticEmbedderResult_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::blink::mojom::SemanticEmbedderResultDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal

}  // namespace mojo


namespace blink::mojom {



inline void ContentEmbeddingDataView::GetValuesDataView(
    mojo::ArrayDataView<float>* output) {
  auto pointer = data_->values.Get();
  *output = mojo::ArrayDataView<float>(pointer, message_);
}


inline void SemanticEmbedderResultDataView::GetEmbeddingsDataView(
    mojo::ArrayDataView<ContentEmbeddingDataView>* output) {
  auto pointer = data_->embeddings.Get();
  *output = mojo::ArrayDataView<ContentEmbeddingDataView>(pointer, message_);
}



}  // blink::mojom

// Declare TraceFormatTraits for enums, which should be defined in ::perfetto
// namespace.

namespace perfetto {

template <>
struct COMPONENT_EXPORT(MOJOM_SHARED_BLINK_COMMON_EXPORT) TraceFormatTraits<::blink::mojom::AISemanticEmbedderTaskType> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::blink::mojom::AISemanticEmbedderTaskType value);
};

} // namespace perfetto

#endif  // THIRD_PARTY_BLINK_PUBLIC_MOJOM_AI_AI_SEMANTIC_EMBEDDER_MOJOM_SHARED_H_