52#include <initializer_list>
155 bytes.shrink_to_fit();
163 template<Type::ByteInputRange R>
164 explicit Binary(
const R& range);
171 template<Type::ByteInputRange R>
172 explicit Binary(R&& range);
222 bool operator==(const
Binary& other) const noexcept;
229 bool operator!=(const
Binary& other) const noexcept;
237 return m_bytes <=> other.m_bytes;
245 bool operator==(std::span<const std::byte> bytes)
const noexcept;
252 bool operator!=(std::span<const std::byte> bytes)
const noexcept;
260 return std::lexicographical_compare_three_way(
span().
begin(),
span().
end(), bytes.begin(), bytes.end());
400 const
std::
byte& operator[](const
ByteSize& index) const noexcept;
459 return std::span<std::byte>(
data(),
static_cast<std::size_t
>(
size()));
467 return std::span<const std::byte>(
data(),
static_cast<std::size_t
>(
size()));
491 const std::span<const std::byte> bytes =
span();
492 return std::vector<std::byte>(bytes.begin(), bytes.end());
500 const std::span<const std::byte> bytes =
span();
501 std::vector<std::byte> out(bytes.begin(), bytes.end());
518 void assign(std::span<const std::byte> bytes);
524 void assign(std::initializer_list<std::byte> list);
532 template<
typename InputIt>
533 void assign(InputIt first, InputIt last);
539 void append(std::span<const std::byte> bytes);
643 template<
typename InputIt>
689 virtual void Discard(std::span<std::byte> bytes)
noexcept;
732 void Reallocate(
std::
size_t new_cap);
738 void Grow(
std::
size_t required);
744 void SetSize(
std::
size_t new_size);
752 std::
byte* OpenGap(
std::
size_t offset,
std::
size_t count);
771 return data == bytes;
781 return data != bytes;
791 return 0 <=> (data <=> bytes);
794 template<Type::ByteInputRange R>
796 if constexpr (
requires { std::size(range); })
798 for (
auto&&
byte : range)
802 template<Type::ByteInputRange R>
804 using U = std::remove_cvref_t<R>;
806 *
this = std::move(
static_cast<Binary&
>(range));
808 if constexpr (
requires { std::size(range); })
810 for (
auto&&
byte : range)
815 template<
typename InputIt>
818 for (; first != last; ++first)
819 push_back(
static_cast<std::byte
>(*first));
824 push_back(
static_cast<std::byte
>(std::forward<T>(value)));
828 template<
typename InputIt>
830 auto offset =
static_cast<std::size_t
>(pos -
cbegin());
831 if constexpr (std::forward_iterator<InputIt>) {
832 const auto count =
static_cast<std::size_t
>(std::distance(first, last));
834 return begin() + offset;
835 std::byte* gap = OpenGap(offset, count);
836 for (std::size_t index = 0; first != last; ++first, ++index)
837 gap[index] =
static_cast<std::byte
>(*first);
841 const std::size_t start = offset;
842 for (; first != last; ++first, ++offset)
843 insert(
cbegin() + offset,
static_cast<std::byte
>(*first));
844 return begin() + start;
IEC octet length (uint64_t), implicit only to std::size_t.
Count of octets (uint64_t storage).
Definition byte_size.hxx:105
Owned contiguous sequence of std::byte, stored in a Vector.
Definition binary.hxx:79
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator.
Definition binary.hxx:90
const std::byte * const_iterator
Contiguous read-only iterator.
Definition binary.hxx:89
iterator begin() noexcept
Mutable iterator to the first byte.
reverse_iterator rbegin() noexcept
Mutable reverse iterator to the last byte.
const_reverse_iterator crend() const noexcept
Read-only reverse iterator before the first byte.
void resize(const ByteSize &new_size)
Resize to new_size bytes.
Binary & operator+=(std::span< const std::byte > bytes)
Append a copy of bytes.
Binary & operator+=(const Binary &other)
Append a copy of other.
std::byte & reference
Mutable element reference.
Definition binary.hxx:84
STORMBYTE_FORCE_INLINE Binary(std::vector< std::byte > &&bytes)
Copy bytes from a caller-owned vector, then empty it.
Definition binary.hxx:153
virtual ~Binary() noexcept
Destroy the sequence on Base's heap.
bool operator!=(std::span< const std::byte > bytes) const noexcept
Inequality with a byte span.
std::span< std::byte > Storage() noexcept
The whole allocated block, including unused capacity.
void append(Binary &&other)
Append other, then empty it.
Size size_type
Count typedef. size() returns ByteSize.
Definition binary.hxx:82
virtual bool ConstantTimeCompare() const noexcept
Whether equality must not depend on where the bytes differ.
std::byte * data() noexcept
Mutable pointer to the first byte, or null when empty.
static void Wipe(std::span< std::byte > bytes) noexcept
Zero bytes.
Binary(const Binary &other)
Copy construct.
reference emplace_back(T &&value)
Append a byte constructed in place.
Definition binary.hxx:823
void swap(Binary &other) noexcept
Exchange storage with other.
ByteSize capacity() const noexcept
Allocated capacity in bytes.
iterator insert(const_iterator pos, std::byte value)
Insert one byte before pos.
reverse_iterator rend() noexcept
Mutable reverse iterator before the first byte.
void assign(std::initializer_list< std::byte > list)
Replace contents with an initializer list.
String HexDump() const
Hexadecimal dump, sixteen bytes per row.
void reserve(const ByteSize &new_cap)
Request capacity of at least new_cap bytes.
iterator erase(const_iterator first, const_iterator last)
Erase [first, last).
const_iterator cbegin() const noexcept
Read-only iterator to the first byte.
void shrink_to_fit()
Release unused capacity when the implementation allows it.
std::byte value_type
Element type.
Definition binary.hxx:81
bool empty() const noexcept
Whether the sequence holds no bytes.
const std::byte * const_pointer
Read-only pointer.
Definition binary.hxx:87
void append(const std::byte *bytes, const ByteSize &count)
Append count bytes starting at bytes.
STORMBYTE_FORCE_INLINE std::span< std::byte > span() noexcept
Mutable view of the occupied bytes.
Definition binary.hxx:458
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(std::span< const std::byte > bytes) const noexcept
Three-way comparison with a byte span.
Definition binary.hxx:259
iterator insert(const_iterator pos, const ByteSize &count, std::byte value)
Insert count copies of value before pos.
std::byte * pointer
Mutable pointer.
Definition binary.hxx:86
void push_back(std::byte value)
Append one byte.
Binary(Binary &&other) noexcept
Move construct.
std::reverse_iterator< const_iterator > const_reverse_iterator
Read-only reverse iterator.
Definition binary.hxx:91
iterator insert(const_iterator pos, std::span< const std::byte > bytes)
Insert a span before pos.
void clear() noexcept
Drop every byte.
String HexDump(Size columns) const
Hexadecimal dump of the occupied bytes.
void append(std::span< const std::byte > bytes)
Append a copy of bytes.
void append(const Binary &other)
Append a copy of other.
ByteSize size() const noexcept
Occupied length in bytes.
bool operator==(std::span< const std::byte > bytes) const noexcept
Equality with a byte span.
std::ptrdiff_t difference_type
Iterator difference.
Definition binary.hxx:83
const std::byte & const_reference
Read-only element reference.
Definition binary.hxx:85
void assign(const ByteSize &count, std::byte value)
Replace contents with count copies of value.
Binary & operator+=(Binary &&other)
Append other, then empty it.
iterator insert(const_iterator pos, std::initializer_list< std::byte > list)
Insert an initializer list before pos.
STORMBYTE_FORCE_INLINE std::span< const std::byte > span() const noexcept
Read-only view of the occupied bytes.
Definition binary.hxx:466
void pop_back()
Remove the last byte.
virtual void Release(std::span< std::byte > block) noexcept
Called when a block stops being owned by this object: the old block after a reallocation,...
virtual void Discard(std::span< std::byte > bytes) noexcept
Called with every byte range this sequence is about to drop or release.
std::byte & back()
Last byte.
Binary() noexcept
Construct an empty sequence.
const_reverse_iterator crbegin() const noexcept
Read-only reverse iterator to the last byte.
ByteSize max_size() const noexcept
Implementation maximum size in bytes.
iterator erase(const_iterator pos)
Erase the byte at pos.
std::byte * iterator
Contiguous mutable iterator.
Definition binary.hxx:88
std::byte & at(const ByteSize &index)
Checked mutable subscript.
iterator end() noexcept
Mutable iterator one past the last byte.
const_iterator cend() const noexcept
Read-only iterator one past the last byte.
void assign(std::span< const std::byte > bytes)
Replace contents with a copy of bytes.
virtual void Acquire(std::span< std::byte > block) noexcept
Called when an allocated block becomes owned by this object: a new block on growth or shrinking,...
std::byte & front()
First byte.
Owned UTF-8 text.
Definition string.hxx:113
Contiguous sequence stored on Base's heap.
Definition vector.hxx:81
Count of abstract units (uint64_t storage).
Definition size.hxx:107
Derived derives from Base (std::is_base_of).
Definition relations.hxx:156
Lvalue reference type (std::is_lvalue_reference).
Definition categories.hxx:97
Owned values that cross a DLL without the caller's CRT.
bool operator==(std::span< const std::byte > bytes, const Binary &data) noexcept
Equality of a span against a sequence.
Definition binary.hxx:770
bool operator!=(std::span< const std::byte > bytes, const Binary &data) noexcept
Inequality of a span against a sequence.
Definition binary.hxx:780
void swap(Binary &left, Binary &right) noexcept
Exchange two sequences.
Definition binary.hxx:760
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(std::span< const std::byte > bytes, const Binary &data) noexcept
Three-way comparison of a span against a sequence.
Definition binary.hxx:790
STORMBYTE_FORCE_INLINE std::size_t HashBytes(std::span< const std::byte > bytes) noexcept
Mix a byte range with FNV-1a.
Definition hash.hxx:66
Root namespace of the StormByte suite.
Host-width-stable count (uint64_t), implicit only to std::size_t.
STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::Binary &value) const noexcept
Hashes value.
Definition binary.hxx:860
Cross-module hash.
Definition hash.hxx:95
std::size_t operator()(const StormByte::Safe::Binary &value) const noexcept
Hashes value.
Definition binary.hxx:875
#define STORMBYTE_PUBLIC
Definition visibility.h:52