VLink  2.0.0
A high-performance communication middleware
raw_data.h 文件参考

Generic zero-copy byte-buffer container with a Header prefix. 更多...

#include <cstdint>
#include "../base/bytes.h"
#include "./header.h"
raw_data.h 的引用(Include)关系图:

浏览源代码.

命名空间

 
 

函数

struct vlink::zerocopy::VLINK_EXPORT_AND_ALIGNED (8) AudioFrame final
 

详细描述

Generic zero-copy byte-buffer container with a Header prefix.

RawData is the most lightweight container in the vlink::zerocopy family. It pairs an opaque payload (any application-defined byte blob: Protobuf wire bytes, FlatBuffer tables, compressed frames, encrypted CAN snapshots, ...) with a 40-byte Header so that consumers can sequence and time-stamp the payload without parsing it. Use RawData whenever the payload schema is opaque to VLink, or when a higher-level layer wraps its own framing on top.

Ownership mode How to create Frees on destruction
Owned create(size) Yes
Borrowed shallow_copy(ptr, size) No
Deserialised operator<<(bytes) No (borrows bytes)
Wire format
RawData is POD; the canonical serialiser is memcpy(). The sizeof value is locked by static_assert and forms a permanent binary contract: VLink zero-copy containers have NO forward and NO backward compatibility across versions, and every field including the reserved slot is part of that contract.
static_assert(sizeof(RawData) == 64, "Sizeof must be 64 bytes.");
64-byte POD container that wraps an opaque byte payload with a Header prefix.
Memory layout
Offset Size Field
------ ----- --------------------------------
0 40 Header header
40 8 uint8_t* data_
48 8 size_t size_
56 1 bool is_owner_
57 1 (padding)
58 2 uint16_t reserved_buf_
60 4 (tail padding to align(8))
------ ----- --------------------------------
Total 64 bytes (alignas 8)
Wire envelope:
[ magic_begin (4) | version (4) | RawData struct (64) | payload (size_) | magic_end (4) ]
40-byte timestamp / sequencing metadata prefix shared by all zero-copy containers.
Reserved bytes
reserved_buf_ travels through the wire format unchanged. It is exposed via get_reserved() so applications can stash a flag or minor sub-type id without inflating the struct, but the slot must not be redefined later – doing so would silently break any peer that still expects the old meaning.
Example
vlink::zerocopy::RawData rd;
rd.header.seq = ++seq;
rd.header.time_pub = vlink::time_ns();
rd.create(payload.size());
std::memcpy(const_cast<uint8_t*>(rd.data()), payload.data(), payload.size());
rd >> wire;
vlink::zerocopy::RawData rx;
rx << wire;