// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
// Based on "crates/store/re_types/definitions/rerun/archetypes/mcap_channel.fbs".

#include "mcap_channel.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    McapChannel McapChannel::clear_fields() {
        auto archetype = McapChannel();
        archetype.id =
            ComponentBatch::empty<rerun::components::ChannelId>(Descriptor_id).value_or_throw();
        archetype.topic =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_topic).value_or_throw();
        archetype.message_encoding =
            ComponentBatch::empty<rerun::components::Text>(Descriptor_message_encoding)
                .value_or_throw();
        archetype.metadata =
            ComponentBatch::empty<rerun::components::KeyValuePairs>(Descriptor_metadata)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> McapChannel::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(4);
        if (id.has_value()) {
            columns.push_back(id.value().partitioned(lengths_).value_or_throw());
        }
        if (topic.has_value()) {
            columns.push_back(topic.value().partitioned(lengths_).value_or_throw());
        }
        if (message_encoding.has_value()) {
            columns.push_back(message_encoding.value().partitioned(lengths_).value_or_throw());
        }
        if (metadata.has_value()) {
            columns.push_back(metadata.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

    Collection<ComponentColumn> McapChannel::columns() {
        if (id.has_value()) {
            return columns(std::vector<uint32_t>(id.value().length(), 1));
        }
        if (topic.has_value()) {
            return columns(std::vector<uint32_t>(topic.value().length(), 1));
        }
        if (message_encoding.has_value()) {
            return columns(std::vector<uint32_t>(message_encoding.value().length(), 1));
        }
        if (metadata.has_value()) {
            return columns(std::vector<uint32_t>(metadata.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

    Result<Collection<ComponentBatch>> AsComponents<archetypes::McapChannel>::as_batches(
        const archetypes::McapChannel& archetype
    ) {
        using namespace archetypes;
        std::vector<ComponentBatch> cells;
        cells.reserve(4);

        if (archetype.id.has_value()) {
            cells.push_back(archetype.id.value());
        }
        if (archetype.topic.has_value()) {
            cells.push_back(archetype.topic.value());
        }
        if (archetype.message_encoding.has_value()) {
            cells.push_back(archetype.message_encoding.value());
        }
        if (archetype.metadata.has_value()) {
            cells.push_back(archetype.metadata.value());
        }

        return rerun::take_ownership(std::move(cells));
    }
} // namespace rerun
