2 #include <samchon/API.hpp> 31 :
public std::vector<unsigned char>
34 typedef std::vector<unsigned char> super;
78 auto getPosition() const ->
size_t;
85 void setPosition(
size_t);
87 auto leftSize() const ->
size_t;
96 template <typename T> static auto reverse(const T &val) -> T
101 unsigned char *originalBytes = (
unsigned char*)&val;
102 unsigned char *reversedBytes = (
unsigned char*)&res;
104 for (
int i = 0; i < size; i++)
105 reversedBytes[i] = originalBytes[size - i - 1];
121 template <
typename T>
auto read() const -> T
123 T *ptr = (T*)(data() + position);
124 ((
ByteArray*)
this)->position +=
sizeof(T);
128 template<>
auto read()
const -> std::string
130 if (position >= size())
133 std::string str = (
char*)(data() + position);
134 ((
ByteArray*)
this)->position = str.size();
168 template <
typename T>
void write(
const T &val)
170 unsigned char *ptr = (
unsigned char*)&val;
171 insert(end(), ptr, ptr +
sizeof(T));
173 template<>
void write(
const std::string &str)
175 unsigned char *begin = (
unsigned char*)str.data();
176 insert(end(), begin, begin + str.size());
178 template<>
void write(
const ByteArray &byteArray)
180 insert(end(), byteArray.begin(), byteArray.end());
size_t position
Current position of the ByteArray. .
auto read() const -> T
Read data.
void writeReversely(const T &val)
Write a data.
auto readReversely() const -> T
Read a reversed data.
Top level namespace of products built from samchon.
void write(const T &val)
Write a data.