// media/mojo/mojom/channel_layout.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 "media/mojo/mojom/channel_layout.mojom.h"
#include <stdint.h>
#include <utility>
#include "base/notreached.h"
#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 "media/mojo/mojom/channel_layout.mojom-params-data.h"
#include "media/mojo/mojom/channel_layout.mojom-shared-message-ids.h"

#include "media/mojo/mojom/channel_layout.mojom-import-headers.h"
#include "media/mojo/mojom/channel_layout.mojom-test-utils.h"


namespace media::mojom {
ChannelLayoutConfigPtr
ChannelLayoutConfig::NewPredefinedLayout(
    ::media::ChannelLayout value) {
  return ChannelLayoutConfigPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kPredefinedLayout)>,
      std::move(value));
}

ChannelLayoutConfigPtr
ChannelLayoutConfig::NewDiscreteChannels(
    uint32_t value) {
  return ChannelLayoutConfigPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kDiscreteChannels)>,
      std::move(value));
}

ChannelLayoutConfig::ChannelLayoutConfig(
    std::in_place_index_t<static_cast<size_t>(Tag::kPredefinedLayout)>,
    ::media::ChannelLayout value)
    : tag_(Tag::kPredefinedLayout),
      data_(std::in_place_index<static_cast<size_t>(Tag::kPredefinedLayout)>,
            std::move(value)) {}

ChannelLayoutConfig::ChannelLayoutConfig(
    std::in_place_index_t<static_cast<size_t>(Tag::kDiscreteChannels)>,
    uint32_t value)
    : tag_(Tag::kDiscreteChannels),
      data_(std::in_place_index<static_cast<size_t>(Tag::kDiscreteChannels)>,
            std::move(value)) {}
ChannelLayoutConfig::~ChannelLayoutConfig() {
  DestroyActive();
}

void ChannelLayoutConfig::set_predefined_layout(::media::ChannelLayout predefined_layout) {
  if (tag_ != Tag::kPredefinedLayout) {
    DestroyActive();
    tag_ = Tag::kPredefinedLayout;
  }
  data_.predefined_layout = predefined_layout;
}

void ChannelLayoutConfig::set_discrete_channels(uint32_t discrete_channels) {
  if (tag_ != Tag::kDiscreteChannels) {
    DestroyActive();
    tag_ = Tag::kDiscreteChannels;
  }
  data_.discrete_channels = discrete_channels;
}


ChannelLayoutConfig::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kPredefinedLayout)>,
    ::media::ChannelLayout value)
    : predefined_layout(std::move(value)) {}

ChannelLayoutConfig::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kDiscreteChannels)>,
    uint32_t value)
    : discrete_channels(std::move(value)) {}

void ChannelLayoutConfig::DestroyActive() {
  switch (tag_) {

    case Tag::kPredefinedLayout:
      std::destroy_at(&data_.predefined_layout);
      break;
    case Tag::kDiscreteChannels:
      std::destroy_at(&data_.discrete_channels);
      break;
  }
}

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


}  // media::mojom


namespace mojo {

// static
bool UnionTraits<::media::mojom::ChannelLayoutConfig::DataView, ::media::mojom::ChannelLayoutConfigPtr>::Read(
    ::media::mojom::ChannelLayoutConfig::DataView input,
    ::media::mojom::ChannelLayoutConfigPtr* output) {
  using UnionType = ::media::mojom::ChannelLayoutConfig;
  using Tag = UnionType::Tag;

  switch (input.tag()) {
    case Tag::kPredefinedLayout: {
      ::media::ChannelLayout result_predefined_layout;
      if (!input.ReadPredefinedLayout(&result_predefined_layout))
        return false;

      *output = UnionType::NewPredefinedLayout(result_predefined_layout);
      break;
    }
    case Tag::kDiscreteChannels: {
      *output = UnionType::NewDiscreteChannels(input.discrete_channels());
      break;
    }
    default:

      return false;
  }
  return true;
}

}  // namespace mojo


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


namespace media::mojom {




}  // media::mojom


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