1#ifndef CHITECH_BYTE_ARRAY_H
2#define CHITECH_BYTE_ARRAY_H
20 explicit ByteArray(std::vector<std::byte>&& raw_data)
24 explicit ByteArray(
const std::vector<std::byte>& raw_data)
36 const size_t num_bytes =
sizeof(T);
37 const std::byte* value_byte_array =
38 reinterpret_cast<const std::byte*
>(&value);
41 raw_data_.end(), value_byte_array, value_byte_array + num_bytes);
56 const size_t num_bytes =
sizeof(T);
58 throw std::out_of_range(
59 std::string(
"ByteArray reading error. ") +
60 " Typename: " + std::string(
typeid(T).name()) +
" m_offset: " +
62 " num_bytes to read: " + std::to_string(num_bytes));
82 T
Read(
const size_t address,
size_t* next_address =
nullptr)
const
84 const size_t num_bytes =
sizeof(T);
85 if ((address + num_bytes - 1) >=
raw_data_.size())
86 throw std::logic_error(
87 std::string(
"ByteArray reading error. ") +
" Typename: " +
88 std::string(
typeid(T).name()) +
" address: " + std::to_string(address) +
89 " size: " + std::to_string(
raw_data_.size()) +
90 " num_bytes to read: " + std::to_string(num_bytes));
92 T value = *
reinterpret_cast<const T*
>(&
raw_data_[address]);
93 if (next_address !=
nullptr) *next_address = address + num_bytes;
103 const auto& slave = other_raw.
Data();
104 master.insert(master.end(), slave.begin(), slave.end());
109 void Append(
const std::vector<std::byte>& other_raw)
113 const auto& slave = other_raw;
114 master.insert(master.end(), slave.begin(), slave.end());
ByteArray(std::vector< std::byte > &&raw_data)
ByteArray(const std::vector< std::byte > &raw_data)
void Seek(const size_t address=0)
std::vector< std::byte > & Data()
void Append(const std::vector< std::byte > &other_raw)
std::vector< std::byte > raw_data_
T Read(const size_t address, size_t *next_address=nullptr) const
const std::vector< std::byte > & Data() const
void Append(const ByteArray &other_raw)
void Write(const T &value)
ByteArray(const size_t raw_data_size)