102 #include <string_view>
145 static
void release_memory_pool() noexcept;
154 [[nodiscard]] static uint8_t* bytes_malloc(
size_t size) noexcept;
162 static
void bytes_free(uint8_t* ptr,
size_t size) noexcept;
177 [[nodiscard]] static
Bytes create(
size_t size, uint8_t offset = 0) noexcept;
191 [[nodiscard]] static
Bytes shallow_copy(uint8_t* data,
size_t size) noexcept;
205 [[nodiscard]] static
Bytes shallow_copy(const uint8_t* data,
size_t size) noexcept;
217 [[nodiscard]] static
Bytes shallow_copy_ptr(
void* data) noexcept;
233 [[nodiscard]] static
Bytes deep_copy(uint8_t* data,
size_t size, uint8_t offset = 0) noexcept;
247 [[nodiscard]] static
Bytes deep_copy(const uint8_t* data,
size_t size, uint8_t offset = 0) noexcept;
261 [[nodiscard]] static
Bytes loan_internal(uint8_t* data,
size_t size) noexcept;
272 [[nodiscard]] static
Bytes loan_internal(const uint8_t* data,
size_t size) noexcept;
281 [[nodiscard]] static
Bytes from_string(const std::
string& str, uint8_t offset = 0) noexcept;
295 [[nodiscard]] static
Bytes from_user_input(const std::
string& str,
bool* ok =
nullptr) noexcept;
304 [[nodiscard]] static std::
string convert_to_hex_str(const uint8_t* value,
size_t size) noexcept;
312 [[nodiscard]] static
Bytes reverse_order(const
Bytes& target) noexcept;
320 [[nodiscard]] static std::
string encode_to_base64(const
Bytes& target) noexcept;
328 [[nodiscard]] static
Bytes decode_from_base64(const std::
string& target) noexcept;
336 [[nodiscard]] static uint32_t get_crc_32(const
Bytes& target) noexcept;
344 [[nodiscard]] static uint64_t get_crc_64(const
Bytes& target) noexcept;
382 Bytes(const std::initializer_list<uint8_t>& list) noexcept;
389 explicit
Bytes(const std::vector<uint8_t>& data) noexcept;
422 Bytes& operator=(const std::vector<uint8_t>& data) noexcept;
430 [[nodiscard]]
bool operator==(const
Bytes& target) const noexcept;
438 [[nodiscard]]
bool operator!=(const
Bytes& target) const noexcept;
446 [[nodiscard]]
bool operator==(const std::vector<uint8_t>& data) const noexcept;
454 [[nodiscard]]
bool operator!=(const std::vector<uint8_t>& data) const noexcept;
466 [[nodiscard]] uint8_t& operator[](
size_t index) noexcept;
474 [[nodiscard]] const uint8_t& operator[](
size_t index) const noexcept;
481 [[nodiscard]] uint8_t* data() noexcept;
488 [[nodiscard]] const uint8_t* data() const noexcept;
498 [[nodiscard]] uint8_t* real_data() noexcept;
505 [[nodiscard]] const uint8_t* real_data() const noexcept;
512 [[nodiscard]]
size_t size() const noexcept;
519 [[nodiscard]]
size_t real_size() const noexcept;
529 [[nodiscard]]
size_t capacity() const noexcept;
536 [[nodiscard]] uint8_t offset() const noexcept;
544 [[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;
593 [[nodiscard]] uint8_t* real_begin() 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;
626 [[nodiscard]]
bool is_ptr() const noexcept;
633 [[nodiscard]] std::vector<uint8_t> to_raw_data() const noexcept;
640 [[nodiscard]] std::
string to_string() const noexcept;
650 [[nodiscard]] std::string_view to_string_view() const noexcept;
661 template <typename T =
void>
662 [[nodiscard]] T* to_ptr() const noexcept;
669 [[nodiscard]] static constexpr uint8_t stack_size() noexcept;
676 [[nodiscard]] static constexpr
bool is_little_endian() noexcept;
683 [[nodiscard]] static constexpr
bool is_big_endian() noexcept;
696 [[nodiscard]] static
bool is_compress_data(const uint8_t* data,
size_t size) noexcept;
710 [[nodiscard]] static
Bytes compress_data(const uint8_t* data,
size_t size,
bool high_ratio = false) noexcept;
725 [[nodiscard]] static
Bytes uncompress_data(const uint8_t* data,
size_t size,
bool check_valid = true) noexcept;
734 void clear() noexcept;
746 [[nodiscard]]
bool shrink_to(
size_t size) noexcept;
758 [[nodiscard]]
bool reserve(
size_t new_capacity) noexcept;
771 [[nodiscard]]
bool resize(
size_t size) noexcept;
816 VLINK_EXPORT friend std::ostream& operator<<(std::ostream& ostream, const
Bytes& target) noexcept;
819 enum Type : uint8_t {
826 Bytes(
Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned) noexcept;
828 void process_type(
Type type, uint8_t* data,
size_t size, uint8_t offset,
bool loaned,
Bytes* tmp =
nullptr) noexcept;
830 static constexpr uint8_t kStackSize{96};
831 alignas(std::max_align_t) uint8_t stack_data_[kStackSize]{0};
832 bool is_owner_{
false};
833 bool is_loaned_{
false};
835 uint8_t* data_{
nullptr};
846 inline const uint8_t&
Bytes::operator[](
size_t index)
const noexcept {
return data_[offset_ + index]; }
848 inline uint8_t*
Bytes::data() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
850 inline const uint8_t*
Bytes::data() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
868 inline bool Bytes::empty() const noexcept {
return data_ ==
nullptr && size_ == 0; }
870 inline uint8_t*
Bytes::begin() noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
872 inline const uint8_t*
Bytes::begin() const noexcept {
return data_ ? (data_ + offset_) :
nullptr; }
874 inline uint8_t*
Bytes::end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
876 inline const uint8_t*
Bytes::end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
882 inline uint8_t*
Bytes::real_end() noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
884 inline const uint8_t*
Bytes::real_end() const noexcept {
return data_ ? (data_ + offset_ + size_) :
nullptr; }
886 inline bool Bytes::is_ptr() const noexcept {
return data_ !=
nullptr && size_ == 0 && offset_ == 0 && !is_owner_; }
888 template <
typename T>
890 return reinterpret_cast<T*
>(data_);
896 #if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || \
897 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
899 #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:868
bool is_owner() const noexcept
Reports whether this instance owns and will free its storage.
Definition: bytes.h:864
size_t capacity() const noexcept
Returns the allocated capacity of the backing buffer.
Definition: bytes.h:860
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:874
bool is_loaned() const noexcept
Reports whether the buffer is an iceoryx loan that VLink must not free.
Definition: bytes.h:866
static constexpr bool is_little_endian() noexcept
Returns true at compile time when the platform is little-endian.
Definition: bytes.h:895
uint8_t & operator[](size_t index) noexcept
Mutable indexed access into the payload region.
Definition: bytes.h:844
uint8_t * real_data() noexcept
Returns a mutable pointer to the very beginning of the backing buffer.
Definition: bytes.h:852
bool is_ptr() const noexcept
Reports whether this carrier merely wraps an opaque pointer.
Definition: bytes.h:886
uint8_t * begin() noexcept
Returns a mutable iterator to the first payload byte.
Definition: bytes.h:870
static constexpr uint8_t stack_size() noexcept
Returns the SBO threshold below which payloads stay inline.
Definition: bytes.h:893
uint8_t * real_end() noexcept
Returns a mutable iterator one past the prefix-plus-payload region.
Definition: bytes.h:882
size_t size() const noexcept
Returns the size of the payload region in bytes.
Definition: bytes.h:856
uint8_t * data() noexcept
Returns a mutable pointer to the start of the payload (post-offset).
Definition: bytes.h:848
uint8_t offset() const noexcept
Returns the reserved header offset preceding the payload.
Definition: bytes.h:862
static constexpr bool is_big_endian() noexcept
Returns true at compile time when the platform is big-endian.
Definition: bytes.h:906
uint8_t * real_begin() noexcept
Returns a mutable iterator to the start of the raw backing region.
Definition: bytes.h:878
size_t real_size() const noexcept
Returns the size of the used backing region (payload plus prefix offset).
Definition: bytes.h:858
T * to_ptr() const noexcept
Reinterprets the backing pointer as T*.
Definition: bytes.h:889
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81