// media/mojo/mojom/speech_recognizer.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 "media/mojo/mojom/speech_recognizer.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 "media/mojo/mojom/speech_recognizer.mojom-params-data.h"
namespace media {
namespace mojom {

NOINLINE static const char* AvailabilityStatusToStringHelper(AvailabilityStatus value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case AvailabilityStatus::kUnavailable:
      return "kUnavailable";
    case AvailabilityStatus::kDownloadable:
      return "kDownloadable";
    case AvailabilityStatus::kDownloading:
      return "kDownloading";
    case AvailabilityStatus::kAvailable:
      return "kAvailable";
    case AvailabilityStatus::kDownloadableWithoutUserActivation:
      return "kDownloadableWithoutUserActivation";
    default:
      return nullptr;
  }
}

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

std::ostream& operator<<(std::ostream& os, AvailabilityStatus value) {
  return os << AvailabilityStatusToString(value);
}

NOINLINE static const char* SpeechRecognitionQualityToStringHelper(SpeechRecognitionQuality value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SpeechRecognitionQuality::kCommand:
      return "kCommand";
    case SpeechRecognitionQuality::kDictation:
      return "kDictation";
    case SpeechRecognitionQuality::kConversation:
      return "kConversation";
    default:
      return nullptr;
  }
}

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

std::ostream& operator<<(std::ostream& os, SpeechRecognitionQuality value) {
  return os << SpeechRecognitionQualityToString(value);
}

namespace internal {


// static
bool StartSpeechRecognitionRequestParams_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  static constexpr mojo::internal::StructVersionSize kVersionSizes[] = {
    { 0, 72 },
    { 1, 72 },
  };
  if (!ValidateStructHeaderAndVersionSizeAndClaimMemory(
          data, kVersionSizes, 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 StartSpeechRecognitionRequestParams_Data* object =
      static_cast<const StartSpeechRecognitionRequestParams_Data*>(data);

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

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

  if (!mojo::internal::ValidatePointerNonNullable(
          object->language, 3, 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;
  }

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

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

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


  if (!::media::mojom::internal::SpeechRecognitionQuality_Data
        ::Validate(object->quality, validation_context))
    return false;

  return true;
}

StartSpeechRecognitionRequestParams_Data::StartSpeechRecognitionRequestParams_Data()
    : header_({sizeof(*this), 1}) {}


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

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

  return true;
}

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


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

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


  if (!::media::mojom::internal::SpeechRecognitionQuality_Data
        ::Validate(object->quality, validation_context))
    return false;

  return true;
}

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


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


  if (!::media::mojom::internal::AvailabilityStatus_Data
        ::Validate(object->status, validation_context))
    return false;

  return true;
}

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


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

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


  if (!::media::mojom::internal::SpeechRecognitionQuality_Data
        ::Validate(object->quality, validation_context))
    return false;

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

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

  return true;
}

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


// static
bool SpeechRecognitionSessionClient_ResultRetrieved_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 SpeechRecognitionSessionClient_ResultRetrieved_Params_Data* object =
      static_cast<const SpeechRecognitionSessionClient_ResultRetrieved_Params_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;
}

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


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

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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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


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

  return true;
}

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

}  // namespace internal
}  // namespace mojom
}  // namespace media

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto