VLink  2.0.0
A high-performance communication middleware
vlink::Bytes类 参考final

Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs. 更多...

#include <bytes.h>

vlink::Bytes 的协作图:

Public 成员函数

 Bytes () noexcept
 Constructs an empty, non-owning carrier with no payload. 更多...
 
 Bytes (const Bytes &target) noexcept
 Copy constructor; converts any source into an owned deep copy. 更多...
 
 Bytes (Bytes &&target) noexcept
 Move constructor; transfers payload, ownership flags and prefix from target. 更多...
 
 Bytes (const std::initializer_list< uint8_t > &list) noexcept
 Constructs an owned buffer from an initialiser list of bytes. 更多...
 
 Bytes (const std::vector< uint8_t > &data) noexcept
 Constructs an owned buffer from a std::vector<uint8_t> by deep copy. 更多...
 
 ~Bytes () noexcept
 Destructor; releases owned heap storage and ignores loaned / shallow buffers. 更多...
 
Bytesoperator= (const Bytes &target) noexcept
 Copy assignment; converts any source into an owned deep copy of target. 更多...
 
Bytesoperator= (Bytes &&target) noexcept
 Move assignment; releases the current buffer and adopts target's state. 更多...
 
Bytesoperator= (const std::vector< uint8_t > &data) noexcept
 Replaces the payload with a deep copy of data. 更多...
 
bool operator== (const Bytes &target) const noexcept
 Byte-wise equality comparison with another Bytes. 更多...
 
bool operator!= (const Bytes &target) const noexcept
 Byte-wise inequality comparison with another Bytes. 更多...
 
bool operator== (const std::vector< uint8_t > &data) const noexcept
 Byte-wise equality comparison with a std::vector<uint8_t>. 更多...
 
bool operator!= (const std::vector< uint8_t > &data) const noexcept
 Byte-wise inequality comparison with a std::vector<uint8_t>. 更多...
 
uint8_t & operator[] (size_t index) noexcept
 Mutable indexed access into the payload region. 更多...
 
const uint8_t & operator[] (size_t index) const noexcept
 Read-only indexed access into the payload region. 更多...
 
uint8_t * data () noexcept
 Returns a mutable pointer to the start of the payload (post-offset). 更多...
 
const uint8_t * data () const noexcept
 Returns a read-only pointer to the start of the payload (post-offset). 更多...
 
uint8_t * real_data () noexcept
 Returns a mutable pointer to the very beginning of the backing buffer. 更多...
 
const uint8_t * real_data () const noexcept
 Returns a read-only pointer to the very beginning of the backing buffer. 更多...
 
size_t size () const noexcept
 Returns the size of the payload region in bytes. 更多...
 
size_t real_size () const noexcept
 Returns the size of the used backing region (payload plus prefix offset). 更多...
 
size_t capacity () const noexcept
 Returns the allocated capacity of the backing buffer. 更多...
 
uint8_t offset () const noexcept
 Returns the reserved header offset preceding the payload. 更多...
 
bool is_owner () const noexcept
 Reports whether this instance owns and will free its storage. 更多...
 
bool is_loaned () const noexcept
 Reports whether the buffer is an iceoryx loan that VLink must not free. 更多...
 
bool empty () const noexcept
 Reports whether the buffer is logically empty. 更多...
 
uint8_t * begin () noexcept
 Returns a mutable iterator to the first payload byte. 更多...
 
const uint8_t * begin () const noexcept
 Returns a read-only iterator to the first payload byte. 更多...
 
uint8_t * end () noexcept
 Returns a mutable iterator one past the last payload byte. 更多...
 
const uint8_t * end () const noexcept
 Returns a read-only iterator one past the last payload byte. 更多...
 
uint8_t * real_begin () noexcept
 Returns a mutable iterator to the start of the raw backing region. 更多...
 
const uint8_t * real_begin () const noexcept
 Returns a read-only iterator to the start of the raw backing region. 更多...
 
uint8_t * real_end () noexcept
 Returns a mutable iterator one past the prefix-plus-payload region. 更多...
 
const uint8_t * real_end () const noexcept
 Returns a read-only iterator one past the prefix-plus-payload region. 更多...
 
bool is_ptr () const noexcept
 Reports whether this carrier merely wraps an opaque pointer. 更多...
 
std::vector< uint8_t > to_raw_data () const noexcept
 Copies the payload region into a new std::vector<uint8_t>. 更多...
 
std::string to_string () const noexcept
 Materialises the payload region as a new std::string. 更多...
 
std::string_view to_string_view () const noexcept
 Returns a non-owning std::string_view into the payload region. 更多...
 
template<typename T = void>
T * to_ptr () const noexcept
 Reinterprets the backing pointer as T*. 更多...
 
void clear () noexcept
 Releases owned storage and resets all metadata to the empty state. 更多...
 
bool shrink_to (size_t size) noexcept
 Truncates the logical payload size in place without reallocating. 更多...
 
bool reserve (size_t new_capacity) noexcept
 Ensures the backing capacity is at least new_capacity bytes. 更多...
 
bool resize (size_t size) noexcept
 Resizes the logical payload region to size bytes. 更多...
 
Bytesshallow_copy (const Bytes &bytes) noexcept
 Replaces this instance with a non-owning alias of bytes. 更多...
 
Bytesdeep_copy (const Bytes &bytes) noexcept
 Replaces this instance with an owned deep copy of bytes. 更多...
 
Bytesdeep_copy_self () noexcept
 Converts an existing non-owning carrier into an owning one in place. 更多...
 

静态 Public 成员函数

static void init_memory_pool () noexcept
 Eagerly constructs the process-wide MemoryPool that backs heap allocations. 更多...
 
static void release_memory_pool () noexcept
 Releases every empty chunk currently cached by the Bytes memory pool. 更多...
 
static uint8_t * bytes_malloc (size_t size) noexcept
 Allocates a raw aligned byte buffer through the global memory pool. 更多...
 
static void bytes_free (uint8_t *ptr, size_t size) noexcept
 Returns a buffer previously obtained from bytes_malloc to the pool. 更多...
 
static Bytes create (size_t size, uint8_t offset=0) noexcept
 Allocates an owned buffer of the requested size with an optional header offset. 更多...
 
static Bytes shallow_copy (uint8_t *data, size_t size) noexcept
 Wraps an external mutable buffer as a non-owning alias. 更多...
 
static Bytes shallow_copy (const uint8_t *data, size_t size) noexcept
 Wraps an external read-only buffer as a non-owning alias. 更多...
 
static Bytes shallow_copy_ptr (void *data) noexcept
 Wraps an opaque pointer as a zero-size pointer carrier. 更多...
 
static Bytes deep_copy (uint8_t *data, size_t size, uint8_t offset=0) noexcept
 Produces an owned copy of an external mutable buffer. 更多...
 
static Bytes deep_copy (const uint8_t *data, size_t size, uint8_t offset=0) noexcept
 Produces an owned copy of an external read-only buffer. 更多...
 
static Bytes loan_internal (uint8_t *data, size_t size) noexcept
 Wraps an iceoryx-loaned mutable payload as a non-owning, non-aliasing carrier. 更多...
 
static Bytes loan_internal (const uint8_t *data, size_t size) noexcept
 Wraps an iceoryx-loaned read-only payload as a non-owning, non-aliasing carrier. 更多...
 
static Bytes from_string (const std::string &str, uint8_t offset=0) noexcept
 Builds an owned Bytes from the bytes of a UTF-8 string. 更多...
 
static Bytes from_user_input (const std::string &str, bool *ok=nullptr) noexcept
 Parses a user-typed hex literal into a Bytes payload. 更多...
 
static std::string convert_to_hex_str (const uint8_t *value, size_t size) noexcept
 Renders a raw byte array as space-separated uppercase hex tokens. 更多...
 
static Bytes reverse_order (const Bytes &target) noexcept
 Returns a new owned Bytes with the byte order of target reversed. 更多...
 
static std::string encode_to_base64 (const Bytes &target) noexcept
 Encodes a payload as a standard Base-64 ASCII string. 更多...
 
static Bytes decode_from_base64 (const std::string &target) noexcept
 Decodes a Base-64 ASCII string back into a binary payload. 更多...
 
static uint32_t get_crc_32 (const Bytes &target) noexcept
 Computes the CRC-32 (ISO-HDLC) checksum of target. 更多...
 
static uint64_t get_crc_64 (const Bytes &target) noexcept
 Computes the CRC-64 (ECMA-182) checksum of target. 更多...
 
static constexpr uint8_t stack_size () noexcept
 Returns the SBO threshold below which payloads stay inline. 更多...
 
static constexpr bool is_little_endian () noexcept
 Returns true at compile time when the platform is little-endian. 更多...
 
static constexpr bool is_big_endian () noexcept
 Returns true at compile time when the platform is big-endian. 更多...
 
static bool is_compress_data (const uint8_t *data, size_t size) noexcept
 Detects whether a raw byte buffer matches the VLink LZAV compression frame layout. 更多...
 
static Bytes compress_data (const uint8_t *data, size_t size, bool high_ratio=false) noexcept
 Compresses a payload using LZAV and wraps it in the VLink compression frame. 更多...
 
static Bytes uncompress_data (const uint8_t *data, size_t size, bool check_valid=true) noexcept
 Decompresses an LZAV-framed buffer back into its original payload. 更多...
 

友元

VLINK_EXPORT friend std::ostream & operator<< (std::ostream &ostream, const Bytes &target) noexcept
 Stream insertion operator; prints the payload as space-separated hex bytes. 更多...
 

详细描述

Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.

Implements VLink's universal binary carrier. Small payloads live inside the embedded stack_data_ array; larger payloads spill to the global MemoryPool. Ownership is encoded in two flags (is_owner_, is_loaned_) so the destructor can route to the correct release primitive: heap free, iceoryx loan release, or no-op for shallow aliases. All public functions are noexcept; failure is reported via empty return values.

构造及析构函数说明

◆ Bytes() [1/5]

vlink::Bytes::Bytes ( )
noexcept

Constructs an empty, non-owning carrier with no payload.

data() is nullptr and size() is 0; both is_owner() and is_loaned() are false. The SBO region is zero-initialised.

◆ Bytes() [2/5]

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

Copy constructor; converts any source into an owned deep copy.

Allocates a fresh buffer through the memory pool and copies target's bytes into it when target carries data. Empty inputs yield an empty non-owning result. The copy is always an owner regardless of the source's ownership tags – aliasing and loaned semantics are not preserved by this constructor.

参数
targetSource buffer.
注解
To keep aliasing or loaned semantics use the explicit factory methods (shallow_copy / loan_internal) instead of the copy constructor.

◆ Bytes() [3/5]

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

Move constructor; transfers payload, ownership flags and prefix from target.

参数
targetSource buffer left in the empty state after the move.

◆ Bytes() [4/5]

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

Constructs an owned buffer from an initialiser list of bytes.

参数
listByte values to copy into the new buffer.

◆ Bytes() [5/5]

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

Constructs an owned buffer from a std::vector<uint8_t> by deep copy.

参数
dataSource vector; its contents are copied verbatim.

◆ ~Bytes()

vlink::Bytes::~Bytes ( )
noexcept

Destructor; releases owned heap storage and ignores loaned / shallow buffers.

成员函数说明

◆ begin() [1/2]

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

Returns a read-only iterator to the first payload byte.

返回
Pointer to the first payload byte, or nullptr when empty.

◆ begin() [2/2]

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

Returns a mutable iterator to the first payload byte.

返回
Pointer to the first payload byte, or nullptr when empty.

◆ bytes_free()

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

Returns a buffer previously obtained from bytes_malloc to the pool.

参数
ptrPointer returned by bytes_malloc. nullptr is a no-op.
sizeOriginal size; must match the value passed to bytes_malloc.

◆ bytes_malloc()

static uint8_t* vlink::Bytes::bytes_malloc ( size_t  size)
staticnoexcept

Allocates a raw aligned byte buffer through the global memory pool.

参数
sizeNumber of bytes requested.
返回
Pointer to the newly allocated buffer, or nullptr on upstream OOM.
注解
The same size value must be passed to the matching bytes_free call.

◆ capacity()

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

Returns the allocated capacity of the backing buffer.

SBO buffers report kStackSize; pool-allocated buffers report the rounded allocation size.

返回
Capacity in bytes; always >= real_size().

◆ clear()

void vlink::Bytes::clear ( )
noexcept

Releases owned storage and resets all metadata to the empty state.

When is_owner() is true the backing buffer is returned to the pool; loaned and shallow carriers are simply forgotten. After the call empty() reports true.

◆ compress_data()

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

Compresses a payload using LZAV and wraps it in the VLink compression frame.

Emits the layout shown in the file-level diagram. Inputs larger than 1 MiB (kMaxCompressCacheSize) are rejected and produce an empty result.

参数
dataSource pointer.
sizeSource length in bytes.
high_ratiotrue to use LZAV's high-compression preset; default false.
返回
Compressed framed buffer, or an empty Bytes on failure.

◆ convert_to_hex_str()

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

Renders a raw byte array as space-separated uppercase hex tokens.

参数
valuePointer to the source buffer.
sizeNumber of bytes to render.
返回
Hex string such as "1A B2 C3" for the input {0x1A, 0xB2, 0xC3}.

◆ create()

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

Allocates an owned buffer of the requested size with an optional header offset.

Payloads up to kStackSize stay in stack_data_; larger payloads use the memory pool. The content is left uninitialised. When offset is non-zero the first offset bytes of the backing buffer are reserved so transport layers can prepend frame headers in place; data() then points past the reserved prefix.

参数
sizeNumber of usable payload bytes after construction.
offsetHeader bytes reserved before the payload region. Default: 0.
返回
New owning Bytes instance.
这是这个函数的调用关系图:

◆ data() [1/2]

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

Returns a read-only pointer to the start of the payload (post-offset).

返回
Pointer to the first payload byte, or nullptr when empty.

◆ data() [2/2]

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

Returns a mutable pointer to the start of the payload (post-offset).

返回
Pointer to the first payload byte, or nullptr when empty.
这是这个函数的调用关系图:

◆ decode_from_base64()

static Bytes vlink::Bytes::decode_from_base64 ( const std::string &  target)
staticnoexcept

Decodes a Base-64 ASCII string back into a binary payload.

参数
targetBase-64 source string.
返回
Decoded Bytes, or an empty value on invalid input.

◆ deep_copy() [1/3]

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

Replaces this instance with an owned deep copy of bytes.

Releases any owned storage first, then allocates and populates a fresh buffer when bytes carries data. Empty sources leave this instance empty and non-owning.

参数
bytesSource carrier to copy.
返回
Reference to *this.

◆ deep_copy() [2/3]

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

Produces an owned copy of an external read-only buffer.

Read-only overload of deep_copy(uint8_t*, size_t, uint8_t). Ownership rules for empty sources match the mutable overload exactly.

参数
dataSource read-only buffer.
sizeNumber of bytes to copy.
offsetHeader bytes reserved in the new buffer. Default: 0.
返回
Owning Bytes containing the copied payload.

◆ deep_copy() [3/3]

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

Produces an owned copy of an external mutable buffer.

Allocates a fresh buffer and memcpy s size bytes from data into it. When the source is empty (null pointer or zero size) and offset is 0 the result is empty and non-owning; with a non-zero offset only the prefix region is allocated.

参数
dataSource buffer.
sizeNumber of bytes to copy.
offsetHeader bytes reserved in the new buffer. Default: 0.
返回
Owning Bytes containing the copied payload.
这是这个函数的调用关系图:

◆ deep_copy_self()

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

Converts an existing non-owning carrier into an owning one in place.

Owners are returned unchanged. Empty carriers are cleared. Otherwise a fresh buffer is allocated and the current payload copied into it.

返回
Reference to *this.

◆ empty()

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

Reports whether the buffer is logically empty.

返回
true when data() is nullptr and size() is 0.
这是这个函数的调用关系图:

◆ encode_to_base64()

static std::string vlink::Bytes::encode_to_base64 ( const Bytes target)
staticnoexcept

Encodes a payload as a standard Base-64 ASCII string.

参数
targetSource buffer.
返回
Base-64 string representation.

◆ end() [1/2]

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

Returns a read-only iterator one past the last payload byte.

返回
End pointer, or nullptr when empty.

◆ end() [2/2]

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

Returns a mutable iterator one past the last payload byte.

返回
End pointer, or nullptr when empty.

◆ from_string()

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

Builds an owned Bytes from the bytes of a UTF-8 string.

参数
strSource string; copied byte-for-byte.
offsetHeader bytes reserved before the payload. Default: 0.
返回
Owning Bytes containing str. Empty input with zero offset yields an empty result.

◆ from_user_input()

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

Parses a user-typed hex literal into a Bytes payload.

Accepts space-separated byte tokens ("1A @c 2B"), a contiguous even-length hex run with or without a 0x / 0X prefix ("0x1A2B"), or mixed forms. Returns an empty result on parse failure and sets ok to false.

参数
strSource hex string.
okOptional pointer set to true on success and false on failure.
返回
Parsed Bytes, or an empty value on failure.

◆ get_crc_32()

static uint32_t vlink::Bytes::get_crc_32 ( const Bytes target)
staticnoexcept

Computes the CRC-32 (ISO-HDLC) checksum of target.

参数
targetSource buffer.
返回
32-bit CRC-32 value.

◆ get_crc_64()

static uint64_t vlink::Bytes::get_crc_64 ( const Bytes target)
staticnoexcept

Computes the CRC-64 (ECMA-182) checksum of target.

参数
targetSource buffer.
返回
64-bit CRC-64 value.

◆ init_memory_pool()

static void vlink::Bytes::init_memory_pool ( )
staticnoexcept

Eagerly constructs the process-wide MemoryPool that backs heap allocations.

Bytes::bytes_malloc routes through MemoryPool::global_instance(). Calling this once at program start front-loads the singleton construction cost and respects VLINK_MEMORY_LEVEL / VLINK_MEMORY_PREALLOC. Subsequent calls are idempotent no-ops.

这是这个函数的调用关系图:

◆ is_big_endian()

constexpr bool vlink::Bytes::is_big_endian ( )
inlinestaticconstexprnoexcept

Returns true at compile time when the platform is big-endian.

返回
Logical negation of is_little_endian().
函数调用图:

◆ is_compress_data()

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

Detects whether a raw byte buffer matches the VLink LZAV compression frame layout.

Validates the 4-byte header magic (17 49 B2 6F), the 4-byte footer magic (A7 05 ED 71) and that the buffer is at least 13 bytes long.

参数
dataPointer to the buffer to inspect.
sizeLength of the buffer.
返回
true when both magics match and the size precondition holds.

◆ is_little_endian()

constexpr bool vlink::Bytes::is_little_endian ( )
inlinestaticconstexprnoexcept

Returns true at compile time when the platform is little-endian.

返回
true on x86 / arm-le / Windows; false on big-endian targets.
这是这个函数的调用关系图:

◆ is_loaned()

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

Reports whether the buffer is an iceoryx loan that VLink must not free.

返回
true for objects produced by loan_internal.
这是这个函数的调用关系图:

◆ is_owner()

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

Reports whether this instance owns and will free its storage.

返回
true for objects produced by create / deep_copy and surviving copy/move assignments that produced an owned deep copy.

◆ is_ptr()

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

Reports whether this carrier merely wraps an opaque pointer.

A pointer-only wrapper satisfies data_ != nullptr, size_ == 0, offset_ == 0 and is_owner_ == false. Retrieve the underlying pointer via to_ptr<T>().

返回
true when this is a pointer-only wrapper.
这是这个函数的调用关系图:

◆ loan_internal() [1/2]

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

Wraps an iceoryx-loaned read-only payload as a non-owning, non-aliasing carrier.

参数
dataPointer to the read-only iceoryx chunk payload.
sizeLength of the payload in bytes.
返回
Loaned Bytes instance.

◆ loan_internal() [2/2]

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

Wraps an iceoryx-loaned mutable payload as a non-owning, non-aliasing carrier.

Marks is_loaned() as true so the destructor skips the free call – the underlying memory is owned by RouDi. Used internally by the shm:// transport backend.

参数
dataPointer to the iceoryx chunk payload.
sizeLength of the payload in bytes.
返回
Loaned Bytes instance.

◆ offset()

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

Returns the reserved header offset preceding the payload.

返回
Offset in bytes.

◆ operator!=() [1/2]

bool vlink::Bytes::operator!= ( const Bytes target) const
noexcept

Byte-wise inequality comparison with another Bytes.

参数
targetRight-hand operand.
返回
true when either the sizes or the payload bytes differ.

◆ operator!=() [2/2]

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

Byte-wise inequality comparison with a std::vector<uint8_t>.

参数
dataRight-hand operand.
返回
true when either the sizes or the bytes differ.

◆ operator=() [1/3]

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

Move assignment; releases the current buffer and adopts target's state.

参数
targetSource buffer left empty after the move.
返回
Reference to *this.

◆ operator=() [2/3]

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

Copy assignment; converts any source into an owned deep copy of target.

Releases the current buffer first when this instance owns one. Empty sources produce an empty non-owning result.

参数
targetSource buffer.
返回
Reference to *this.

◆ operator=() [3/3]

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

Replaces the payload with a deep copy of data.

参数
dataSource vector.
返回
Reference to *this.

◆ operator==() [1/2]

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

Byte-wise equality comparison with another Bytes.

参数
targetRight-hand operand.
返回
true when sizes and payload bytes match exactly.

◆ operator==() [2/2]

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

Byte-wise equality comparison with a std::vector<uint8_t>.

参数
dataRight-hand operand.
返回
true when sizes and bytes match exactly.

◆ operator[]() [1/2]

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

Read-only indexed access into the payload region.

参数
indexZero-based logical offset within the payload.
返回
Const reference to the byte at index.

◆ operator[]() [2/2]

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

Mutable indexed access into the payload region.

Details

Resolves to real_data()[offset() + index]. No bounds checking is performed; pass indices in [0, size()).

参数
indexZero-based logical offset within the payload.
返回
Reference to the byte at index.

◆ real_begin() [1/2]

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

Returns a read-only iterator to the start of the raw backing region.

返回
Pointer equal to real_data().

◆ real_begin() [2/2]

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

Returns a mutable iterator to the start of the raw backing region.

返回
Pointer equal to real_data().

◆ real_data() [1/2]

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

Returns a read-only pointer to the very beginning of the backing buffer.

返回
Pointer to the raw buffer origin, or nullptr when empty.

◆ real_data() [2/2]

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

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

real_data() points at the prefix region; real_data() + offset() equals data().

返回
Pointer to the raw buffer origin, or nullptr when empty.
这是这个函数的调用关系图:

◆ real_end() [1/2]

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

Returns a read-only iterator one past the prefix-plus-payload region.

返回
End pointer for the used backing region, or nullptr when empty.

◆ real_end() [2/2]

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

Returns a mutable iterator one past the prefix-plus-payload region.

返回
End pointer for the used backing region, or nullptr when empty.

◆ real_size()

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

Returns the size of the used backing region (payload plus prefix offset).

返回
size() + offset().

◆ release_memory_pool()

static void vlink::Bytes::release_memory_pool ( )
staticnoexcept

Releases every empty chunk currently cached by the Bytes memory pool.

Forwards to MemoryPool::global_instance().trim(). Only chunks whose blocks are entirely on their tier's free list are returned to the system allocator; chunks still backing a live Bytes instance are preserved. Lifetime statistics and the geometric chunk-growth state are kept intact.

注解
Safe to invoke concurrently with allocations and frees; treat as a periodic maintenance call rather than a hot-path primitive.

◆ reserve()

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

Ensures the backing capacity is at least new_capacity bytes.

Valid only for owned buffers. When the current capacity already satisfies the request the call is a no-op; otherwise a fresh buffer is allocated and the existing payload copied.

参数
new_capacityMinimum required capacity.
返回
true on success; false for non-owned buffers or allocation failure.

◆ resize()

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

Resizes the logical payload region to size bytes.

Valid only for owned buffers. When size exceeds the current capacity reserve is invoked first. Newly exposed bytes are uninitialised unless the build defines VLINK_BYTES_MEM_RESET.

参数
sizeNew payload size in bytes.
返回
true on success; false for non-owned buffers or reallocation failure.

◆ reverse_order()

static Bytes vlink::Bytes::reverse_order ( const Bytes target)
staticnoexcept

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

参数
targetSource buffer to reverse.
返回
New owned buffer with reversed byte order.

◆ shallow_copy() [1/3]

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

Replaces this instance with a non-owning alias of bytes.

Releases any owned storage first. Copies bytes's raw pointer, size and offset without copying the payload. The result is non-owning regardless of bytes's loaned tag; use loan_internal directly to preserve loaned semantics.

参数
bytesSource carrier to alias.
返回
Reference to *this.

◆ shallow_copy() [2/3]

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

Wraps an external read-only buffer as a non-owning alias.

Identical to the mutable overload; the const pointer is stored verbatim through a const_cast so the non-const data() accessor returns the same address.

参数
dataExternal read-only buffer to alias.
sizeLength of the buffer in bytes.
返回
Non-owning Bytes pointing at data.

◆ shallow_copy() [3/3]

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

Wraps an external mutable buffer as a non-owning alias.

Performs no allocation and no copy. The caller guarantees the lifetime of data exceeds the lifetime of the returned object.

参数
dataExternal buffer to alias.
sizeLength of the buffer in bytes.
返回
Non-owning Bytes pointing at data.
这是这个函数的调用关系图:

◆ shallow_copy_ptr()

static Bytes vlink::Bytes::shallow_copy_ptr ( void *  data)
staticnoexcept

Wraps an opaque pointer as a zero-size pointer carrier.

Sets size() and offset() to 0 so is_ptr() reports true. The wrapped pointer is retrieved through to_ptr<T>(); ownership stays with the caller.

参数
dataOpaque pointer value to embed.
返回
Non-owning, zero-size Bytes carrying data.
这是这个函数的调用关系图:

◆ shrink_to()

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

Truncates the logical payload size in place without reallocating.

Valid only for owned buffers. size must be <= current size(); the backing capacity is unchanged.

参数
sizeNew logical size in bytes.
返回
true on success; false for non-owned buffers or oversized requests.

◆ size()

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

Returns the size of the payload region in bytes.

返回
Number of payload bytes (excluding the prefix offset).
这是这个函数的调用关系图:

◆ stack_size()

constexpr uint8_t vlink::Bytes::stack_size ( )
inlinestaticconstexprnoexcept

Returns the SBO threshold below which payloads stay inline.

返回
kStackSize (96).

◆ to_ptr()

template<typename T >
T * vlink::Bytes::to_ptr
inlinenoexcept

Reinterprets the backing pointer as T*.

Equivalent to reinterpret_cast<T*>(real_data()). Caller is responsible for alignment.

模板参数
TTarget pointee type. Defaults to void.
返回
Pointer to T, or nullptr when empty.
这是这个函数的调用关系图:

◆ to_raw_data()

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

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

返回
Vector mirroring data()[0, size()).

◆ to_string()

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

Materialises the payload region as a new std::string.

返回
Owning string with the payload bytes.

◆ to_string_view()

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

Returns a non-owning std::string_view into the payload region.

The view is valid until the next mutation of this Bytes instance or its destruction.

返回
View covering data()[0, size()).

◆ uncompress_data()

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

Decompresses an LZAV-framed buffer back into its original payload.

Strips the header / size / footer fields and feeds the LZAV payload to lzav_decompress. When check_valid is true the magics are verified up front; invalid magics yield an empty result. Stored original sizes of 0 or above 256 MiB are also rejected.

参数
dataFramed source pointer.
sizeFramed source length in bytes.
check_validtrue to verify magics before decompressing. Default: true.
返回
Decompressed payload, or an empty Bytes on failure.

友元及相关函数文档

◆ operator<<

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

Stream insertion operator; prints the payload as space-separated hex bytes.

参数
ostreamTarget output stream.
targetBuffer to print.
返回
Reference to ostream.

该类的文档由以下文件生成: