// services/network/public/mojom/declarative_performance_observer.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 "services/network/public/mojom/declarative_performance_observer.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 "services/network/public/mojom/declarative_performance_observer.mojom-params-data.h"
namespace network {
namespace mojom {

NOINLINE static const char* PerformanceEntryTypeToStringHelper(PerformanceEntryType value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case PerformanceEntryType::kNavigation:
      return "kNavigation";
    case PerformanceEntryType::kMark:
      return "kMark";
    case PerformanceEntryType::kVisibilityState:
      return "kVisibilityState";
    case PerformanceEntryType::kLargestContentfulPaint:
      return "kLargestContentfulPaint";
    default:
      return nullptr;
  }
}

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

std::ostream& operator<<(std::ostream& os, PerformanceEntryType value) {
  return os << PerformanceEntryTypeToString(value);
}

namespace internal {


// static
bool DeclarativePerformanceObserverPolicy_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 DeclarativePerformanceObserverPolicy_Data* object =
      static_cast<const DeclarativePerformanceObserverPolicy_Data*>(data);

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

  if (!mojo::internal::ValidatePointerNonNullable(
          object->entry_types, 2, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& entry_types_validate_params =
      mojo::internal::GetArrayOfEnumsValidator<0, false, ::network::mojom::internal::PerformanceEntryType_Data::Validate>();
  if (!mojo::internal::ValidateContainer(object->entry_types, validation_context,
                                         &entry_types_validate_params)) {
    return false;
  }

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

  return true;
}

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

}  // namespace internal
}  // namespace mojom
}  // namespace network

namespace perfetto {

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

} // namespace perfetto