Chi-Tech
chi_data_types::ByteArray Class Reference

#include <byte_array.h>

Public Member Functions

 ByteArray ()=default
 
 ByteArray (const size_t raw_data_size)
 
 ByteArray (std::vector< std::byte > &&raw_data)
 
 ByteArray (const std::vector< std::byte > &raw_data)
 
template<typename T >
void Write (const T &value)
 
template<typename T >
Read ()
 
template<typename T >
Read (const size_t address, size_t *next_address=nullptr) const
 
void Append (const ByteArray &other_raw)
 
void Append (const std::vector< std::byte > &other_raw)
 
void Clear ()
 
void Seek (const size_t address=0)
 
size_t Offset () const
 
bool EndOfBuffer () const
 
size_t Size () const
 
std::vector< std::byte > & Data ()
 
const std::vector< std::byte > & Data () const
 

Protected Attributes

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

Detailed Description

Definition at line 11 of file byte_array.h.

Constructor & Destructor Documentation

◆ ByteArray() [1/4]

chi_data_types::ByteArray::ByteArray ( )
default

◆ ByteArray() [2/4]

chi_data_types::ByteArray::ByteArray ( const size_t  raw_data_size)
inlineexplicit

Definition at line 19 of file byte_array.h.

◆ ByteArray() [3/4]

chi_data_types::ByteArray::ByteArray ( std::vector< std::byte > &&  raw_data)
inlineexplicit

Definition at line 20 of file byte_array.h.

◆ ByteArray() [4/4]

chi_data_types::ByteArray::ByteArray ( const std::vector< std::byte > &  raw_data)
inlineexplicit

Definition at line 24 of file byte_array.h.

Member Function Documentation

◆ Append() [1/2]

void chi_data_types::ByteArray::Append ( const ByteArray other_raw)
inline

Appends a ByteArray to the current internal byte array.

Definition at line 99 of file byte_array.h.

◆ Append() [2/2]

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

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

Definition at line 109 of file byte_array.h.

◆ Clear()

void chi_data_types::ByteArray::Clear ( )
inline

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

Definition at line 118 of file byte_array.h.

◆ Data() [1/2]

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

Returns a reference to the internal byte array.

Definition at line 135 of file byte_array.h.

◆ Data() [2/2]

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

Returns a const reference of the internal byte array.

Definition at line 137 of file byte_array.h.

◆ EndOfBuffer()

bool chi_data_types::ByteArray::EndOfBuffer ( ) const
inline

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

Definition at line 130 of file byte_array.h.

◆ Offset()

size_t chi_data_types::ByteArray::Offset ( ) const
inline

Returns the internal address marker position.

Definition at line 127 of file byte_array.h.

◆ Read() [1/2]

template<typename T >
T chi_data_types::ByteArray::Read ( )
inline

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.

Definition at line 54 of file byte_array.h.

◆ Read() [2/2]

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

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.

Definition at line 82 of file byte_array.h.

◆ Seek()

void chi_data_types::ByteArray::Seek ( const size_t  address = 0)
inline

Moves the address marker to the supplied address.

Definition at line 125 of file byte_array.h.

◆ Size()

size_t chi_data_types::ByteArray::Size ( ) const
inline

Returns the current size of the internal byte array.

Definition at line 132 of file byte_array.h.

◆ Write()

template<typename T >
void chi_data_types::ByteArray::Write ( const T &  value)
inline

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.

Definition at line 34 of file byte_array.h.

Field Documentation

◆ offset_

size_t chi_data_types::ByteArray::offset_ = 0
protected

Definition at line 15 of file byte_array.h.

◆ raw_data_

std::vector<std::byte> chi_data_types::ByteArray::raw_data_
protected

Definition at line 14 of file byte_array.h.


The documentation for this class was generated from the following file: