Files
softbus_daemon/src/message_bus/pipeline/PayloadRef.h
2026-03-30 11:11:05 +08:00

37 lines
796 B
C++

#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)