![]() |
Divide Framework 0.1
A free and open-source 3D Framework under heavy development
|
#include <ByteBuffer.h>
Public Member Functions | |
ByteBuffer () noexcept=default | |
void | clear () noexcept |
Resets the entire storage and the read and write positions. | |
template<class T , size_t N> | |
void | addMarker (const T(&pattern)[N]) |
Add a specific list of items in order to mark a special point in the buffer. Can be used for skipping entire blocks later. | |
template<class T , size_t N> | |
void | readSkipToMarker (const T(&pattern)[N]) |
Skip (consume) everything in the buffer until we find the specified list of items. If the markers aren't found, the buffer will skip to the end! | |
template<typename T > | |
void | put (size_t pos, const T &value) |
Inserts 'value' at the specified position overriding any existing data at that location. Does not allocate storage! | |
template<typename T > | |
ByteBuffer & | operator<< (const T &value) |
Appends 'value' to the buffer. | |
template<typename T > | |
ByteBuffer & | operator>> (T &value) |
Reads sizeof(T) data from the buffer and saves its contents into 'value'. Reading moves the read head forward! | |
template<typename U > | |
ByteBuffer & | operator>> (Unused< U > &value) |
Can be used as an alternative for readSkip<U>() to preserve local coding conventions. | |
template<typename T > | |
void | readSkip () |
Moves the read head sizeof(T) units forward. | |
void | readSkip (size_t skip) noexcept |
Moves the read head 'skip' units forward. | |
template<typename T > | |
void | readNoSkip (T &value) |
Reads sizeof(T) data from the buffer and saves it into 'value' but does NOT move the read head forward! | |
template<typename T > | |
void | read (T &out) |
Reads sizeof(T) data from the buffer and returns it. Reading moves the read head forward! | |
template<typename T > | |
void | readNoSkipFrom (size_t pos, T &out) const |
Reads sizeof(T) data from the buffer and returns it but does NOT move the read head forward! | |
void | read (Byte *dest, size_t len) |
Reads 'len' bytes of data from the buffer and memcpy's it into dest. Reading moves the read head forward! | |
void | readPackXYZ (F32 &x, F32 &y, F32 &z) |
Reads a packed U32 from the buffer and unpackes it into x,y,z. Reading moves the read head forward! | |
void | appendPackXYZ (F32 x, F32 y, F32 z) |
Packes x,y and z into a single U32 and appends it to the buffer. | |
U64 | readPackGUID () |
Reads a packed U64 from the buffer and returns it. Reading moves the read head forward! | |
void | appendPackGUID (U64 guid) |
Packes guid into a multiple I32s and appends them to the buffer. | |
void | append (const Byte *src, size_t cnt) |
Appends 'cnt' bytes from 'src' to the buffer. | |
template<typename T > | |
void | append (const T *src, const size_t cnt) |
Appends (sizeof(T) * 'cnt') bytes from 'src' to the buffer. | |
Byte | operator[] (size_t pos) const |
Read the byte at position 'pos' from the buffer without moving the read head. | |
size_t | rpos () const noexcept |
Returns the current read head position. | |
size_t | rpos (size_t rpos_) noexcept |
size_t | wpos () const noexcept |
Returns the current write head position. | |
size_t | wpos (size_t wpos_) noexcept |
Returns the current write head position. | |
size_t | bufferSize () const noexcept |
Returns the size (in bytes) of the data inside of the buffer (wpos - rpos) | |
bool | bufferEmpty () const noexcept |
Returns true if the read position and the write position are identical. | |
size_t | storageSize () const noexcept |
Returns the total size (in bytes) of the underlying storage, regardles of wpos and rpos. | |
bool | storageEmpty () const noexcept |
Returns true if the underlying storage is empty, regardless of wpos and rpos. | |
void | resize (size_t newsize) |
Resizes the underlying storage to 'newsize' bytes and resets the read and write head positions. | |
void | reserve (size_t resize) |
Reserves 'resize' bytes of additional storage in the underlying storage structure without changing the read and write head positions. | |
const Byte * | contents () const noexcept |
Returns a raw pointer to the underlying storage data. Does NOT depend on the read head position! (use contents() + rpos() for that) | |
void | put (size_t pos, const Byte *src, size_t cnt) |
Overrides existing data in the buffer starting ad position 'pos' by memcpy-ing 'cnt' bytes from 'src'. | |
bool | dumpToFile (const ResourcePath &path, std::string_view fileName, const U8 version=BUFFER_FORMAT_VERSION) |
Saves the entire buffer contents to file. Always appends the version at the end of the file. | |
bool | loadFromFile (const ResourcePath &path, std::string_view fileName, const U8 version=BUFFER_FORMAT_VERSION) |
template<> | |
ByteBuffer & | operator>> (bool &value) |
template<> | |
ByteBuffer & | operator>> (string &value) |
template<> | |
void | readNoSkip (bool &value) |
template<> | |
void | readNoSkip (string &value) |
template<> | |
void | readNoSkip (ResourcePath &value) |
template<> | |
void | readSkip () |
template<> | |
void | readSkip () |
template<> | |
void | readSkip () |
template<> | |
void | append (const string &str) |
template<> | |
void | append (const ResourcePath &str) |
template<> | |
void | append (const bool &value) |
template<> | |
void | append (const ByteBuffer &buffer) |
Static Public Attributes | |
static const U8 | BUFFER_FORMAT_VERSION { 10u } |
static const size_t | DEFAULT_SIZE { 0x1000 } |
Protected Attributes | |
size_t | _rpos = 0u |
size_t | _wpos = 0u |
vector< Byte > | _storage |
Private Member Functions | |
template<typename T > | |
void | append (const T &value) |
Limited for internal use because can "append" any unexpected type (e.g. a pointer) with hard detection problem. | |
Definition at line 74 of file ByteBuffer.h.
|
defaultnoexcept |
void Divide::ByteBuffer::addMarker | ( | const T(&) | pattern[N] | ) |
Add a specific list of items in order to mark a special point in the buffer. Can be used for skipping entire blocks later.
Definition at line 56 of file ByteBuffer.inl.
|
inline |
Definition at line 411 of file ByteBuffer.inl.
void Divide::ByteBuffer::append | ( | const Byte * | src, |
size_t | cnt | ||
) |
Appends 'cnt' bytes from 'src' to the buffer.
Definition at line 33 of file ByteBuffer.cpp.
|
inline |
Definition at line 416 of file ByteBuffer.inl.
|
inline |
Definition at line 406 of file ByteBuffer.inl.
|
inline |
Definition at line 400 of file ByteBuffer.inl.
|
private |
Limited for internal use because can "append" any unexpected type (e.g. a pointer) with hard detection problem.
Definition at line 389 of file ByteBuffer.inl.
void Divide::ByteBuffer::append | ( | const T * | src, |
const size_t | cnt | ||
) |
Appends (sizeof(T) * 'cnt') bytes from 'src' to the buffer.
Definition at line 394 of file ByteBuffer.inl.
|
inline |
Packes guid into a multiple I32s and appends them to the buffer.
Definition at line 305 of file ByteBuffer.inl.
Packes x,y and z into a single U32 and appends it to the buffer.
Definition at line 296 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns true if the read position and the write position are identical.
Definition at line 353 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the size (in bytes) of the data inside of the buffer (wpos - rpos)
Definition at line 349 of file ByteBuffer.inl.
|
noexcept |
Resets the entire storage and the read and write positions.
Definition at line 28 of file ByteBuffer.cpp.
|
inlinenoexcept |
Returns a raw pointer to the underlying storage data. Does NOT depend on the read head position! (use contents() + rpos() for that)
Definition at line 377 of file ByteBuffer.inl.
bool Divide::ByteBuffer::dumpToFile | ( | const ResourcePath & | path, |
std::string_view | fileName, | ||
const U8 | version = BUFFER_FORMAT_VERSION |
||
) |
Saves the entire buffer contents to file. Always appends the version at the end of the file.
Definition at line 47 of file ByteBuffer.cpp.
bool Divide::ByteBuffer::loadFromFile | ( | const ResourcePath & | path, |
std::string_view | fileName, | ||
const U8 | version = BUFFER_FORMAT_VERSION |
||
) |
Reads the specified file and loads its contents as raw data into the buffer. Returns FALSE if reading of the file failed OR if the version doesn't match To skip version checking, pass 0u as the version! This will erase any existing data inside of the buffer
Definition at line 57 of file ByteBuffer.cpp.
ByteBuffer & Divide::ByteBuffer::operator<< | ( | const T & | value | ) |
Appends 'value' to the buffer.
Definition at line 112 of file ByteBuffer.inl.
|
inline |
Definition at line 126 of file ByteBuffer.inl.
|
inline |
Definition at line 135 of file ByteBuffer.inl.
ByteBuffer & Divide::ByteBuffer::operator>> | ( | T & | value | ) |
Reads sizeof(T) data from the buffer and saves its contents into 'value'. Reading moves the read head forward!
Definition at line 119 of file ByteBuffer.inl.
ByteBuffer & Divide::ByteBuffer::operator>> | ( | Unused< U > & | value | ) |
Can be used as an alternative for readSkip<U>() to preserve local coding conventions.
Definition at line 197 of file ByteBuffer.inl.
|
inline |
Read the byte at position 'pos' from the buffer without moving the read head.
Definition at line 325 of file ByteBuffer.inl.
|
inline |
Overrides existing data in the buffer starting ad position 'pos' by memcpy-ing 'cnt' bytes from 'src'.
Definition at line 381 of file ByteBuffer.inl.
void Divide::ByteBuffer::put | ( | size_t | pos, |
const T & | value | ||
) |
Inserts 'value' at the specified position overriding any existing data at that location. Does not allocate storage!
Definition at line 105 of file ByteBuffer.inl.
|
inline |
Reads 'len' bytes of data from the buffer and memcpy's it into dest. Reading moves the read head forward!
Definition at line 256 of file ByteBuffer.inl.
void Divide::ByteBuffer::read | ( | T & | out | ) |
Reads sizeof(T) data from the buffer and returns it. Reading moves the read head forward!
Definition at line 239 of file ByteBuffer.inl.
|
inline |
Definition at line 160 of file ByteBuffer.inl.
|
inline |
Definition at line 189 of file ByteBuffer.inl.
|
inline |
Definition at line 167 of file ByteBuffer.inl.
void Divide::ByteBuffer::readNoSkip | ( | T & | value | ) |
Reads sizeof(T) data from the buffer and saves it into 'value' but does NOT move the read head forward!
Definition at line 154 of file ByteBuffer.inl.
void Divide::ByteBuffer::readNoSkipFrom | ( | size_t | pos, |
T & | out | ||
) | const |
Reads sizeof(T) data from the buffer and returns it but does NOT move the read head forward!
Definition at line 246 of file ByteBuffer.inl.
|
inline |
Reads a packed U64 from the buffer and returns it. Reading moves the read head forward!
Definition at line 276 of file ByteBuffer.inl.
Reads a packed U32 from the buffer and unpackes it into x,y,z. Reading moves the read head forward!
Definition at line 267 of file ByteBuffer.inl.
void Divide::ByteBuffer::readSkip |
Moves the read head sizeof(T) units forward.
Definition at line 204 of file ByteBuffer.inl.
|
inline |
Definition at line 210 of file ByteBuffer.inl.
|
inline |
Definition at line 217 of file ByteBuffer.inl.
|
inline |
Definition at line 223 of file ByteBuffer.inl.
|
inlinenoexcept |
Moves the read head 'skip' units forward.
Definition at line 228 of file ByteBuffer.inl.
void Divide::ByteBuffer::readSkipToMarker | ( | const T(&) | pattern[N] | ) |
Skip (consume) everything in the buffer until we find the specified list of items. If the markers aren't found, the buffer will skip to the end!
Definition at line 65 of file ByteBuffer.inl.
|
inline |
Reserves 'resize' bytes of additional storage in the underlying storage structure without changing the read and write head positions.
Definition at line 371 of file ByteBuffer.inl.
|
inline |
Resizes the underlying storage to 'newsize' bytes and resets the read and write head positions.
Definition at line 365 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the current read head position.
Definition at line 331 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the current read head position Returns the current read head position
Definition at line 335 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns true if the underlying storage is empty, regardless of wpos and rpos.
Definition at line 361 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the total size (in bytes) of the underlying storage, regardles of wpos and rpos.
Definition at line 357 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the current write head position.
Definition at line 340 of file ByteBuffer.inl.
|
inlinenoexcept |
Returns the current write head position.
Definition at line 344 of file ByteBuffer.inl.
|
protected |
Definition at line 192 of file ByteBuffer.h.
Definition at line 193 of file ByteBuffer.h.
|
protected |
Definition at line 192 of file ByteBuffer.h.
|
static |
Definition at line 76 of file ByteBuffer.h.
|
static |
Definition at line 77 of file ByteBuffer.h.