// third_party/blink/public/mojom/remote_objects/remote_objects.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_REMOTE_OBJECTS_REMOTE_OBJECTS_MOJOM_SHARED_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_REMOTE_OBJECTS_REMOTE_OBJECTS_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/remote_objects/remote_objects.mojom-shared-internal.h"
#include "mojo/public/mojom/base/big_buffer.mojom-shared.h"
#include "mojo/public/mojom/base/string16.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/remote_objects/remote_objects.mojom-data-view.h"  // IWYU pragma: export
#include "base/component_export.h"




namespace std {

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

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

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

}  // namespace std

namespace mojo {


namespace internal {

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

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

    
    mojo::internal::Serialize<::blink::mojom::RemoteArrayType>(
      Traits::type(input),
      &fragment->type);

    decltype(Traits::buffer(input)) in_buffer = Traits::buffer(input);
    mojo::internal::MessageFragment<decltype(fragment->buffer)>
        buffer_fragment(fragment.message());
    buffer_fragment.Claim(&fragment->buffer);
    
    mojo::internal::Serialize<::mojo_base::mojom::BigBufferDataView>(
      in_buffer,
      buffer_fragment,
      true);

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

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

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

}  // namespace internal


namespace internal {

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

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

    
    mojo::internal::Serialize<::blink::mojom::RemoteInvocationError>(
      Traits::error(input),
      &fragment->error);

    decltype(Traits::value(input)) in_value = Traits::value(input);
    mojo::internal::MessageFragment<decltype(fragment->value)>
        value_fragment(fragment.message());
    value_fragment.Claim(&fragment->value);
    
    mojo::internal::Serialize<::blink::mojom::RemoteInvocationResultValueDataView>(
      in_value,
      value_fragment,
      true);
  }

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

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

}  // namespace internal


namespace internal {

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

  static void Serialize(MaybeConstUserType& input,
                        MessageFragment<::blink::mojom::internal::RemoteInvocationArgument_Data>& fragment,
                        bool inlined) {
    
    if (CallIsNullIfExists<Traits>(input)) {
       if (inlined)
        fragment->set_null();
      return;
    }

if (!inlined)
  fragment.Allocate();

    // TODO(azani): Handle unknown and objects.
    // Set the not-null flag.
fragment->size = kUnionDataSize;
fragment->tag = Traits::GetTag(input);
switch (fragment->tag) {
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kNumberValue: {
    decltype(Traits::number_value(input))
    in_number_value = Traits::number_value(input);
    fragment->data.f_number_value = in_number_value;
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kBooleanValue: {
    decltype(Traits::boolean_value(input))
    in_boolean_value = Traits::boolean_value(input);
    fragment->data.f_boolean_value = in_boolean_value;
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kStringValue: {
    decltype(Traits::string_value(input))
    in_string_value = Traits::string_value(input);
    mojo::internal::MessageFragment<
      typename decltype(fragment->data.f_string_value)::BaseType>
    value_fragment(fragment.message());
        
mojo::internal::Serialize<::mojo_base::mojom::String16DataView>(
  in_string_value,
  value_fragment);
  
MOJO_INTERNAL_CHECK_SERIALIZATION(
  mojo::internal::SendValidation::kDefault,
  !(value_fragment.is_null()),
  mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
  "null string_value in RemoteInvocationArgument union");
    fragment->data.f_string_value.Set(
      value_fragment.is_null() ? nullptr : value_fragment.data());
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kSingletonValue: {
    decltype(Traits::singleton_value(input))
    in_singleton_value = Traits::singleton_value(input);
        
mojo::internal::Serialize<::blink::mojom::SingletonJavaScriptValue>(
  in_singleton_value,
  &fragment->data.f_singleton_value);
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kArrayValue: {
    decltype(Traits::array_value(input))
    in_array_value = Traits::array_value(input);
    mojo::internal::MessageFragment<
      typename decltype(fragment->data.f_array_value)::BaseType>
    value_fragment(fragment.message());
        constexpr const mojo::internal::ContainerValidateParams& array_value_validate_params =
            mojo::internal::GetArrayValidator<0, false, nullptr>();
        
mojo::internal::Serialize<mojo::ArrayDataView<::blink::mojom::RemoteInvocationArgumentDataView>>(
  in_array_value,
  value_fragment,
  &array_value_validate_params);
  
MOJO_INTERNAL_CHECK_SERIALIZATION(
  mojo::internal::SendValidation::kDefault,
  !(value_fragment.is_null()),
  mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
  "null array_value in RemoteInvocationArgument union");
    fragment->data.f_array_value.Set(
      value_fragment.is_null() ? nullptr : value_fragment.data());
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kTypedArrayValue: {
    decltype(Traits::typed_array_value(input))
    in_typed_array_value = Traits::typed_array_value(input);
    mojo::internal::MessageFragment<
      typename decltype(fragment->data.f_typed_array_value)::BaseType>
    value_fragment(fragment.message());
        
mojo::internal::Serialize<::blink::mojom::RemoteTypedArrayDataView>(
  in_typed_array_value,
  value_fragment);
  
MOJO_INTERNAL_CHECK_SERIALIZATION(
  mojo::internal::SendValidation::kDefault,
  !(value_fragment.is_null()),
  mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
  "null typed_array_value in RemoteInvocationArgument union");
    fragment->data.f_typed_array_value.Set(
      value_fragment.is_null() ? nullptr : value_fragment.data());
    break;
  }
  case ::blink::mojom::RemoteInvocationArgumentDataView::Tag::kObjectIdValue: {
    decltype(Traits::object_id_value(input))
    in_object_id_value = Traits::object_id_value(input);
    fragment->data.f_object_id_value = in_object_id_value;
    break;
  }
}
  }

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

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

}  // namespace internal


namespace internal {

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

  static void Serialize(MaybeConstUserType& input,
                        MessageFragment<::blink::mojom::internal::RemoteInvocationResultValue_Data>& fragment,
                        bool inlined) {
    
    if (CallIsNullIfExists<Traits>(input)) {
       if (inlined)
        fragment->set_null();
      return;
    }

if (!inlined)
  fragment.Allocate();

    // TODO(azani): Handle unknown and objects.
    // Set the not-null flag.
fragment->size = kUnionDataSize;
fragment->tag = Traits::GetTag(input);
switch (fragment->tag) {
  case ::blink::mojom::RemoteInvocationResultValueDataView::Tag::kNumberValue: {
    decltype(Traits::number_value(input))
    in_number_value = Traits::number_value(input);
    fragment->data.f_number_value = in_number_value;
    break;
  }
  case ::blink::mojom::RemoteInvocationResultValueDataView::Tag::kBooleanValue: {
    decltype(Traits::boolean_value(input))
    in_boolean_value = Traits::boolean_value(input);
    fragment->data.f_boolean_value = in_boolean_value;
    break;
  }
  case ::blink::mojom::RemoteInvocationResultValueDataView::Tag::kStringValue: {
    decltype(Traits::string_value(input))
    in_string_value = Traits::string_value(input);
    mojo::internal::MessageFragment<
      typename decltype(fragment->data.f_string_value)::BaseType>
    value_fragment(fragment.message());
        
mojo::internal::Serialize<::mojo_base::mojom::String16DataView>(
  in_string_value,
  value_fragment);
  
MOJO_INTERNAL_CHECK_SERIALIZATION(
  mojo::internal::SendValidation::kDefault,
  !(value_fragment.is_null()),
  mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
  "null string_value in RemoteInvocationResultValue union");
    fragment->data.f_string_value.Set(
      value_fragment.is_null() ? nullptr : value_fragment.data());
    break;
  }
  case ::blink::mojom::RemoteInvocationResultValueDataView::Tag::kSingletonValue: {
    decltype(Traits::singleton_value(input))
    in_singleton_value = Traits::singleton_value(input);
        
mojo::internal::Serialize<::blink::mojom::SingletonJavaScriptValue>(
  in_singleton_value,
  &fragment->data.f_singleton_value);
    break;
  }
  case ::blink::mojom::RemoteInvocationResultValueDataView::Tag::kObjectId: {
    decltype(Traits::object_id(input))
    in_object_id = Traits::object_id(input);
    fragment->data.f_object_id = in_object_id;
    break;
  }
}
  }

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

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

}  // namespace internal

}  // namespace mojo


namespace blink::mojom {

inline void RemoteTypedArrayDataView::GetBufferDataView(
    ::mojo_base::mojom::BigBufferDataView* output) {
  auto pointer = &data_->buffer;
  *output = ::mojo_base::mojom::BigBufferDataView(pointer, message_);
}


inline void RemoteInvocationResultDataView::GetValueDataView(
    RemoteInvocationResultValueDataView* output) {
  auto pointer = &data_->value;
  *output = RemoteInvocationResultValueDataView(pointer, message_);
}


inline void RemoteInvocationArgumentDataView::GetStringValueDataView(
    ::mojo_base::mojom::String16DataView* output) const {
  CHECK(is_string_value());
  *output = ::mojo_base::mojom::String16DataView(data_->data.f_string_value.Get(), message_);
}
inline void RemoteInvocationArgumentDataView::GetArrayValueDataView(
    mojo::ArrayDataView<RemoteInvocationArgumentDataView>* output) const {
  CHECK(is_array_value());
  *output = mojo::ArrayDataView<RemoteInvocationArgumentDataView>(data_->data.f_array_value.Get(), message_);
}
inline void RemoteInvocationArgumentDataView::GetTypedArrayValueDataView(
    RemoteTypedArrayDataView* output) const {
  CHECK(is_typed_array_value());
  *output = RemoteTypedArrayDataView(data_->data.f_typed_array_value.Get(), message_);
}

inline void RemoteInvocationResultValueDataView::GetStringValueDataView(
    ::mojo_base::mojom::String16DataView* output) const {
  CHECK(is_string_value());
  *output = ::mojo_base::mojom::String16DataView(data_->data.f_string_value.Get(), 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::SingletonJavaScriptValue> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::blink::mojom::SingletonJavaScriptValue value);
};

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

#endif  // THIRD_PARTY_BLINK_PUBLIC_MOJOM_REMOTE_OBJECTS_REMOTE_OBJECTS_MOJOM_SHARED_H_