ReplicaNet and RNLobby
1
|
#include <MessageHelper.h>
Public Member Functions | |
DynamicMessageHelper () | |
DynamicMessageHelper (const int size) | |
DynamicMessageHelper (const void *message, const int size) | |
virtual | ~DynamicMessageHelper () |
void | SetBufferSize (const int size=1024) |
int | GetBufferSize (void) |
void | SetSize (const int size) |
void | AddVariable (const void *variable, const int size) |
void | AddData (const void *data, const int size) |
void | FreeBuffer (void) |
void | EnsureBufferAllocated (void) |
bool | Write (const char *filename, const bool rawData=false) |
bool | Read (const char *filename, const bool rawData=false) |
template<typename T > | |
void | operator<< (const T &rhs) |
template<typename T > | |
void | operator>> (T &rhs) |
void | operator<< (const char *rhs) |
void | operator<< (const std::string &rhs) |
void | operator>> (std::string &rhs) |
void | operator<< (const DynamicMessageHelper &rhs) |
void | operator>> (DynamicMessageHelper &rhs) |
bool | operator== (const DynamicMessageHelper &rhs) const |
bool | operator!= (const DynamicMessageHelper &rhs) const |
void | operator<< (const bool &rhs) |
void | operator>> (bool &rhs) |
bool | ReadAsHex (const std::string &data) |
![]() | |
MessageHelper () | |
virtual | ~MessageHelper () |
void | SetBuffer (void *const buffer) |
void * | GetBuffer (void) const |
void * | GetCurrentPosition (void) const |
void | GetVariable (void *const variable, const int size) |
void | GetData (void *const data, const int size) |
void | SkipData (const int size) |
int | GetSize (void) const |
void | SetSize (const int size) |
void | AddInteger (const int value) |
void | AddFloat (const float value) |
int | GetInteger (void) |
float | GetFloat (void) |
std::string | DumpAsHex (const bool csv=true) const |
void | SetGuardSize (const int size=-1) |
void | SanityCheckGuardSize (const int newSize=0) |
int | GetLastSizeAdded (void) const |
template<typename T > | |
void | operator<< (const T &rhs) |
template<typename T > | |
void | operator>> (T &rhs) |
void | operator<< (const char *rhs) |
void | operator<< (const std::string &rhs) |
void | operator>> (std::string &rhs) |
void | operator<< (const bool &rhs) |
void | operator>> (bool &rhs) |
Additional Inherited Members | |
![]() | |
static void | AddVariable (void *buffer, const void *variable, const int size) |
Adds data to a buffer with endian checking. | |
static void | GetVariable (const void *buffer, void *const variable, const int size) |
Adds data from a buffer with endian checking. | |
static int | GetInt (const void *buffer, const int offset) |
static short | GetShort (const void *buffer, const int offset) |
static void | SetInt (void *buffer, const int offset, const int value) |
static void | SetShort (void *buffer, const int offset, const short value) |
static std::string | DumpAsHex (const void *data, const int size, const bool csv=true) |
![]() | |
int | mLastSizeAdded |
This extends the interface provided by MessageHelper to include a data buffer that dynamically grows to accommodate new data.
The ctor performs some basic initialisation
DynamicMessageHelper | ( | const int | size | ) |
The ctor performs some basic initialisation.
size | If size is greater than 0 then the buffer is allocated to be that size. |
DynamicMessageHelper | ( | const void * | message, |
const int | size | ||
) |
The ctor performs some basic initialisation.
message | If message is not null then the data is copied to the message for size bytes. If message is null then a buffer of size is allocated but there is no copy of data. |
size | If size is greater than 0 then the buffer is allocated to be that size. |
|
virtual |
The dtor makes sure everything is tidy
|
virtual |
Adds a data block of a specified size to the message buffer without using any endian checking
data | the pointer to the data |
size | the size of the data |
Reimplemented from MessageHelper.
|
virtual |
Adds a variable of a specified size to the message buffer while using an endian check to preserve the value between platforms with different endian formats
variable | the pointer to the variable |
size | the size of the data |
Reimplemented from MessageHelper.
void EnsureBufferAllocated | ( | void | ) |
This ensures the buffer is allocated.
void FreeBuffer | ( | void | ) |
This frees the buffer used by this class and sets the current size to 0. This also calls SetBufferSize() to reset the size to the default value.
int GetBufferSize | ( | void | ) |
Gets the value configured by SetBufferSize().
bool Read | ( | const char * | filename, |
const bool | rawData = false |
||
) |
Reads the contents of a file to this class. GetBufferSize() will return the size of the message in the file and GetSize() will return 0.
rawData | If true this will read the raw data of the file and not check for the DynamicMessageHelper file header. |
bool ReadAsHex | ( | const std::string & | data | ) |
Reads a hex encoded buffer without commas and converts it to binary data from the current position of the buffer. If there is an error reading the data then the result of the buffer is undefined.
void SetBufferSize | ( | const int | size = 1024 | ) |
Sets the data buffer size to use while constructing or deconstructing this message. Any previous buffer is freed. The buffer is not allocated immediately, buffer allocation happens when data is added to the buffer. To force an allocation of the buffer use EnsureBufferAllocated().
buffer | the buffer pointer to set. The default size is 1024 bytes. |
void SetSize | ( | const int | size | ) |
Sets the current size of the message in bytes, allocating a buffer if required.
the | size of the message in bytes |
bool Write | ( | const char * | filename, |
const bool | rawData = false |
||
) |
Writes the contents of this class to a file.
rawData | If true this will write the raw data of the file and not add the DynamicMessageHelper file header. |