367 Bytes(const
std::initializer_list<uint8_t>& list) noexcept;
417 [[nodiscard]]
bool operator==(const
Bytes& target) const noexcept;
425 [[nodiscard]]
bool operator!=(const
Bytes& target) const noexcept;
433 [[nodiscard]]
bool operator==(const
std::vector<uint8_t>&
data) const noexcept;
441 [[nodiscard]]
bool operator!=(const
std::vector<uint8_t>&
data) const noexcept;
453 [[nodiscard]] uint8_t& operator[](
size_t index) noexcept;
461 [[nodiscard]] const uint8_t& operator[](
size_t index) const noexcept;
472 [[nodiscard]] uint8_t*
data() noexcept;
479 [[nodiscard]] const uint8_t*
data() const noexcept;
490 [[nodiscard]] uint8_t*
real_data() noexcept;
497 [[nodiscard]] const uint8_t*
real_data() const noexcept;
504 [[nodiscard]]
size_t size() const noexcept;
514 [[nodiscard]]
size_t real_size() const noexcept;
524 [[nodiscard]]
size_t capacity() const noexcept;
534 [[nodiscard]] uint8_t
offset() const noexcept;
541 [[nodiscard]]
bool is_owner() const noexcept;
551 [[nodiscard]]
bool is_loaned() const noexcept;
558 [[nodiscard]]
bool empty() const noexcept;
565 [[nodiscard]] uint8_t*
begin() noexcept;
572 [[nodiscard]] const uint8_t*
begin() const noexcept;
579 [[nodiscard]] uint8_t*
end() noexcept;
586 [[nodiscard]] const uint8_t*
end() const noexcept;
600 [[nodiscard]] const uint8_t*
real_begin() const noexcept;
607 [[nodiscard]] uint8_t*
real_end() noexcept;
614 [[nodiscard]] const uint8_t*
real_end() const noexcept;
625 [[nodiscard]]
bool is_ptr() const noexcept;
661 template <typename T =
void>
662 [[nodiscard]] T*
to_ptr() const noexcept;
673 [[nodiscard]] static constexpr uint8_t
stack_size() noexcept;
691 [[nodiscard]] static constexpr
bool is_big_endian() noexcept;
831 enum Type : uint8_t {
838 Bytes(Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned)
noexcept;
840 void process_type(Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned,
Bytes* tmp =
nullptr) noexcept;
842 static constexpr uint8_t kStackSize{96};
843 alignas(std::max_align_t) uint8_t stack_data_[kStackSize]{0};
844 bool is_owner_{
false};
845 bool is_loaned_{
false};
847 uint8_t* data_{
nullptr};
858inline const uint8_t&
Bytes::operator[](
size_t index)
const noexcept {
return data_[offset_ + index]; }
860inline uint8_t*
Bytes::data() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
862inline const uint8_t*
Bytes::data() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
880inline bool Bytes::empty() const noexcept {
return data_ ==
nullptr && size_ == 0; }
882inline uint8_t*
Bytes::begin() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
884inline const uint8_t*
Bytes::begin() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
886inline uint8_t*
Bytes::end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
888inline const uint8_t*
Bytes::end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
894inline uint8_t*
Bytes::real_end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
896inline const uint8_t*
Bytes::real_end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
898inline bool Bytes::is_ptr() const noexcept {
return data_ !=
nullptr && size_ == 0 && offset_ == 0 && !is_owner_; }
902 return reinterpret_cast<T*
>(data_);
908#if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || \
909 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
911#elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
Versatile 128-byte byte buffer with SBO, five ownership modes and compression helpers.
定义 bytes.h:113
static Bytes reverse_order(const Bytes &target) noexcept
Returns a new Bytes object with the byte order of target reversed.
bool empty() const noexcept
Returns true if the buffer is empty (no data pointer and size == 0).
定义 bytes.h:880
bool is_owner() const noexcept
Returns true if this object owns and is responsible for freeing its buffer.
定义 bytes.h:876
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.
size_t capacity() const noexcept
Returns the allocated capacity of the backing buffer.
定义 bytes.h:872
std::vector< uint8_t > to_raw_data() const noexcept
Copies the usable byte region into a new std::vector<uint8_t>.
static Bytes uncompress_data(const uint8_t *data, size_t size, bool check_valid=true) noexcept
Decompresses a LZAV-compressed Bytes buffer.
static void init_memory_pool() noexcept
Initialises the global thread-safe memory pool for Bytes allocations.
static bool is_compress_data(const uint8_t *data, size_t size) noexcept
Checks whether a raw byte buffer contains LZAV-compressed VLink data.
Bytes & deep_copy_self() noexcept
Converts this object from a non-owning alias to a fully owned deep copy of its own data.
static Bytes decode_from_base64(const std::string &target) noexcept
Decodes a Base-64 ASCII string into a Bytes buffer.
static std::string encode_to_base64(const Bytes &target) noexcept
Encodes a Bytes buffer as a standard Base-64 ASCII string.
uint8_t * end() noexcept
Iterator end (mutable) – one past the last usable byte.
定义 bytes.h:886
bool is_loaned() const noexcept
Returns true if this object holds an iceoryx loaned chunk.
定义 bytes.h:878
static Bytes shallow_copy_ptr(void *data) noexcept
Wraps an opaque pointer without associating a byte size.
static constexpr bool is_little_endian() noexcept
Returns true if the platform uses little-endian byte order.
定义 bytes.h:907
uint8_t & operator[](size_t index) noexcept
Mutable subscript operator.
定义 bytes.h:856
static Bytes shallow_copy(uint8_t *data, size_t size) noexcept
Creates a non-owning Bytes alias pointing to an external mutable buffer.
uint8_t * real_data() noexcept
Returns a pointer to the very beginning of the backing buffer (before the offset).
定义 bytes.h:864
bool is_ptr() const noexcept
Returns true if the object holds only an opaque pointer (size == 0 and not owner).
定义 bytes.h:898
uint8_t * begin() noexcept
Iterator begin (mutable) – same as data().
定义 bytes.h:882
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 constexpr uint8_t stack_size() noexcept
Returns the size of the inline stack storage in bytes.
定义 bytes.h:905
static uint8_t * bytes_malloc(size_t size) noexcept
Allocates a raw byte buffer from the memory pool (or heap if pool is unavailable).
uint8_t * real_end() noexcept
Iterator end for the full backing buffer (mutable).
定义 bytes.h:894
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 uint32_t get_crc_32(const Bytes &target) noexcept
Computes the CRC-32 checksum of a Bytes buffer.
bool reserve(size_t new_capacity) noexcept
Ensures the backing buffer can hold at least new_capacity bytes.
Bytes() noexcept
Constructs an empty, unallocated Bytes object.
size_t size() const noexcept
Returns the number of usable bytes (excluding the prefix offset region).
定义 bytes.h:868
bool shrink_to(size_t size) noexcept
Reduces the logical size of the buffer without reallocating.
static void bytes_free(uint8_t *ptr, size_t size) noexcept
Frees a buffer previously allocated by bytes_malloc().
std::string to_string() const noexcept
Returns the usable byte region as a std::string.
uint8_t * data() noexcept
Returns a pointer to the start of the user data region (after the prefix offset).
定义 bytes.h:860
static Bytes loan_internal(uint8_t *data, size_t size) noexcept
Creates a loaned (non-owning) alias for an iceoryx zero-copy payload (mutable).
std::string_view to_string_view() const noexcept
Returns a zero-copy std::string_view over the usable byte region.
uint8_t offset() const noexcept
Returns the size of the prefix offset region in bytes.
定义 bytes.h:874
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 constexpr bool is_big_endian() noexcept
Returns true if the platform uses big-endian byte order.
定义 bytes.h:918
static Bytes create(size_t size, uint8_t offset=0) noexcept
Creates an owned Bytes buffer of the given size.
uint8_t * real_begin() noexcept
Iterator begin for the full backing buffer (mutable) – same as real_data().
定义 bytes.h:890
bool resize(size_t size) noexcept
Resizes the logical data region to size bytes.
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.
size_t real_size() const noexcept
Returns the total backing-buffer size including the prefix offset region.
定义 bytes.h:870
static void release_memory_pool() noexcept
Releases the global memory pool and returns its memory to the OS.
void clear() noexcept
Releases the buffer and resets the object to the empty state.
T * to_ptr() const noexcept
Reinterprets the backing buffer as a pointer to T.
定义 bytes.h:901
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT
定义 macros.h:85