// mojo/public/interfaces/bindings/native_struct.mojom.cc is auto generated by mojom_bindings_generator.py, do not edit

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

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

#include "mojo/public/interfaces/bindings/native_struct.mojom.h"
#include <stdint.h>
#include <utility>
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "mojo/public/interfaces/bindings/native_struct.mojom-params-data.h"
#include "mojo/public/interfaces/bindings/native_struct.mojom-shared-message-ids.h"

#include "mojo/public/interfaces/bindings/native_struct.mojom-import-headers.h"
#include "mojo/public/interfaces/bindings/native_struct.mojom-test-utils.h"


namespace mojo::native {
SerializedHandle::SerializedHandle()
    : the_handle(),
      type() {}

SerializedHandle::SerializedHandle(
    ::mojo::ScopedHandle the_handle_in,
    SerializedHandleType type_in)
    : the_handle(std::move(the_handle_in)),
      type(std::move(type_in)) {}

SerializedHandle::~SerializedHandle() = default;

void SerializedHandle::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "the_handle"), this->the_handle,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type ::mojo::ScopedHandle>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "type"), this->type,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type SerializedHandleType>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool SerializedHandle::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
NativeStruct::NativeStruct()
    : data(),
      handles() {}

NativeStruct::NativeStruct(
    std::vector<uint8_t> data_in,
    std::optional<std::vector<SerializedHandlePtr>> handles_in)
    : data(std::move(data_in)),
      handles(std::move(handles_in)) {}

NativeStruct::~NativeStruct() = default;

void NativeStruct::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "data"), this->data,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::vector<uint8_t>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "handles"), this->handles,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::optional<std::vector<SerializedHandlePtr>>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool NativeStruct::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}


}  // mojo::native


namespace mojo {


// static
bool StructTraits<::mojo::native::SerializedHandle::DataView, ::mojo::native::SerializedHandlePtr>::Read(
    ::mojo::native::SerializedHandle::DataView input,
    ::mojo::native::SerializedHandlePtr* output) {
  bool success = true;
  ::mojo::native::SerializedHandlePtr result(::mojo::native::SerializedHandle::New());
  
      if (success)
        result->the_handle = input.TakeTheHandle();
      if (success && !input.ReadType(&result->type))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::mojo::native::NativeStruct::DataView, ::mojo::native::NativeStructPtr>::Read(
    ::mojo::native::NativeStruct::DataView input,
    ::mojo::native::NativeStructPtr* output) {
  bool success = true;
  ::mojo::native::NativeStructPtr result(::mojo::native::NativeStruct::New());
  
      if (success && !input.ReadData(&result->data))
        success = false;
      if (success && !input.ReadHandles(&result->handles))
        success = false;
  *output = std::move(result);
  return success;
}

}  // namespace mojo


// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.


namespace mojo::native {




}  // mojo::native


#if defined(__clang__)
#pragma clang diagnostic pop
#endif