syncsys
|
helpclass for data-(de)-serialization. More...
#include <NetworkBuffer.h>
Public Member Functions | |
NetworkBuffer (Allocstrategy strat=BUFFER_ADD) | |
standard c'tor | |
NetworkBuffer (unsigned _size, Allocstrategy strat=BUFFER_ADD) | |
c'tor which calls CheckUnusedSize(_size). | |
void | SetReadOffset (unsigned newoffset) |
set the readoffset, which must not be greater then the writeoffset. | |
void | SetWriteOffset (unsigned newoffset) |
set the Writeoffset, which must not be greater then the buffersize. | |
void | ResetOffsets (void) |
set the read- and the writeoffset to zero. | |
unsigned | GetReadOffset (void) const |
getter for the readoffset | |
unsigned | GetWriteOffset (void) const |
getter for the writeoffset | |
unsigned | GetUnusedSize (void) const |
getter for buffersize - writeoffset = unusedsize | |
unsigned | GetUnreadSize (void) const |
getter for writeoffset - readoffset = unreadsize | |
unsigned | GetBufferSize (void) const |
getter for buffersize | |
const char * | GetData (void) const |
getter for direct access to the buffer. Internal purpose only. | |
const char * | GetDataFromWOffset (void) const |
getter for direct access with pointershift (buffer + writeoffset) | |
const char * | GetDataFromROffset (void) const |
getter for direct access with pointershift (buffer + readoffset) | |
bool | EqualBuffers (const NetworkBuffer &_buf, bool ignoreOffsets) |
compares two buffers with memcmp. If ignoreOffsets is false, the ReadOffset is used. | |
void | SetData (const char *buf, unsigned newsize) |
Copy data from buf directly into buffer. | |
void | ResizeBuffer (unsigned newsize, bool copydata, unsigned copyoffset=0) |
force the buffer to resize (for example if it takes to much space). Shift offsets as well. | |
bool | CheckUnusedSize (unsigned neededsize) |
Checks that there is enough free space. | |
bool | CheckBufferSize (unsigned neededsize, unsigned copyoffset) |
Checks that buffer is big enought. | |
void | ShiftBuffer (bool left, unsigned numbytes) |
shift the data and offsets by numbytes, to left or to right | |
void | WritePlain (volatile const void *_buffer, unsigned _size) |
void*-buffer write methode. | |
void | Write (const char *string) |
char*-string write methode. | |
void | Write (const wchar_t *string) |
wchar_t*-string write methode. | |
template<class T1 > | |
void | WriteAt (const volatile T1 &t, unsigned offset) |
template write methode. | |
void | Write (const NetworkBuffer &_buf) |
Appends _buffer to this buffer. | |
template<class T1 > | |
void | Write (const volatile T1 &t) |
redirector (template). | |
template<class T1 > | |
void | Write (const T1 &t) |
redirector (template). | |
void | Write (const std::string &str) |
redirector for std::string. | |
void | Write (const std::wstring &str) |
redirector for std::wstring. | |
void | Write (char *string) |
redirector for char* strings (has to be nullterminated) | |
void | Write (wchar_t *string) |
redirector for wchar_t* strings (has to be nullterminated) | |
void | ReadPlain (volatile void *buf, unsigned _size) |
Counterpart to WritePlain. Only Read buf(char*). | |
bool | Read (char **str, unsigned int tokenlimit=-1, bool allocate_array=true) |
Counterpart to Write. | |
bool | Read (wchar_t **str, unsigned int tokenlimit=-1, bool allocate_array=true) |
Counterpart to Write. | |
template<typename T > | |
bool | Read (std::basic_string< T > &string, unsigned int tokenlimit=-1) |
Counterpart to Write. | |
template<class T1 > | |
void | Read (T1 &t) |
redirector (template). | |
bool | Read (char str[], unsigned int tokenlimit=-1) |
redirector for char[] | |
bool | Read (wchar_t str[], unsigned int tokenlimit=-1) |
redirector for wchar_t[] | |
template<typename T > | |
void | Write (T *) |
redirector for ptr*. if you know what you do just add a DONT_BOTHER_ME define. | |
template<typename T > | |
bool | Read (T *ptr) |
redirector for ptr* instances. Should never been called because you should never read/write a ptr directly! |
helpclass for data-(de)-serialization.
bool helpers::NetworkBuffer::CheckBufferSize | ( | unsigned | neededsize, |
unsigned | copyoffset | ||
) | [inline] |
Checks that buffer is big enought.
return true, if buffersize is greate enought. Else it resizes the buffer to fit and return false. Only copy with offset (shift to right) if it has to resize.
bool helpers::NetworkBuffer::CheckUnusedSize | ( | unsigned | neededsize | ) | [inline] |
Checks that there is enough free space.
return true, if unusedsize is greate enought. Else it resizes the buffer to fit and return false.
bool helpers::NetworkBuffer::Read | ( | wchar_t ** | str, |
unsigned int | tokenlimit = -1 , |
||
bool | allocate_array = true |
||
) | [inline] |
Counterpart to Write.
Read _size(unsigned int), alloc string, read string(char*) and convert it from multibyte.
bool helpers::NetworkBuffer::Read | ( | std::basic_string< T > & | string, |
unsigned int | tokenlimit = -1 |
||
) | [inline] |
Counterpart to Write.
Read _size(unsigned int), alloc string, read string, copy it and deallocs string.
bool helpers::NetworkBuffer::Read | ( | char ** | str, |
unsigned int | tokenlimit = -1 , |
||
bool | allocate_array = true |
||
) | [inline] |
Counterpart to Write.
Read _size(unsigned int), alloc string (if wished) and read string(char*).
void helpers::NetworkBuffer::ReadPlain | ( | volatile void * | buf, |
unsigned | _size | ||
) | [inline] |
Counterpart to WritePlain. Only Read buf(char*).
void helpers::NetworkBuffer::SetData | ( | const char * | buf, |
unsigned | newsize | ||
) | [inline] |
Copy data from buf directly into buffer.
void helpers::NetworkBuffer::Write | ( | const NetworkBuffer & | _buf | ) | [inline] |
Appends _buffer to this buffer.
Readoffset of _buf is used.
void helpers::NetworkBuffer::Write | ( | const wchar_t * | string | ) | [inline] |
wchar_t*-string write methode.
string should be nullterminated. Convert to multibyte, measure length, write length(unsigned int) + string(char*).
void helpers::NetworkBuffer::Write | ( | const char * | string | ) | [inline] |
char*-string write methode.
string should be nullterminated. Measure length, write length(unsigned int) + string(char*).
void helpers::NetworkBuffer::WriteAt | ( | const volatile T1 & | t, |
unsigned | offset | ||
) | [inline] |
template write methode.
void helpers::NetworkBuffer::WritePlain | ( | volatile const void * | _buffer, |
unsigned | _size | ||
) | [inline] |
void*-buffer write methode.
Write _buffer direct to buffer, without writing _size.