#pragma once

#include <cstddef>
#include <cstdint>
#include <memory>

#include <QMetaType>

#include "core/memory/MemoryPool.h"

namespace softbus::message_bus::pipeline
{

struct PayloadRef
{
    softbus::core::memory::MemoryPool::BlockPtr block;
    std::size_t offset{0};
    std::size_t length{0};

    const std::uint8_t* bytes() const
    {
        if (!block || !block->data || offset > block->capacity) {
            return nullptr;
        }
        return block->data + offset;
    }

    bool valid() const
    {
        return block && block->data && (offset + length <= block->capacity);
    }
};

} // namespace softbus::message_bus::pipeline

Q_DECLARE_METATYPE(softbus::message_bus::pipeline::PayloadRef)
