1 #ifndef DATA_BUFFER_HPP
2 #define DATA_BUFFER_HPP
39 std::vector<unsigned char> _buffer;
40 mutable size_t _cursor;
46 const std::vector<unsigned char>
data()
const;
54 void append(
const unsigned char*
data,
size_t len);
62 const unsigned char* ptr =
reinterpret_cast<const unsigned char*
>(&value);
63 _buffer.insert(_buffer.end(), ptr, ptr +
sizeof(T));
70 if (
sizeof(T) + _cursor > _buffer.size())
71 throw std::out_of_range(
"Buffer overflow on read");
73 std::memcpy(&value, _buffer.data() + _cursor,
sizeof(T));
A simple LIFO data buffer for serialization and deserialization for simple data types and std::string...
void reset() const
Reset the read/write cursor to the beginning of the buffer.
const DataBuffer & operator>>(T &value) const
void increaseCursor(size_t amount) const
Increase the read/write cursor by a specified amount.
const DataBuffer & operator>>(std::string &value) const
void clear()
Clear the buffer and reset the cursor.
const std::vector< unsigned char > data() const
void decreaseCursor(size_t amount) const
Decrease the read/write cursor by a specified amount.
DataBuffer & operator<<(const T &value)
void append(const unsigned char *data, size_t len)
DataBuffer & operator<<(const std::string &value)