|
VLink
2.0.0
A high-performance communication middleware
|
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs. 更多...
#include <bytes.h>
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. 更多... | |
| Bytes & | operator= (const Bytes &target) noexcept |
Copy assignment; converts any source into an owned deep copy of target. 更多... | |
| Bytes & | operator= (Bytes &&target) noexcept |
Move assignment; releases the current buffer and adopts target's state. 更多... | |
| Bytes & | operator= (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. 更多... | |
| Bytes & | shallow_copy (const Bytes &bytes) noexcept |
Replaces this instance with a non-owning alias of bytes. 更多... | |
| Bytes & | deep_copy (const Bytes &bytes) noexcept |
Replaces this instance with an owned deep copy of bytes. 更多... | |
| Bytes & | deep_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.
|
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.
|
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.
| target | Source buffer. |
shallow_copy / loan_internal) instead of the copy constructor.
|
noexcept |
Move constructor; transfers payload, ownership flags and prefix from target.
| target | Source buffer left in the empty state after the move. |
|
noexcept |
Constructs an owned buffer from an initialiser list of bytes.
| list | Byte values to copy into the new buffer. |
|
explicitnoexcept |
Constructs an owned buffer from a std::vector<uint8_t> by deep copy.
| data | Source vector; its contents are copied verbatim. |
|
noexcept |
Destructor; releases owned heap storage and ignores loaned / shallow buffers.
|
inlinenoexcept |
Returns a read-only iterator to the first payload byte.
nullptr when empty.
|
inlinenoexcept |
Returns a mutable iterator to the first payload byte.
nullptr when empty.
|
staticnoexcept |
Returns a buffer previously obtained from bytes_malloc to the pool.
| ptr | Pointer returned by bytes_malloc. nullptr is a no-op. |
| size | Original size; must match the value passed to bytes_malloc. |
|
staticnoexcept |
Allocates a raw aligned byte buffer through the global memory pool.
| size | Number of bytes requested. |
nullptr on upstream OOM. size value must be passed to the matching bytes_free call.
|
inlinenoexcept |
Returns the allocated capacity of the backing buffer.
SBO buffers report kStackSize; pool-allocated buffers report the rounded allocation size.
>= real_size().
|
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.
|
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.
| data | Source pointer. |
| size | Source length in bytes. |
| high_ratio | true to use LZAV's high-compression preset; default false. |
Bytes on failure.
|
staticnoexcept |
Renders a raw byte array as space-separated uppercase hex tokens.
| value | Pointer to the source buffer. |
| size | Number of bytes to render. |
"1A B2 C3" for the input {0x1A, 0xB2, 0xC3}.
|
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.
| size | Number of usable payload bytes after construction. |
| offset | Header bytes reserved before the payload region. Default: 0. |
Bytes instance.
|
inlinenoexcept |
Returns a read-only pointer to the start of the payload (post-offset).
nullptr when empty.
|
inlinenoexcept |
Returns a mutable pointer to the start of the payload (post-offset).
nullptr when empty.
|
staticnoexcept |
Decodes a Base-64 ASCII string back into a binary payload.
| target | Base-64 source string. |
Bytes, or an empty value on invalid input. 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.
| bytes | Source carrier to copy. |
*this.
|
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.
| data | Source read-only buffer. |
| size | Number of bytes to copy. |
| offset | Header bytes reserved in the new buffer. Default: 0. |
Bytes containing the copied payload.
|
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.
| data | Source buffer. |
| size | Number of bytes to copy. |
| offset | Header bytes reserved in the new buffer. Default: 0. |
Bytes containing the copied payload.
|
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.
*this.
|
inlinenoexcept |
|
staticnoexcept |
Encodes a payload as a standard Base-64 ASCII string.
| target | Source buffer. |
|
inlinenoexcept |
Returns a read-only iterator one past the last payload byte.
nullptr when empty.
|
inlinenoexcept |
Returns a mutable iterator one past the last payload byte.
nullptr when empty.
|
staticnoexcept |
|
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.
| str | Source hex string. |
| ok | Optional pointer set to true on success and false on failure. |
Bytes, or an empty value on failure.
|
staticnoexcept |
Computes the CRC-32 (ISO-HDLC) checksum of target.
| target | Source buffer. |
|
staticnoexcept |
Computes the CRC-64 (ECMA-182) checksum of target.
| target | Source buffer. |
|
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.
|
inlinestaticconstexprnoexcept |
Returns true at compile time when the platform is big-endian.
is_little_endian().
|
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.
| data | Pointer to the buffer to inspect. |
| size | Length of the buffer. |
true when both magics match and the size precondition holds.
|
inlinestaticconstexprnoexcept |
Returns true at compile time when the platform is little-endian.
true on x86 / arm-le / Windows; false on big-endian targets.
|
inlinenoexcept |
Reports whether the buffer is an iceoryx loan that VLink must not free.
true for objects produced by loan_internal.
|
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.
|
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.
|
staticnoexcept |
Wraps an iceoryx-loaned read-only payload as a non-owning, non-aliasing carrier.
| data | Pointer to the read-only iceoryx chunk payload. |
| size | Length of the payload in bytes. |
Bytes instance.
|
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.
| data | Pointer to the iceoryx chunk payload. |
| size | Length of the payload in bytes. |
Bytes instance.
|
inlinenoexcept |
Returns the reserved header offset preceding the payload.
|
noexcept |
Byte-wise inequality comparison with another Bytes.
| target | Right-hand operand. |
true when either the sizes or the payload bytes differ.
|
noexcept |
Byte-wise inequality comparison with a std::vector<uint8_t>.
| data | Right-hand operand. |
true when either the sizes or the bytes differ. Move assignment; releases the current buffer and adopts target's state.
| target | Source buffer left empty after the move. |
*this. 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.
| target | Source buffer. |
*this.
|
noexcept |
Replaces the payload with a deep copy of data.
| data | Source vector. |
*this.
|
noexcept |
Byte-wise equality comparison with another Bytes.
| target | Right-hand operand. |
true when sizes and payload bytes match exactly.
|
noexcept |
Byte-wise equality comparison with a std::vector<uint8_t>.
| data | Right-hand operand. |
true when sizes and bytes match exactly.
|
inlinenoexcept |
Read-only indexed access into the payload region.
| index | Zero-based logical offset within the payload. |
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()).
| index | Zero-based logical offset within the payload. |
index.
|
inlinenoexcept |
Returns a read-only iterator to the start of the raw backing region.
real_data().
|
inlinenoexcept |
Returns a mutable iterator to the start of the raw backing region.
real_data().
|
inlinenoexcept |
Returns a read-only pointer to the very beginning of the backing buffer.
nullptr when empty.
|
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().
nullptr when empty.
|
inlinenoexcept |
Returns a read-only iterator one past the prefix-plus-payload region.
nullptr when empty.
|
inlinenoexcept |
Returns a mutable iterator one past the prefix-plus-payload region.
nullptr when empty.
|
inlinenoexcept |
|
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.
|
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_capacity | Minimum required capacity. |
true on success; false for non-owned buffers or allocation failure.
|
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.
| size | New payload size in bytes. |
true on success; false for non-owned buffers or reallocation failure. Returns a new owned Bytes with the byte order of target reversed.
| target | Source buffer to reverse. |
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.
| bytes | Source carrier to alias. |
*this.
|
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.
| data | External read-only buffer to alias. |
| size | Length of the buffer in bytes. |
Bytes pointing at data.
|
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.
| data | External buffer to alias. |
| size | Length of the buffer in bytes. |
Bytes pointing at 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.
| data | Opaque pointer value to embed. |
Bytes carrying data.
|
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.
| size | New logical size in bytes. |
true on success; false for non-owned buffers or oversized requests.
|
inlinenoexcept |
Returns the size of the payload region in bytes.
|
inlinestaticconstexprnoexcept |
Returns the SBO threshold below which payloads stay inline.
kStackSize (96).
|
inlinenoexcept |
Reinterprets the backing pointer as T*.
Equivalent to reinterpret_cast<T*>(real_data()). Caller is responsible for alignment.
| T | Target pointee type. Defaults to void. |
T, or nullptr when empty.
|
noexcept |
|
noexcept |
Materialises the payload region as a new std::string.
|
noexcept |
|
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.
| data | Framed source pointer. |
| size | Framed source length in bytes. |
| check_valid | true to verify magics before decompressing. Default: true. |
Bytes on failure.
|
friend |
Stream insertion operator; prints the payload as space-separated hex bytes.
| ostream | Target output stream. |
| target | Buffer to print. |
ostream.