30 :
public std::vector<unsigned char>
33 typedef std::vector<unsigned char> super;
76 assign(obj.begin(), obj.end());
84 super::operator=(move(obj));
113 auto left_size()
const ->
size_t 125 template <
typename T>
static auto reverse(
const T &val) -> T
128 int size =
sizeof(T);
130 unsigned char *originalBytes = (
unsigned char*)&val;
131 unsigned char *reversedBytes = (
unsigned char*)&res;
133 for (
int i = 0; i < size; i++)
134 reversedBytes[i] = originalBytes[size - i - 1];
150 template <
typename T>
auto read() const -> T
153 ((
ByteArray*)
this)->position +=
sizeof(T);
157 template<>
auto read()
const -> std::string
159 if (position >= size())
162 std::string str = (
char*)(data() +
position);
163 ((
ByteArray*)
this)->position = str.size();
197 template <
typename T>
void write(
const T &val)
199 unsigned char *ptr = (
unsigned char*)&val;
200 insert(end(), ptr, ptr +
sizeof(T));
202 template<>
void write(
const std::string &str)
204 unsigned char *begin = (
unsigned char*)str.data();
205 insert(end(), begin, begin + str.size());
209 insert(end(), byte_array.begin(), byte_array.end());
size_t position
Current position of the ByteArray. .
ByteArray()
Default Constructor.
void set_position(size_t val)
Set poisition.
ByteArray(const ByteArray &obj)
Copy Constructor.
static auto reverse(const T &val) -> T
Reverse byte ordering.
auto read() const -> T
Read data.
void writeReversely(const T &val)
Write a data.
ByteArray(ByteArray &&obj)
Move Constructor.
auto decompress() const -> ByteArray
Decompress the binary data.
auto compress() const -> ByteArray
Compress the binary data .
auto get_position() const -> size_t
Get position.
auto readReversely() const -> T
Read a reversed data.
void write(const T &val)
Write a data.