// components/optimization_guide/public/mojom/model_broker_debug.mojom-shared.cc 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.

#include "components/optimization_guide/public/mojom/model_broker_debug.mojom-shared.h"
#include <ostream>
#include <utility>
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "components/optimization_guide/public/mojom/model_broker_debug.mojom-params-data.h"
namespace optimization_guide {
namespace mojom {

NOINLINE static const char* BrokerAssetStateToStringHelper(BrokerAssetState value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case BrokerAssetState::kNotInstalled:
      return "kNotInstalled";
    case BrokerAssetState::kRegistering:
      return "kRegistering";
    case BrokerAssetState::kBackgroundInstalling:
      return "kBackgroundInstalling";
    case BrokerAssetState::kForegroundInstalling:
      return "kForegroundInstalling";
    case BrokerAssetState::kReady:
      return "kReady";
    case BrokerAssetState::kUninstalling:
      return "kUninstalling";
    default:
      return nullptr;
  }
}

std::string BrokerAssetStateToString(BrokerAssetState value) {
  const char *str = BrokerAssetStateToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown BrokerAssetState value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, BrokerAssetState value) {
  return os << BrokerAssetStateToString(value);
}

namespace internal {


// static
bool BrokerPropertyInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const BrokerPropertyInfo_Data* object =
      static_cast<const BrokerPropertyInfo_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->description, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& description_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->description, validation_context,
                                         &description_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->value, 2, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& value_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->value, validation_context,
                                         &value_validate_params)) {
    return false;
  }

  return true;
}

BrokerPropertyInfo_Data::BrokerPropertyInfo_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool BrokerAssetInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 56, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const BrokerAssetInfo_Data* object =
      static_cast<const BrokerAssetInfo_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->name, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& name_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->name, validation_context,
                                         &name_validate_params)) {
    return false;
  }

  constexpr const mojo::internal::ContainerValidateParams& version_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->version, validation_context,
                                         &version_validate_params)) {
    return false;
  }


  if (!::optimization_guide::mojom::internal::BrokerAssetState_Data
        ::Validate(object->state, validation_context))
    return false;

  constexpr const mojo::internal::ContainerValidateParams& error_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->error, validation_context,
                                         &error_validate_params)) {
    return false;
  }

  return true;
}

BrokerAssetInfo_Data::BrokerAssetInfo_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool BrokerUseCaseInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const BrokerUseCaseInfo_Data* object =
      static_cast<const BrokerUseCaseInfo_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->name, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& name_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->name, validation_context,
                                         &name_validate_params)) {
    return false;
  }


  if (!::optimization_guide::mojom::internal::ModelUnavailableReason_Data
        ::Validate(object->unavailable_reason_$value, validation_context))
    return false;

  return true;
}

BrokerUseCaseInfo_Data::BrokerUseCaseInfo_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool BrokerModelInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 40, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const BrokerModelInfo_Data* object =
      static_cast<const BrokerModelInfo_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->name, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& name_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->name, validation_context,
                                         &name_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->weights_path, 3, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& weights_path_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->weights_path, validation_context,
                                         &weights_path_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->backend_type, 4, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& backend_type_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->backend_type, validation_context,
                                         &backend_type_validate_params)) {
    return false;
  }

  return true;
}

BrokerModelInfo_Data::BrokerModelInfo_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool BrokerStateInfo_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 56, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const BrokerStateInfo_Data* object =
      static_cast<const BrokerStateInfo_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->properties, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& properties_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->properties, validation_context,
                                         &properties_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->assets, 2, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& assets_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->assets, validation_context,
                                         &assets_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->use_cases, 3, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& use_cases_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->use_cases, validation_context,
                                         &use_cases_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->models, 4, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& models_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->models, validation_context,
                                         &models_validate_params)) {
    return false;
  }

  return true;
}

BrokerStateInfo_Data::BrokerStateInfo_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 8, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data* object =
      static_cast<const ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data*>(data);

  return true;
}

ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data::ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_GetStateInfo_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 8, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_GetStateInfo_Params_Data* object =
      static_cast<const ModelBrokerDebug_GetStateInfo_Params_Data*>(data);

  return true;
}

ModelBrokerDebug_GetStateInfo_Params_Data::ModelBrokerDebug_GetStateInfo_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_GetStateInfo_ResponseParams_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_GetStateInfo_ResponseParams_Data* object =
      static_cast<const ModelBrokerDebug_GetStateInfo_ResponseParams_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->state, 1, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateStruct(object->state, validation_context))
    return false;

  return true;
}

ModelBrokerDebug_GetStateInfo_ResponseParams_Data::ModelBrokerDebug_GetStateInfo_ResponseParams_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_SetUseCaseRequested_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_SetUseCaseRequested_Params_Data* object =
      static_cast<const ModelBrokerDebug_SetUseCaseRequested_Params_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->use_case, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& use_case_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->use_case, validation_context,
                                         &use_case_validate_params)) {
    return false;
  }

  return true;
}

ModelBrokerDebug_SetUseCaseRequested_Params_Data::ModelBrokerDebug_SetUseCaseRequested_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_UninstallModels_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 8, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_UninstallModels_Params_Data* object =
      static_cast<const ModelBrokerDebug_UninstallModels_Params_Data*>(data);

  return true;
}

ModelBrokerDebug_UninstallModels_Params_Data::ModelBrokerDebug_UninstallModels_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_ResetModelCrashCount_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 8, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_ResetModelCrashCount_Params_Data* object =
      static_cast<const ModelBrokerDebug_ResetModelCrashCount_Params_Data*>(data);

  return true;
}

ModelBrokerDebug_ResetModelCrashCount_Params_Data::ModelBrokerDebug_ResetModelCrashCount_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_AddObserver_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_AddObserver_Params_Data* object =
      static_cast<const ModelBrokerDebug_AddObserver_Params_Data*>(data);

  if (!mojo::internal::ValidateHandleOrInterfaceNonNullable(
          object->observer, 1, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateHandleOrInterface(object->observer,
                                                 validation_context)) {
    return false;
  }

  return true;
}

ModelBrokerDebug_AddObserver_Params_Data::ModelBrokerDebug_AddObserver_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool ModelBrokerDebug_AddAssetDownloadObserver_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const ModelBrokerDebug_AddAssetDownloadObserver_Params_Data* object =
      static_cast<const ModelBrokerDebug_AddAssetDownloadObserver_Params_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->asset_name, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& asset_name_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->asset_name, validation_context,
                                         &asset_name_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidateHandleOrInterfaceNonNullable(
          object->observer, 2, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateHandleOrInterface(object->observer,
                                                 validation_context)) {
    return false;
  }

  return true;
}

ModelBrokerDebug_AddAssetDownloadObserver_Params_Data::ModelBrokerDebug_AddAssetDownloadObserver_Params_Data()
    : header_({sizeof(*this), 0}) {}

}  // namespace internal
}  // namespace mojom
}  // namespace optimization_guide

namespace perfetto {

// static
void TraceFormatTraits<::optimization_guide::mojom::BrokerAssetState>::WriteIntoTrace(
   perfetto::TracedValue context, ::optimization_guide::mojom::BrokerAssetState value) {
  return std::move(context).WriteString(::optimization_guide::mojom::BrokerAssetStateToString(value));
}

} // namespace perfetto