VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Bytes Class Referencefinal

Versatile 128-byte byte buffer with SBO, five ownership modes and compression helpers. More...

#include <bytes.h>

Collaboration diagram for vlink::Bytes:

Public Member Functions

 Bytes () noexcept
 Constructs an empty, unallocated Bytes object.
 Bytes (const Bytes &target) noexcept
 Copy constructor.
 Bytes (Bytes &&target) noexcept
 Move constructor.
 Bytes (const std::initializer_list< uint8_t > &list) noexcept
 Constructs an owned Bytes from an initialiser list of byte values.
 Bytes (const std::vector< uint8_t > &data) noexcept
 Constructs an owned Bytes by deep-copying a std::vector<uint8_t>.
 ~Bytes () noexcept
 Destructor. Frees owned memory if is_owner() is true and is_loaned() is false.
Bytesoperator= (const Bytes &target) noexcept
 Copy assignment operator.
Bytesoperator= (Bytes &&target) noexcept
 Move assignment operator.
Bytesoperator= (const std::vector< uint8_t > &data) noexcept
 Assignment from a std::vector<uint8_t> (deep copy).
bool operator== (const Bytes &target) const noexcept
 Equality comparison – compares byte content.
bool operator!= (const Bytes &target) const noexcept
 Inequality comparison – compares byte content.
bool operator== (const std::vector< uint8_t > &data) const noexcept
 Equality comparison with a std::vector<uint8_t>.
bool operator!= (const std::vector< uint8_t > &data) const noexcept
 Inequality comparison with a std::vector<uint8_t>.
uint8_t & operator[] (size_t index) noexcept
 Mutable subscript operator.
const uint8_t & operator[] (size_t index) const noexcept
 Read-only subscript operator.
uint8_t * data () noexcept
 Returns a pointer to the start of the user data region (after the prefix offset).
const uint8_t * data () const noexcept
 Returns a const pointer to the start of the user data region.
uint8_t * real_data () noexcept
 Returns a pointer to the very beginning of the backing buffer (before the offset).
const uint8_t * real_data () const noexcept
 Returns a const pointer to the very beginning of the backing buffer.
size_t size () const noexcept
 Returns the number of usable bytes (excluding the prefix offset region).
size_t real_size () const noexcept
 Returns the total backing-buffer size including the prefix offset region.
size_t capacity () const noexcept
 Returns the allocated capacity of the backing buffer.
uint8_t offset () const noexcept
 Returns the size of the prefix offset region in bytes.
bool is_owner () const noexcept
 Returns true if this object owns and is responsible for freeing its buffer.
bool is_loaned () const noexcept
 Returns true if this object holds an iceoryx loaned chunk.
bool empty () const noexcept
 Returns true if the buffer is empty (no data pointer and size == 0).
uint8_t * begin () noexcept
 Iterator begin (mutable) – same as data().
const uint8_t * begin () const noexcept
 Iterator begin (const) – same as data() const.
uint8_t * end () noexcept
 Iterator end (mutable) – one past the last usable byte.
const uint8_t * end () const noexcept
 Iterator end (const) – one past the last usable byte.
uint8_t * real_begin () noexcept
 Iterator begin for the full backing buffer (mutable) – same as real_data().
const uint8_t * real_begin () const noexcept
 Iterator begin for the full backing buffer (const).
uint8_t * real_end () noexcept
 Iterator end for the full backing buffer (mutable).
const uint8_t * real_end () const noexcept
 Iterator end for the full backing buffer (const).
bool is_ptr () const noexcept
 Returns true if the object holds only an opaque pointer (size == 0 and not owner).
std::vector< uint8_t > to_raw_data () const noexcept
 Copies the usable byte region into a new std::vector<uint8_t>.
std::string to_string () const noexcept
 Returns the usable byte region as a std::string.
std::string_view to_string_view () const noexcept
 Returns a zero-copy std::string_view over the usable byte region.
template<typename T = void>
T * to_ptr () const noexcept
 Reinterprets the backing buffer as a pointer to T.
void clear () noexcept
 Releases the buffer and resets the object to the empty state.
bool shrink_to (size_t size) noexcept
 Reduces the logical size of the buffer without reallocating.
bool reserve (size_t new_capacity) noexcept
 Ensures the backing buffer can hold at least new_capacity bytes.
bool resize (size_t size) noexcept
 Resizes the logical data region to size bytes.
Bytesshallow_copy (const Bytes &bytes) noexcept
 Makes this object a non-owning alias of bytes (shallow copy in-place).
Bytesdeep_copy (const Bytes &bytes) noexcept
 Replaces this object with a fully owned deep copy of bytes.
Bytesdeep_copy_self () noexcept
 Converts this object from a non-owning alias to a fully owned deep copy of its own data.

Static Public Member Functions

static void init_memory_pool () noexcept
 Initialises the global thread-safe memory pool for Bytes allocations.
static void release_memory_pool () noexcept
 Releases the global memory pool and returns its memory to the OS.
static uint8_t * bytes_malloc (size_t size) noexcept
 Allocates a raw byte buffer from the memory pool (or heap if pool is unavailable).
static void bytes_free (uint8_t *ptr, size_t size) noexcept
 Frees a buffer previously allocated by bytes_malloc().
static Bytes create (size_t size, uint8_t offset=0) noexcept
 Creates an owned Bytes buffer of the given size.
static Bytes shallow_copy (uint8_t *data, size_t size) noexcept
 Creates a non-owning Bytes alias pointing to an external mutable buffer.
static Bytes shallow_copy (const uint8_t *data, size_t size) noexcept
 Creates a non-owning Bytes alias pointing to an external read-only buffer.
static Bytes shallow_copy_ptr (void *data) noexcept
 Wraps an opaque pointer without associating a byte size.
static Bytes deep_copy (uint8_t *data, size_t size, uint8_t offset=0) noexcept
 Creates an owned deep copy of an external mutable buffer.
static Bytes deep_copy (const uint8_t *data, size_t size, uint8_t offset=0) noexcept
 Creates an owned deep copy of an external read-only buffer.
static Bytes loan_internal (uint8_t *data, size_t size) noexcept
 Creates a loaned (non-owning) alias for an iceoryx zero-copy payload (mutable).
static Bytes loan_internal (const uint8_t *data, size_t size) noexcept
 Creates a loaned (non-owning) alias for an iceoryx zero-copy payload (read-only).
static Bytes from_string (const std::string &str, uint8_t offset=0) noexcept
 Constructs a Bytes buffer from a std::string by deep-copying its contents.
static Bytes from_user_input (const std::string &str, bool *ok=nullptr) noexcept
 Parses a user-provided hex or binary string literal into a Bytes buffer.
static std::string convert_to_hex_str (const uint8_t *value, size_t size) noexcept
 Converts a raw byte array to an uppercase hex string with spaces.
static Bytes reverse_order (const Bytes &target) noexcept
 Returns a new Bytes object with the byte order of target reversed.
static std::string encode_to_base64 (const Bytes &target) noexcept
 Encodes a Bytes buffer as a standard Base-64 ASCII string.
static Bytes decode_from_base64 (const std::string &target) noexcept
 Decodes a Base-64 ASCII string into a Bytes buffer.
static uint32_t get_crc_32 (const Bytes &target) noexcept
 Computes the CRC-32 checksum of a Bytes buffer.
static constexpr uint8_t stack_size () noexcept
 Returns the size of the inline stack storage in bytes.
static constexpr bool is_little_endian () noexcept
 Returns true if the platform uses little-endian byte order.
static constexpr bool is_big_endian () noexcept
 Returns true if the platform uses big-endian byte order.
static bool is_compress_data (const uint8_t *data, size_t size) noexcept
 Checks whether a raw byte buffer contains LZAV-compressed VLink data.
static Bytes compress_data (const uint8_t *data, size_t size, bool high_ratio=false) noexcept
 Compresses a raw byte buffer using the LZAV algorithm.
static Bytes uncompress_data (const uint8_t *data, size_t size, bool check_valid=true) noexcept
 Decompresses a LZAV-compressed Bytes buffer.

Friends

VLINK_EXPORT friend std::ostream & operator<< (std::ostream &ostream, const Bytes &target) noexcept
 Stream insertion operator – prints bytes as space-separated hex pairs.

Detailed Description

Versatile 128-byte byte buffer with SBO, five ownership modes and compression helpers.

The total object size is always 128 bytes (96-byte inline stack storage + metadata). Allocations larger than 96 bytes spill to the memory pool or system heap.

Constructor & Destructor Documentation

◆ Bytes() [1/5]

vlink::Bytes::Bytes ( )
noexcept

Constructs an empty, unallocated Bytes object.

data() returns nullptr and size() returns 0. is_owner() and is_loaned() are both false.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bytes() [2/5]

vlink::Bytes::Bytes ( const Bytes & target)
noexcept

Copy constructor.

If target is an owner, a deep copy of its data is made. If target is a shallow alias (non-owner, non-loaned), the alias is shared. Loaned objects are shallow-copied as well (ownership is not transferred).

Parameters
targetSource Bytes to copy.
Here is the call graph for this function:

◆ Bytes() [3/5]

vlink::Bytes::Bytes ( Bytes && target)
noexcept

Move constructor.

Transfers all ownership and data from target. After the move, target is empty.

Parameters
targetSource Bytes to move from.
Here is the call graph for this function:

◆ Bytes() [4/5]

vlink::Bytes::Bytes ( const std::initializer_list< uint8_t > & list)
noexcept

Constructs an owned Bytes from an initialiser list of byte values.

Equivalent to create(list.size()) followed by a memcpy of the list elements.

Parameters
listInitialiser list of uint8_t values.
Here is the call graph for this function:

◆ Bytes() [5/5]

vlink::Bytes::Bytes ( const std::vector< uint8_t > & data)
explicitnoexcept

Constructs an owned Bytes by deep-copying a std::vector<uint8_t>.

Parameters
dataVector whose contents are copied into the new buffer.
Here is the call graph for this function:

◆ ~Bytes()

vlink::Bytes::~Bytes ( )
noexcept

Destructor. Frees owned memory if is_owner() is true and is_loaned() is false.

Here is the call graph for this function:

Member Function Documentation

◆ begin() [1/2]

const uint8_t * vlink::Bytes::begin ( ) const
inlinenodiscardnoexcept

Iterator begin (const) – same as data() const.

Returns
Const pointer to the first usable byte.

◆ begin() [2/2]

uint8_t * vlink::Bytes::begin ( )
inlinenodiscardnoexcept

Iterator begin (mutable) – same as data().

Returns
Pointer to the first usable byte.
Here is the caller graph for this function:

◆ bytes_free()

void vlink::Bytes::bytes_free ( uint8_t * ptr,
size_t size )
staticnoexcept

Frees a buffer previously allocated by bytes_malloc().

Parameters
ptrPointer returned by bytes_malloc().
sizeOriginal size passed to bytes_malloc().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bytes_malloc()

uint8_t * vlink::Bytes::bytes_malloc ( size_t size)
staticnodiscardnoexcept

Allocates a raw byte buffer from the memory pool (or heap if pool is unavailable).

Parameters
sizeNumber of bytes to allocate.
Returns
Pointer to the allocated memory, or nullptr on failure.
Note
The returned pointer must be freed with bytes_free() using the same size.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity()

size_t vlink::Bytes::capacity ( ) const
inlinenodiscardnoexcept

Returns the allocated capacity of the backing buffer.

capacity() >= real_size() always holds. For SBO buffers, capacity() == kStackSize.

Returns
Capacity in bytes.
Here is the caller graph for this function:

◆ clear()

void vlink::Bytes::clear ( )
noexcept

Releases the buffer and resets the object to the empty state.

If is_owner() is true, the backing memory is returned to the pool or heap. After this call, empty() returns true.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compress_data()

Bytes vlink::Bytes::compress_data ( const uint8_t * data,
size_t size,
bool high_ratio = false )
staticnodiscardnoexcept

Compresses a raw byte buffer using the LZAV algorithm.

Wraps the compressed payload with a 4-byte header magic and a 4-byte footer magic so that is_compress_data() can recognise it. Buffers larger than kMaxCompressCacheSize (1 MiB) are rejected and an empty Bytes is returned.

Parameters
dataPointer to the uncompressed data.
sizeNumber of bytes to compress.
high_ratioIf true, uses LZAV high-compression mode (slower but better ratio). Default: false (normal mode).
Returns
Compressed Bytes with header/footer magic, or empty on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_to_hex_str()

std::string vlink::Bytes::convert_to_hex_str ( const uint8_t * value,
size_t size )
staticnodiscardnoexcept

Converts a raw byte array to an uppercase hex string with spaces.

Each byte is rendered as two uppercase hex digits followed by a space, e.g., {0x1A, 0xB2} -> "1A B2 ". Useful for logging binary frames.

Parameters
valuePointer to the byte array.
sizeNumber of bytes to convert.
Returns
Hex string representation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

Bytes vlink::Bytes::create ( size_t size,
uint8_t offset = 0 )
staticnodiscardnoexcept

Creates an owned Bytes buffer of the given size.

Memory is allocated from the pool or heap. If size <= kStackSize (96) the inline stack buffer is used instead (no heap allocation). The contents are not initialised.

Parameters
sizeNumber of usable bytes (i.e. size() after construction).
offsetNumber of bytes to reserve at the start of the backing buffer as a prefix region (e.g., for protocol headers). data() = real_data() + offset. Default: 0.
Returns
A new owned Bytes object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [1/2]

const uint8_t * vlink::Bytes::data ( ) const
inlinenodiscardnoexcept

Returns a const pointer to the start of the user data region.

Returns
Read-only pointer to user data, or nullptr if not allocated.

◆ data() [2/2]

uint8_t * vlink::Bytes::data ( )
inlinenodiscardnoexcept

Returns a pointer to the start of the user data region (after the prefix offset).

Equivalent to real_data() + offset(). Returns nullptr if the buffer is empty.

Returns
Mutable pointer to user data, or nullptr if not allocated.
Here is the caller graph for this function:

◆ decode_from_base64()

Bytes vlink::Bytes::decode_from_base64 ( const std::string & target)
staticnodiscardnoexcept

Decodes a Base-64 ASCII string into a Bytes buffer.

Parameters
targetBase-64 encoded string.
Returns
Decoded Bytes. Returns an empty object on invalid input.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deep_copy() [1/3]

Bytes & vlink::Bytes::deep_copy ( const Bytes & bytes)
noexcept

Replaces this object with a fully owned deep copy of bytes.

Releases the current buffer, allocates new memory, and copies all bytes from bytes. After this call is_owner() is true.

Parameters
bytesSource to copy.
Returns
Reference to *this.
Here is the call graph for this function:

◆ deep_copy() [2/3]

Bytes vlink::Bytes::deep_copy ( const uint8_t * data,
size_t size,
uint8_t offset = 0 )
staticnodiscardnoexcept

Creates an owned deep copy of an external read-only buffer.

Same as the mutable overload but accepts a const source pointer.

Parameters
dataPointer to the source read-only buffer.
sizeNumber of bytes to copy.
offsetPrefix-region size in the new buffer. Default: 0.
Returns
A new owned Bytes containing a copy of the source data.
Here is the call graph for this function:

◆ deep_copy() [3/3]

Bytes vlink::Bytes::deep_copy ( uint8_t * data,
size_t size,
uint8_t offset = 0 )
staticnodiscardnoexcept

Creates an owned deep copy of an external mutable buffer.

Allocates new memory, copies size bytes from data, and returns a fully owned Bytes object. Safe even after the original buffer is freed.

Parameters
dataPointer to the source buffer.
sizeNumber of bytes to copy.
offsetPrefix-region size in the new buffer. Default: 0.
Returns
A new owned Bytes containing a copy of the source data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deep_copy_self()

Bytes & vlink::Bytes::deep_copy_self ( )
noexcept

Converts this object from a non-owning alias to a fully owned deep copy of its own data.

If the object is already an owner, this is a no-op. Otherwise, new memory is allocated, the current data is copied, and is_owner_ is set to true.

Returns
Reference to *this.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool vlink::Bytes::empty ( ) const
inlinenodiscardnoexcept

Returns true if the buffer is empty (no data pointer and size == 0).

Returns
true if data_ == nullptr and size_ == 0.
Here is the caller graph for this function:

◆ encode_to_base64()

std::string vlink::Bytes::encode_to_base64 ( const Bytes & target)
staticnodiscardnoexcept

Encodes a Bytes buffer as a standard Base-64 ASCII string.

Parameters
targetBuffer to encode.
Returns
Base-64 encoded string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [1/2]

const uint8_t * vlink::Bytes::end ( ) const
inlinenodiscardnoexcept

Iterator end (const) – one past the last usable byte.

Returns
Const pointer to one past the last byte.

◆ end() [2/2]

uint8_t * vlink::Bytes::end ( )
inlinenodiscardnoexcept

Iterator end (mutable) – one past the last usable byte.

Returns
Pointer to one past the last byte.
Here is the caller graph for this function:

◆ from_string()

Bytes vlink::Bytes::from_string ( const std::string & str,
uint8_t offset = 0 )
staticnodiscardnoexcept

Constructs a Bytes buffer from a std::string by deep-copying its contents.

Parameters
strSource string.
offsetPrefix-region reserved before the string data. Default: 0.
Returns
A new owned Bytes containing the UTF-8 bytes of str.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_user_input()

Bytes vlink::Bytes::from_user_input ( const std::string & str,
bool * ok = nullptr )
staticnodiscardnoexcept

Parses a user-provided hex or binary string literal into a Bytes buffer.

Accepts formats such as "0x1A2B3C" (hex) or raw binary strings. Sets ok to false if parsing fails.

Parameters
strInput string to parse.
okOptional pointer set to true on success, false on failure.
Returns
The parsed Bytes, or an empty object on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_crc_32()

uint32_t vlink::Bytes::get_crc_32 ( const Bytes & target)
staticnodiscardnoexcept

Computes the CRC-32 checksum of a Bytes buffer.

Parameters
targetBuffer to checksum.
Returns
32-bit CRC value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_memory_pool()

void vlink::Bytes::init_memory_pool ( )
staticnoexcept

Initialises the global thread-safe memory pool for Bytes allocations.

On Linux with __cpp_lib_memory_resource support this initialises a pmr::synchronized_pool_resource that reduces per-allocation overhead. Call this once at application start before any Bytes objects are created. Safe to call multiple times; subsequent calls are no-ops.

Here is the caller graph for this function:

◆ is_big_endian()

bool vlink::Bytes::is_big_endian ( )
inlinestaticnodiscardconstexprnoexcept

Returns true if the platform uses big-endian byte order.

Returns
true on big-endian platforms. Equivalent to !is_little_endian().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_compress_data()

bool vlink::Bytes::is_compress_data ( const uint8_t * data,
size_t size )
staticnodiscardnoexcept

Checks whether a raw byte buffer contains LZAV-compressed VLink data.

Inspects the first 4 bytes for the header magic {0x17, 0x49, 0xB2, 0x6F} and the last 4 bytes for the footer magic {0xA7, 0x05, 0xED, 0x71}. Both must match for the function to return true.

Parameters
dataPointer to the buffer to inspect.
sizeLength of the buffer.
Returns
true if header and footer magic are present.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_little_endian()

bool vlink::Bytes::is_little_endian ( )
inlinestaticnodiscardconstexprnoexcept

Returns true if the platform uses little-endian byte order.

Determined at compile time from preprocessor macros (__BYTE_ORDER__, __LITTLE_ENDIAN__, Windows defaults).

Returns
true on little-endian platforms (x86, arm-le, etc.).
Here is the caller graph for this function:

◆ is_loaned()

bool vlink::Bytes::is_loaned ( ) const
inlinenodiscardnoexcept

Returns true if this object holds an iceoryx loaned chunk.

Loaned objects must not free the underlying memory; ownership belongs to RouDi.

Returns
true for objects created via loan_internal().
Here is the caller graph for this function:

◆ is_owner()

bool vlink::Bytes::is_owner ( ) const
inlinenodiscardnoexcept

Returns true if this object owns and is responsible for freeing its buffer.

Returns
true for objects created via create() or deep_copy().
Here is the caller graph for this function:

◆ is_ptr()

bool vlink::Bytes::is_ptr ( ) const
inlinenodiscardnoexcept

Returns true if the object holds only an opaque pointer (size == 0 and not owner).

An object created via shallow_copy_ptr() has size_ == 0, offset_ == 0 and is_owner_ == false. Use to_ptr<T>() to retrieve the wrapped pointer.

Returns
true if this is a pointer-only wrapper.
Here is the caller graph for this function:

◆ loan_internal() [1/2]

Bytes vlink::Bytes::loan_internal ( const uint8_t * data,
size_t size )
staticnodiscardnoexcept

Creates a loaned (non-owning) alias for an iceoryx zero-copy payload (read-only).

Same as the mutable overload but for const payloads.

Parameters
dataPointer to the read-only iceoryx chunk payload.
sizeSize of the payload in bytes.
Returns
A loaned Bytes object.
Here is the call graph for this function:

◆ loan_internal() [2/2]

Bytes vlink::Bytes::loan_internal ( uint8_t * data,
size_t size )
staticnodiscardnoexcept

Creates a loaned (non-owning) alias for an iceoryx zero-copy payload (mutable).

Marks the object with is_loaned() == true. VLink will not free the memory because it is owned by the iceoryx RouDi daemon. This factory is used internally by the shm:// transport backend.

Parameters
dataPointer to the iceoryx chunk payload.
sizeSize of the payload in bytes.
Returns
A loaned Bytes object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ offset()

uint8_t vlink::Bytes::offset ( ) const
inlinenodiscardnoexcept

Returns the size of the prefix offset region in bytes.

data() == real_data() + offset().

Returns
Offset in bytes.
Here is the caller graph for this function:

◆ operator!=() [1/2]

bool vlink::Bytes::operator!= ( const Bytes & target) const
nodiscardnoexcept

Inequality comparison – compares byte content.

Parameters
targetBytes to compare with.
Returns
true if the objects differ in size or content.
Here is the call graph for this function:

◆ operator!=() [2/2]

bool vlink::Bytes::operator!= ( const std::vector< uint8_t > & data) const
nodiscardnoexcept

Inequality comparison with a std::vector<uint8_t>.

Parameters
dataVector to compare with.
Returns
true if sizes or contents differ.
Here is the call graph for this function:

◆ operator=() [1/3]

Bytes & vlink::Bytes::operator= ( Bytes && target)
noexcept

Move assignment operator.

Releases the current buffer, then transfers all state from target.

Parameters
targetSource Bytes to move from.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator=() [2/3]

Bytes & vlink::Bytes::operator= ( const Bytes & target)
noexcept

Copy assignment operator.

Releases the current buffer, then copies target (deep if owner, shallow otherwise).

Parameters
targetSource Bytes to copy-assign from.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator=() [3/3]

Bytes & vlink::Bytes::operator= ( const std::vector< uint8_t > & data)
noexcept

Assignment from a std::vector<uint8_t> (deep copy).

Parameters
dataVector whose contents are deep-copied into this buffer.
Returns
Reference to *this.
Here is the call graph for this function:

◆ operator==() [1/2]

bool vlink::Bytes::operator== ( const Bytes & target) const
nodiscardnoexcept

Equality comparison – compares byte content.

Parameters
targetBytes to compare with.
Returns
true if both objects have identical size and content.
Here is the call graph for this function:

◆ operator==() [2/2]

bool vlink::Bytes::operator== ( const std::vector< uint8_t > & data) const
nodiscardnoexcept

Equality comparison with a std::vector<uint8_t>.

Parameters
dataVector to compare with.
Returns
true if sizes and contents match.
Here is the call graph for this function:

◆ operator[]() [1/2]

const uint8_t & vlink::Bytes::operator[] ( size_t index) const
inlinenodiscardnoexcept

Read-only subscript operator.

Parameters
indexLogical index (0-based from the start of the user data region).
Returns
Const reference to the byte at index.

◆ operator[]() [2/2]

uint8_t & vlink::Bytes::operator[] ( size_t index)
inlinenodiscardnoexcept

Mutable subscript operator.

Details.

Accesses the byte at logical index index (i.e., real_data()[offset + index]). No bounds checking is performed.

Parameters
indexLogical index (0-based from the start of the user data region).
Returns
Reference to the byte at index.

◆ real_begin() [1/2]

const uint8_t * vlink::Bytes::real_begin ( ) const
inlinenodiscardnoexcept

Iterator begin for the full backing buffer (const).

Returns
Const pointer to the first byte of the raw buffer.

◆ real_begin() [2/2]

uint8_t * vlink::Bytes::real_begin ( )
inlinenodiscardnoexcept

Iterator begin for the full backing buffer (mutable) – same as real_data().

Returns
Pointer to the first byte of the raw buffer (before the offset).
Here is the caller graph for this function:

◆ real_data() [1/2]

const uint8_t * vlink::Bytes::real_data ( ) const
inlinenodiscardnoexcept

Returns a const pointer to the very beginning of the backing buffer.

Returns
Read-only pointer to the raw buffer origin.

◆ real_data() [2/2]

uint8_t * vlink::Bytes::real_data ( )
inlinenodiscardnoexcept

Returns a pointer to the very beginning of the backing buffer (before the offset).

Use this to write protocol headers into the reserved prefix region. real_data() + offset() == data().

Returns
Mutable pointer to the raw buffer origin.
Here is the caller graph for this function:

◆ real_end() [1/2]

const uint8_t * vlink::Bytes::real_end ( ) const
inlinenodiscardnoexcept

Iterator end for the full backing buffer (const).

Returns
Const pointer to one past the last byte of the raw buffer.

◆ real_end() [2/2]

uint8_t * vlink::Bytes::real_end ( )
inlinenodiscardnoexcept

Iterator end for the full backing buffer (mutable).

Returns
Pointer to one past the last byte of the raw buffer.
Here is the caller graph for this function:

◆ real_size()

size_t vlink::Bytes::real_size ( ) const
inlinenodiscardnoexcept

Returns the total backing-buffer size including the prefix offset region.

real_size() == size() + offset().

Returns
Total size of the backing buffer in bytes.
Here is the caller graph for this function:

◆ release_memory_pool()

void vlink::Bytes::release_memory_pool ( )
staticnoexcept

Releases the global memory pool and returns its memory to the OS.

After this call, bytes_malloc falls back to the system heap allocator. Call once at application shutdown after all Bytes objects that used the pool have been destroyed, to avoid a use-after-free.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reserve()

bool vlink::Bytes::reserve ( size_t new_capacity)
noexcept

Ensures the backing buffer can hold at least new_capacity bytes.

If the current capacity is already >= new_capacity this is a no-op. Otherwise a new buffer is allocated and the existing data is copied.

Parameters
new_capacityMinimum required capacity in bytes.
Returns
true on success, false if allocation failed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

bool vlink::Bytes::resize ( size_t size)
nodiscardnoexcept

Resizes the logical data region to size bytes.

If size <= current capacity, only size_ is updated. If size > current capacity, reserve(size) is called first. Newly added bytes are not initialised.

Parameters
sizeNew desired size in bytes.
Returns
true on success, false if reallocation failed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reverse_order()

Bytes vlink::Bytes::reverse_order ( const Bytes & target)
staticnodiscardnoexcept

Returns a new Bytes object with the byte order of target reversed.

Parameters
targetSource buffer to reverse.
Returns
A new owned Bytes with bytes in reversed order.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shallow_copy() [1/3]

Bytes & vlink::Bytes::shallow_copy ( const Bytes & bytes)
noexcept

Makes this object a non-owning alias of bytes (shallow copy in-place).

Releases the current buffer, then copies the pointer and metadata from bytes without copying the underlying data. After this call is_owner() is false.

Parameters
bytesSource to alias.
Returns
Reference to *this.
Here is the call graph for this function:

◆ shallow_copy() [2/3]

Bytes vlink::Bytes::shallow_copy ( const uint8_t * data,
size_t size )
staticnodiscardnoexcept

Creates a non-owning Bytes alias pointing to an external read-only buffer.

Same as the mutable overload except the data pointer is const. Calling the non-const data() accessor on the result returns nullptr.

Parameters
dataPointer to the external read-only buffer.
sizeLength of the buffer in bytes.
Returns
A non-owning Bytes object wrapping data.
Here is the call graph for this function:

◆ shallow_copy() [3/3]

Bytes vlink::Bytes::shallow_copy ( uint8_t * data,
size_t size )
staticnodiscardnoexcept

Creates a non-owning Bytes alias pointing to an external mutable buffer.

No memory is allocated or copied. The caller is responsible for ensuring the external buffer outlives the returned Bytes object. is_owner() returns false.

Parameters
dataPointer to the external buffer.
sizeLength of the buffer in bytes.
Returns
A non-owning Bytes object wrapping data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shallow_copy_ptr()

Bytes vlink::Bytes::shallow_copy_ptr ( void * data)
staticnodiscardnoexcept

Wraps an opaque pointer without associating a byte size.

Sets size == 0 and offset == 0 so that is_ptr() returns true. Useful for passing opaque C handles or iceoryx chunk pointers through the Bytes transport. The caller owns the pointed-to memory; VLink will not free it.

Parameters
dataOpaque pointer to wrap.
Returns
A non-owning, zero-size Bytes object carrying the pointer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shrink_to()

bool vlink::Bytes::shrink_to ( size_t size)
nodiscardnoexcept

Reduces the logical size of the buffer without reallocating.

Sets size_ to size if size <= current size(); the backing buffer is not freed or shrunk.

Parameters
sizeNew logical size in bytes. Must be <= current size().
Returns
true on success, false if size exceeds the current size.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t vlink::Bytes::size ( ) const
inlinenodiscardnoexcept

Returns the number of usable bytes (excluding the prefix offset region).

Returns
Size in bytes. Returns 0 if empty.
Here is the caller graph for this function:

◆ stack_size()

uint8_t vlink::Bytes::stack_size ( )
inlinestaticnodiscardconstexprnoexcept

Returns the size of the inline stack storage in bytes.

Buffers of this size or smaller use the embedded stack_data_ array and never incur a heap allocation.

Returns
kStackSize (96).
Here is the caller graph for this function:

◆ to_ptr()

template<typename T>
T * vlink::Bytes::to_ptr ( ) const
inlinenodiscardnoexcept

Reinterprets the backing buffer as a pointer to T.

Calls reinterpret_cast<T*>(real_data()). Use with care; alignment must be compatible with T.

Template Parameters
TTarget type. Defaults to void.
Returns
Pointer to T, or nullptr if the buffer is empty.
Here is the caller graph for this function:

◆ to_raw_data()

std::vector< uint8_t > vlink::Bytes::to_raw_data ( ) const
nodiscardnoexcept

Copies the usable byte region into a new std::vector<uint8_t>.

Returns
A vector containing a copy of data()[0..size()-1].
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string()

std::string vlink::Bytes::to_string ( ) const
nodiscardnoexcept

Returns the usable byte region as a std::string.

Returns
A string constructed from data() and size().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string_view()

std::string_view vlink::Bytes::to_string_view ( ) const
nodiscardnoexcept

Returns a zero-copy std::string_view over the usable byte region.

The returned view is valid only as long as this Bytes object is alive and unmodified.

Returns
string_view pointing into the buffer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uncompress_data()

Bytes vlink::Bytes::uncompress_data ( const uint8_t * data,
size_t size,
bool check_valid = true )
staticnodiscardnoexcept

Decompresses a LZAV-compressed Bytes buffer.

Strips the 4-byte header and footer magic, then calls lzav_decompress(). If check_valid is true the magic bytes are validated first; an invalid magic returns an empty Bytes.

Parameters
dataPointer to the compressed buffer (including header/footer).
sizeTotal size of the compressed buffer.
check_validIf true, validate the header/footer magic before decompressing. Default: true.
Returns
Decompressed Bytes, or empty on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<

VLINK_EXPORT friend std::ostream & operator<< ( std::ostream & ostream,
const Bytes & target )
friend

Stream insertion operator – prints bytes as space-separated hex pairs.

Parameters
ostreamOutput stream.
targetBytes to print.
Returns
Reference to ostream.

The documentation for this class was generated from the following file: