// components/metrics/private_metrics/mojom/private_metrics_interface.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 COMPONENTS_METRICS_PRIVATE_METRICS_MOJOM_PRIVATE_METRICS_INTERFACE_MOJOM_SHARED_H_
#define COMPONENTS_METRICS_PRIVATE_METRICS_MOJOM_PRIVATE_METRICS_INTERFACE_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 "components/metrics/private_metrics/mojom/private_metrics_interface.mojom-shared-internal.h"




#include "components/metrics/private_metrics/mojom/private_metrics_interface.mojom-data-view.h"  // IWYU pragma: export




namespace std {

template <>
struct hash<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type>
    : public mojo::internal::EnumHashImpl<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type, 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<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type, UserType> ||
                        HasInfallibleConversion(::metrics::private_metrics::mojom::PrivateMetricsEntry_Type()),
                    "::metrics::private_metrics::mojom::PrivateMetricsEntry_Type 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<::metrics::private_metrics::mojom::PrivateMetricsEntryDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::metrics::private_metrics::mojom::PrivateMetricsEntryDataView, UserType>;

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

    fragment->event_hash = Traits::event_hash(input);
    fragment->content_hash_$flag = Traits::content_hash(input).has_value();
    if (Traits::content_hash(input).has_value()) {
      fragment->content_hash_$value = Traits::content_hash(input).value();
    }

    decltype(Traits::studies_of_interest(input)) in_studies_of_interest = Traits::studies_of_interest(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->studies_of_interest)::BaseType>
        studies_of_interest_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& studies_of_interest_validate_params =
        mojo::internal::GetMapValidator<*&mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>(), *&mojo::internal::GetArrayValidator<0, false, nullptr>()>();
    
    mojo::internal::Serialize<mojo::MapDataView<mojo::StringDataView, bool>>(
      in_studies_of_interest,
      studies_of_interest_fragment,
      &studies_of_interest_validate_params);

    fragment->studies_of_interest.Set(
        studies_of_interest_fragment.is_null() ? nullptr : studies_of_interest_fragment.data());

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

    
    mojo::internal::Serialize<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type>(
      Traits::type(input),
      &fragment->type);
  }

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

    ::metrics::private_metrics::mojom::PrivateMetricsEntryDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal

}  // namespace mojo


namespace metrics::private_metrics::mojom {

inline void PrivateMetricsEntryDataView::GetStudiesOfInterestDataView(
    mojo::MapDataView<mojo::StringDataView, bool>* output) {
  auto pointer = data_->studies_of_interest.Get();
  *output = mojo::MapDataView<mojo::StringDataView, bool>(pointer, message_);
}



}  // metrics::private_metrics::mojom

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

namespace perfetto {

template <>
struct  TraceFormatTraits<::metrics::private_metrics::mojom::PrivateMetricsEntry_Type> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::metrics::private_metrics::mojom::PrivateMetricsEntry_Type value);
};

} // namespace perfetto

#endif  // COMPONENTS_METRICS_PRIVATE_METRICS_MOJOM_PRIVATE_METRICS_INTERFACE_MOJOM_SHARED_H_