VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
raw_data.h File Reference

Generic zero-copy raw-byte data container for VLink transport. More...

#include <cstdint>
#include "../base/bytes.h"
#include "./header.h"
Include dependency graph for raw_data.h:

Go to the source code of this file.

Namespaces

Functions

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

Detailed Description

Generic zero-copy raw-byte data container for VLink transport.

RawData wraps an untyped byte buffer together with a Header for sequencing and timestamping. It is the simplest zero-copy container in VLink and serves as a building block when the payload format is opaque or application-defined.

The struct is exactly 64 bytes on 64-bit platforms (verified via static_assert). Three ownership modes allow callers to manage memory without extra copies wherever possible:

Mode Created by Owns memory
Owned create(size) Yes
Shallow (borrow) shallow_copy(ptr, size) No
Deserialised operator<<(bytes) No
Binary wire format
[ magic_begin (4) | RawData struct (64) | payload bytes (N) | magic_end (4) ]
Generic zero-copy raw-byte data container with Header metadata.
Magic numbers allow the receiver to detect data corruption before memcpy-ing the struct header.
Usage
vlink::zerocopy::RawData rd;
rd.header.seq = 1;
rd.header.time_pub = get_time_ns();
rd.create(1024);
std::memcpy(const_cast<uint8_t*>(rd.data()), src_buf, 1024);
rd >> wire; // serialise to Bytes
vlink::zerocopy::RawData rd2;
rd2 << wire; // deserialise from Bytes (zero-copy, borrows wire)
Note
  • 32-bit architectures emit a compile-time warning and are not supported.
  • After operator<<, the internal data pointer references memory inside the source Bytes object. The Bytes must outlive the RawData.
  • fill_data is an alias for deep_copy(uint8_t*, size_t).