ReplicaNet and RNLobby
1
|
#include <MessageHelper.h>
Classes | |
class | Exception |
Public Member Functions | |
MessageHelper () | |
virtual | ~MessageHelper () |
void | SetBuffer (void *const buffer) |
void * | GetBuffer (void) const |
void * | GetCurrentPosition (void) const |
virtual void | AddVariable (const void *variable, const int size) |
virtual void | AddData (const void *data, const int size) |
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) |
Static Public Member Functions | |
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) |
Protected Attributes | |
int | mLastSizeAdded |
A simple message helper class that helps to construct and deconstruct sequences of variables. This routine is endian safe and should be used where data needs to be endian safe
MessageHelper | ( | ) |
The ctor performs some basic initialisation
|
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 in DynamicMessageHelper.
void AddFloat | ( | const float | value | ) |
Adds a float to the message buffer
value | the value to add |
void AddInteger | ( | const int | value | ) |
Adds an integer to the message buffer
value | the value to add |
|
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 in DynamicMessageHelper.
|
static |
This produces a hex dump of any length of data
void* GetBuffer | ( | void | ) | const |
Gets the pointer to the start of the buffer.
void* GetCurrentPosition | ( | void | ) | const |
Gets the pointer to the current position in the buffer.
void GetData | ( | void *const | data, |
const int | size | ||
) |
Gets data of a specified size from the message buffer
data | the pointer to the data |
size | the size of the data |
float GetFloat | ( | void | ) |
Gets a float from the message buffer
value | the value to get |
int GetInteger | ( | void | ) |
Gets an integer from the message buffer
value | the value to get |
int GetLastSizeAdded | ( | void | ) | const |
Returns the last size added to this MessageHelper.
int GetSize | ( | void | ) | const |
Returns the current size of the message in bytes
void GetVariable | ( | void *const | variable, |
const int | size | ||
) |
Gets a variable of a specified size from the message buffer
variable | the pointer to the variable |
size | the size of the data |
void SetBuffer | ( | void *const | buffer | ) |
Sets the data buffer pointer to use while constructing or deconstructing this message. This also causes the length of the buffer to revert to zero.
buffer | the buffer pointer to set |
void SetGuardSize | ( | const int | size = -1 | ) |
Sets the guard size and if the MessageHepler reads past the guard a MessageHepler::Exception() exception is thrown.
size | If < 0 then the exception is disabled. Otherwise an exception is thrown when data is read beyond the size configured. |
void SetSize | ( | const int | size | ) |
Sets the current size of the message in bytes.
the | size of the message in bytes |
void SkipData | ( | const int | size | ) |
Skips data of a specified size from the message buffer
size | the size of the data |