// components/spellcheck/common/spellcheck.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/spellcheck/common/spellcheck.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/spellcheck/common/spellcheck.mojom-params-data.h"
namespace spellcheck {
namespace mojom {

NOINLINE static const char* DecorationToStringHelper(Decoration value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case Decoration::kSpelling:
      return "kSpelling";
    case Decoration::kGrammar:
      return "kGrammar";
    default:
      return nullptr;
  }
}

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

std::ostream& operator<<(std::ostream& os, Decoration value) {
  return os << DecorationToString(value);
}

namespace internal {


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

  if (!mojo::internal::ValidateStruct(object->file, validation_context))
    return false;

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

  return true;
}

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


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


  if (!::spellcheck::mojom::internal::Decoration_Data
        ::Validate(object->marker_type, validation_context))
    return false;

  return true;
}

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


// static
bool SpellCheckResult_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 32, 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 SpellCheckResult_Data* object =
      static_cast<const SpellCheckResult_Data*>(data);


  if (!::spellcheck::mojom::internal::Decoration_Data
        ::Validate(object->decoration, validation_context))
    return false;

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

  return true;
}

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


// static
bool SpellChecker_Initialize_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 32, 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 SpellChecker_Initialize_Params_Data* object =
      static_cast<const SpellChecker_Initialize_Params_Data*>(data);

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

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

  return true;
}

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


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

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

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

  return true;
}

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


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

  return true;
}

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


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

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

  return true;
}

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


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

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

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

  return true;
}

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


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

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

  return true;
}

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


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

  return true;
}

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

}  // namespace internal
}  // namespace mojom
}  // namespace spellcheck

namespace perfetto {

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

} // namespace perfetto