Class ByteArray

Class Documentation

class ByteArray

Public Functions

ByteArray() = default
inline explicit ByteArray(const size_t raw_data_size)
inline explicit ByteArray(std::vector<std::byte> &&raw_data)
inline explicit ByteArray(const std::vector<std::byte> &raw_data)
template<typename T>
inline void Write(const T &value)

Uses the template type T to convert an associated value (of type T) to a sub-array of std::bytes and adds it to the internal byte-array.

The template type T must support sizeof.

template<typename T>
inline T Read()

Uses the template type T to convert sizeof(T) number of bytes to a value of type T. The bytes are pulled from the internal byte-array starting at the internal address m_offset which can be viewed with a call to Offset(). This offset is incremented by the amount of bytes used and can be reset with a call to Seek(0).

Bounds-checking is performed by checking if the internal byte array has the required number of bytes available. If this check fails then this call will return an out_of_range exception.

template<typename T>
inline T Read(const size_t address, size_t *next_address = nullptr) const

Uses the template type T to convert sizeof(T) number of bytes to a value of type T. The bytes are pulled from the internal byte-array starting at the internal address specified by the argument “address”. An optional argument next_address can be used to return the location of the value after the value read. This offset is the given “address” argument incremented by the amount of bytes used.

Bounds-checking is performed by checking if the internal byte array has the required number of bytes available. If this check fails then this call will return an out_of_range exception.

inline void Append(const ByteArray &other_raw)

Appends a ByteArray to the current internal byte array.

inline void Append(const std::vector<std::byte> &other_raw)

Appends bytes from a std::vector<std::byte> to the internal byte array.

inline void Clear()

Clears the internal byte array and resets the address offset to zero.

inline void Seek(const size_t address = 0)

Moves the address marker to the supplied address.

inline size_t Offset() const

Returns the internal address marker position.

inline bool EndOfBuffer() const

Determines if the internal address marker is beyond the internal byte array.

inline size_t Size() const

Returns the current size of the internal byte array.

inline std::vector<std::byte> &Data()

Returns a reference to the internal byte array.

inline const std::vector<std::byte> &Data() const

Returns a const reference of the internal byte array.

Protected Attributes

std::vector<std::byte> raw_data_
size_t offset_ = 0