// services/webnn/public/mojom/webnn_tensor.mojom-data-view.h is auto generated by mojom_bindings_generator.py, do not edit

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

// This file defines XDataView for type traits and can be included in
// _mojom_traits.h definitions but otherwise please use .mojom-forward.h,
// .mojom-shared.h or .mojom.h.

// IWYU pragma: private
// IWYU pragma: friend "traits"

#ifndef SERVICES_WEBNN_PUBLIC_MOJOM_WEBNN_TENSOR_MOJOM_DATA_VIEW_H_
#define SERVICES_WEBNN_PUBLIC_MOJOM_WEBNN_TENSOR_MOJOM_DATA_VIEW_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/string_data_view.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"

#include "services/webnn/public/mojom/webnn_tensor.mojom-shared-internal.h"
#include "gpu/ipc/common/sync_token.mojom-shared.h"
#include "mojo/public/mojom/base/big_buffer.mojom-shared.h"
#include "services/webnn/public/mojom/webnn_graph.mojom-shared.h"
#include "services/webnn/public/mojom/webnn_error.mojom-shared.h"


namespace webnn::mojom {
class TensorUsageDataView;

class TensorInfoDataView;

class ReadTensorResultDataView;


}  // webnn::mojom


namespace mojo {
namespace internal {

template <>
struct MojomTypeTraits<::webnn::mojom::TensorUsageDataView> {
  using Data = ::webnn::mojom::internal::TensorUsage_Data;
  using DataAsArrayElement = Pointer<Data>;
  static constexpr MojomTypeCategory category = MojomTypeCategory::kStruct;
};

template <>
struct MojomTypeTraits<::webnn::mojom::TensorInfoDataView> {
  using Data = ::webnn::mojom::internal::TensorInfo_Data;
  using DataAsArrayElement = Pointer<Data>;
  static constexpr MojomTypeCategory category = MojomTypeCategory::kStruct;
};

template <>
struct MojomTypeTraits<::webnn::mojom::ReadTensorResultDataView> {
  using Data = ::webnn::mojom::internal::ReadTensorResult_Data;
  using DataAsArrayElement = Data;
  static constexpr MojomTypeCategory category = MojomTypeCategory::kUnion;
};

}  // namespace internal
}  // namespace mojo


namespace webnn::mojom {
// Interface base classes. They are used for type safety check.
class WebNNTensorInterfaceBase {};

using WebNNTensorPtrDataView =
    mojo::InterfacePtrDataView<WebNNTensorInterfaceBase>;
using WebNNTensorRequestDataView =
    mojo::InterfaceRequestDataView<WebNNTensorInterfaceBase>;
using WebNNTensorAssociatedPtrInfoDataView =
    mojo::AssociatedInterfacePtrInfoDataView<WebNNTensorInterfaceBase>;
using WebNNTensorAssociatedRequestDataView =
    mojo::AssociatedInterfaceRequestDataView<WebNNTensorInterfaceBase>;


class TensorUsageDataView {
 public:
  TensorUsageDataView() = default;

  TensorUsageDataView(
      internal::TensorUsage_Data* data,
      mojo::Message* message)
      : data_(data) {}

  bool is_null() const { return !data_; }
  bool web_gpu_interop() const {
    return data_->web_gpu_interop;
  }
  bool read() const {
    return data_->read;
  }
  bool write() const {
    return data_->write;
  }
 private:
  internal::TensorUsage_Data* data_ = nullptr;
};


class TensorInfoDataView {
 public:
  TensorInfoDataView() = default;

  TensorInfoDataView(
      internal::TensorInfo_Data* data,
      mojo::Message* message)
      : data_(data), message_(message) {}

  bool is_null() const { return !data_; }
  inline void GetDescriptorDataView(
      ::webnn::mojom::OperandDescriptorDataView* output);

  template <typename UserType>
  [[nodiscard]] bool ReadDescriptor(UserType* output) {
    
    auto* pointer = data_->descriptor.Get();
    return mojo::internal::Deserialize<::webnn::mojom::OperandDescriptorDataView>(
        pointer, output, message_);
  }
  inline void GetUsageDataView(
      TensorUsageDataView* output);

  template <typename UserType>
  [[nodiscard]] bool ReadUsage(UserType* output) {
    
    auto* pointer = data_->usage.Get();
    return mojo::internal::Deserialize<::webnn::mojom::TensorUsageDataView>(
        pointer, output, message_);
  }
 private:
  internal::TensorInfo_Data* data_ = nullptr;
  mojo::Message* message_ = nullptr;
};


class ReadTensorResultDataView {
 public:
  using Tag = internal::ReadTensorResult_Data::ReadTensorResult_Tag;

  ReadTensorResultDataView() = default;

  ReadTensorResultDataView(
      internal::ReadTensorResult_Data* data,
      mojo::Message* message)
      : data_(data), message_(message) {}

  bool is_null() const {
    // For inlined unions, |data_| is always non-null. In that case we need to
    // check |data_->is_null()|.
    return !data_ || data_->is_null();
  }

  Tag tag() const { return data_->tag; }
  bool is_buffer() const { return data_->tag == Tag::kBuffer; }
  inline void GetBufferDataView(
      ::mojo_base::mojom::BigBufferDataView* output) const;

  template <typename UserType>
  [[nodiscard]] bool ReadBuffer(UserType* output) const {
    
    CHECK(is_buffer());
    return mojo::internal::Deserialize<::mojo_base::mojom::BigBufferDataView>(
        data_->data.f_buffer.Get(), output, message_);
  }
  bool is_error() const { return data_->tag == Tag::kError; }
  inline void GetErrorDataView(
      ::webnn::mojom::ErrorDataView* output) const;

  template <typename UserType>
  [[nodiscard]] bool ReadError(UserType* output) const {
    
    CHECK(is_error());
    return mojo::internal::Deserialize<::webnn::mojom::ErrorDataView>(
        data_->data.f_error.Get(), output, message_);
  }

 private:
  internal::ReadTensorResult_Data* data_ = nullptr;
  mojo::Message* message_ = nullptr;
};



}  // webnn::mojom

#endif  // SERVICES_WEBNN_PUBLIC_MOJOM_WEBNN_TENSOR_MOJOM_DATA_VIEW_H_