102 #include <string_view>
144 static
void release_memory_pool() noexcept;
153 [[nodiscard]] static uint8_t* bytes_malloc(
size_t size) noexcept;
161 static
void bytes_free(uint8_t* ptr,
size_t size) noexcept;
176 [[nodiscard]] static
Bytes create(
size_t size, uint8_t offset = 0) noexcept;
189 [[nodiscard]] static
Bytes shallow_copy(uint8_t* data,
size_t size) noexcept;
202 [[nodiscard]] static
Bytes shallow_copy(const uint8_t* data,
size_t size) noexcept;
214 [[nodiscard]] static
Bytes shallow_copy_ptr(
void* data) noexcept;
229 [[nodiscard]] static
Bytes deep_copy(uint8_t* data,
size_t size, uint8_t offset = 0) noexcept;
243 [[nodiscard]] static
Bytes deep_copy(const uint8_t* data,
size_t size, uint8_t offset = 0) noexcept;
256 [[nodiscard]] static
Bytes loan_internal(uint8_t* data,
size_t size) noexcept;
265 [[nodiscard]] static
Bytes loan_internal(const uint8_t* data,
size_t size) noexcept;
274 [[nodiscard]] static
Bytes from_string(const std::
string& str, uint8_t offset = 0) noexcept;
288 [[nodiscard]] static
Bytes from_user_input(const std::
string& str,
bool* ok =
nullptr) noexcept;
297 [[nodiscard]] static std::
string convert_to_hex_str(const uint8_t* value,
size_t size) noexcept;
305 [[nodiscard]] static
Bytes reverse_order(const
Bytes& target) noexcept;
313 [[nodiscard]] static std::
string encode_to_base64(const
Bytes& target) noexcept;
321 [[nodiscard]] static
Bytes decode_from_base64(const std::
string& target) noexcept;
329 [[nodiscard]] static uint32_t get_crc_32(const
Bytes& target) noexcept;
337 [[nodiscard]] static uint64_t get_crc_64(const
Bytes& target) noexcept;
375 Bytes(const std::initializer_list<uint8_t>& list) noexcept;
382 explicit
Bytes(const std::vector<uint8_t>& data) noexcept;
415 Bytes& operator=(const std::vector<uint8_t>& data) noexcept;
423 [[nodiscard]]
bool operator==(const
Bytes& target) const noexcept;
431 [[nodiscard]]
bool operator!=(const
Bytes& target) const noexcept;
439 [[nodiscard]]
bool operator==(const std::vector<uint8_t>& data) const noexcept;
447 [[nodiscard]]
bool operator!=(const std::vector<uint8_t>& data) const noexcept;
459 [[nodiscard]] uint8_t& operator[](
size_t index) noexcept;
467 [[nodiscard]] const uint8_t& operator[](
size_t index) const noexcept;
474 [[nodiscard]] uint8_t* data() noexcept;
481 [[nodiscard]] const uint8_t* data() const noexcept;
491 [[nodiscard]] uint8_t* real_data() noexcept;
498 [[nodiscard]] const uint8_t* real_data() const noexcept;
505 [[nodiscard]]
size_t size() const noexcept;
512 [[nodiscard]]
size_t real_size() const noexcept;
522 [[nodiscard]]
size_t capacity() const noexcept;
529 [[nodiscard]] uint8_t offset() const noexcept;
537 [[nodiscard]]
bool is_owner() const noexcept;
544 [[nodiscard]]
bool is_loaned() const noexcept;
551 [[nodiscard]]
bool empty() const noexcept;
558 [[nodiscard]] uint8_t* begin() noexcept;
565 [[nodiscard]] const uint8_t* begin() const noexcept;
572 [[nodiscard]] uint8_t* end() noexcept;
579 [[nodiscard]] const uint8_t* end() const noexcept;
586 [[nodiscard]] uint8_t* real_begin() noexcept;
593 [[nodiscard]] const uint8_t* real_begin() const noexcept;
600 [[nodiscard]] uint8_t* real_end() noexcept;
607 [[nodiscard]] const uint8_t* real_end() const noexcept;
619 [[nodiscard]]
bool is_ptr() const noexcept;
626 [[nodiscard]] std::vector<uint8_t> to_raw_data() const noexcept;
633 [[nodiscard]] std::
string to_string() const noexcept;
643 [[nodiscard]] std::string_view to_string_view() const noexcept;
654 template <typename T =
void>
655 [[nodiscard]] T* to_ptr() const noexcept;
662 [[nodiscard]] static constexpr uint8_t stack_size() noexcept;
669 [[nodiscard]] static constexpr
bool is_little_endian() noexcept;
676 [[nodiscard]] static constexpr
bool is_big_endian() noexcept;
689 [[nodiscard]] static
bool is_compress_data(const uint8_t* data,
size_t size) noexcept;
703 [[nodiscard]] static
Bytes compress_data(const uint8_t* data,
size_t size,
bool high_ratio = false) noexcept;
718 [[nodiscard]] static
Bytes uncompress_data(const uint8_t* data,
size_t size,
bool check_valid = true) noexcept;
727 void clear() noexcept;
739 [[nodiscard]]
bool shrink_to(
size_t size) noexcept;
751 [[nodiscard]]
bool reserve(
size_t new_capacity) noexcept;
764 [[nodiscard]]
bool resize(
size_t size) noexcept;
809 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const
Bytes& target) noexcept;
812 enum Type : uint8_t {
819 Bytes(
Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned) noexcept;
821 void process_type(
Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned,
Bytes* tmp =
nullptr) noexcept;
823 static constexpr uint8_t kStackSize{96};
824 alignas(std::max_align_t) uint8_t stack_data_[kStackSize]{0};
825 bool is_owner_{
false};
826 bool is_loaned_{
false};
828 uint8_t* data_{
nullptr};
839 inline const uint8_t&
Bytes::operator[](
size_t index)
const noexcept {
return data_[offset_ + index]; }
841 inline uint8_t*
Bytes::data() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
843 inline const uint8_t*
Bytes::data() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
861 inline bool Bytes::empty() const noexcept {
return data_ ==
nullptr && size_ == 0; }
863 inline uint8_t*
Bytes::begin() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
865 inline const uint8_t*
Bytes::begin() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
867 inline uint8_t*
Bytes::end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
869 inline const uint8_t*
Bytes::end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
875 inline uint8_t*
Bytes::real_end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
877 inline const uint8_t*
Bytes::real_end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
879 inline bool Bytes::is_ptr() const noexcept {
return data_ !=
nullptr && size_ == 0 && offset_ == 0 && !is_owner_; }
881 template <
typename T>
883 return reinterpret_cast<T*
>(data_);
889 #if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || \
890 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
892 #elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.
Definition: bytes.h:120
bool empty() const noexcept
Reports whether the buffer is logically empty.
Definition: bytes.h:861
bool is_owner() const noexcept
Reports whether this instance owns and will free its storage.
Definition: bytes.h:857
size_t capacity() const noexcept
Returns the allocated capacity of the backing buffer.
Definition: bytes.h:853
static void init_memory_pool() noexcept
Eagerly constructs the process-wide MemoryPool that backs heap allocations.
uint8_t * end() noexcept
Returns a mutable iterator one past the last payload byte.
Definition: bytes.h:867
bool is_loaned() const noexcept
Reports whether the buffer is an iceoryx loan that VLink must not free.
Definition: bytes.h:859
static constexpr bool is_little_endian() noexcept
Returns true at compile time when the platform is little-endian.
Definition: bytes.h:888
uint8_t & operator[](size_t index) noexcept
Mutable indexed access into the payload region.
Definition: bytes.h:837
uint8_t * real_data() noexcept
Returns a mutable pointer to the very beginning of the backing buffer.
Definition: bytes.h:845
bool is_ptr() const noexcept
Reports whether this carrier merely wraps an opaque pointer.
Definition: bytes.h:879
uint8_t * begin() noexcept
Returns a mutable iterator to the first payload byte.
Definition: bytes.h:863
static constexpr uint8_t stack_size() noexcept
Returns the SBO threshold below which payloads stay inline.
Definition: bytes.h:886
uint8_t * real_end() noexcept
Returns a mutable iterator one past the prefix-plus-payload region.
Definition: bytes.h:875
size_t size() const noexcept
Returns the size of the payload region in bytes.
Definition: bytes.h:849
uint8_t * data() noexcept
Returns a mutable pointer to the start of the payload (post-offset).
Definition: bytes.h:841
uint8_t offset() const noexcept
Returns the reserved header offset preceding the payload.
Definition: bytes.h:855
static constexpr bool is_big_endian() noexcept
Returns true at compile time when the platform is big-endian.
Definition: bytes.h:899
uint8_t * real_begin() noexcept
Returns a mutable iterator to the start of the raw backing region.
Definition: bytes.h:871
size_t real_size() const noexcept
Returns the size of the used backing region (payload plus prefix offset).
Definition: bytes.h:851
T * to_ptr() const noexcept
Reinterprets the backing pointer as T*.
Definition: bytes.h:882
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81