Utility#

Contents#

Reference#

class binary#

Class of binary data.

Public Functions

inline binary()#

Constructor.

Create empty data.

inline explicit binary(binary_view data)#

Constructor.

Parameters:

data[in] Data.

inline explicit binary(const std::vector<unsigned char> &data)#

Constructor.

Parameters:

data[in] Data.

inline binary(const unsigned char *data, std::size_t size)#

Constructor.

Parameters:
  • data[in] Pointer to the data.

  • size[in] Size of the data.

inline binary(std::initializer_list<unsigned char> data)#

Constructor.

Parameters:

data[in] Data.

inline explicit binary(std::size_t size)#

Constructor.

Create a buffer with uninitialized data.

Parameters:

size[in] Size of the buffer.

inline explicit binary(std::string_view data_string)#

Constructor.

Note

This function accepts hex expression of data written with numeric characters from 0 to 9 and uppercase characters from A to F.

Warning

Current implementation doesn’t accept lowercase characters from a to f.

Parameters:

data_string[in] Hex expression of data.

inline void append(const unsigned char *data, std::size_t size)#

Append another binary data.

Parameters:
  • data[in] Pointer to the appended data.

  • size[in] Size of the appended data.

inline std::size_t capacity() const noexcept#

Get the size of the internal buffer for data.

Returns:

Size of the internal buffer.

inline const unsigned char *data() const noexcept#

Get the pointer to the data.

Returns:

Pointer to the data.

inline unsigned char *data() noexcept#

Get the pointer to the data.

Returns:

Pointer to the data.

inline bool operator!=(const binary &other) const noexcept#

Compare with another instance.

Parameters:

other[in] Another instance.

Return values:
  • true – Two instances are not equal.

  • false – Two instances are equal.

inline binary &operator+=(const binary &other)#

Append another binary data.

Parameters:

other[in] Another binary data to append.

Returns:

This.

inline bool operator==(const binary &other) const noexcept#

Compare with another instance.

Parameters:

other[in] Another instance.

Return values:
  • true – Two instances are equal.

  • false – Two instances are not equal.

inline unsigned char operator[](std::size_t index) const noexcept#

Access to a byte.

Parameters:

index[in] Index of the byte.

Returns:

Value of the byte.

inline unsigned char &operator[](std::size_t index) noexcept#

Access to a byte.

Parameters:

index[in] Index of the byte.

Returns:

Reference to the byte.

inline void reserve(std::size_t size)#

Change the size of the internal buffer.

This function preserves the existing data and its size.

Parameters:

size[in] New size.

inline void resize(std::size_t size)#

Change the size of this data.

This function preserves the existing data. Additional bytes will be left uninitialized.

Parameters:

size[in] New size.

inline std::size_t size() const noexcept#

Get the size of the data.

Returns:

Size of the data.

class binary_view#

Class to refer binary data.

Note

This class doesn’t manage memory of binary data as std::string_view.

Public Functions

inline binary_view() noexcept#

Constructor.

Create empty data.

inline binary_view(const binary &data) noexcept#

Constructor.

Parameters:

data[in] Data.

inline binary_view(const unsigned char *data, std::size_t size) noexcept#

Constructor.

Parameters:
  • data[in] Pointer to the data.

  • size[in] Size of the data.

inline const unsigned char *data() const noexcept#

Get the pointer to the data.

Returns:

Pointer to the data.

inline std::size_t size() const noexcept#

Get the size of the data.

Returns:

Size of the data.