ReplicaNet and RNLobby  1
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
MessageHelper Class Reference

#include <MessageHelper.h>

Inheritance diagram for MessageHelper:
Inheritance graph
[legend]

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
 

Detailed Description

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

Constructor & Destructor Documentation

The ctor performs some basic initialisation

virtual ~MessageHelper ( )
virtual

The dtor makes sure everything is tidy

Member Function Documentation

virtual void AddData ( const void *  data,
const int  size 
)
virtual

Adds a data block of a specified size to the message buffer without using any endian checking

Parameters
datathe pointer to the data
sizethe size of the data

Reimplemented in DynamicMessageHelper.

void AddFloat ( const float  value)

Adds a float to the message buffer

Parameters
valuethe value to add
void AddInteger ( const int  value)

Adds an integer to the message buffer

Parameters
valuethe value to add
virtual void AddVariable ( const void *  variable,
const int  size 
)
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

Parameters
variablethe pointer to the variable
sizethe size of the data

Reimplemented in DynamicMessageHelper.

static std::string DumpAsHex ( const void *  data,
const int  size,
const bool  csv = true 
)
static

This produces a hex dump of any length of data

void* GetBuffer ( void  ) const

Gets the pointer to the start of the buffer.

Returns
The pointer to the start of the buffer.
void* GetCurrentPosition ( void  ) const

Gets the pointer to the current position in the buffer.

Returns
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

Parameters
datathe pointer to the data
sizethe size of the data
float GetFloat ( void  )

Gets a float from the message buffer

Parameters
valuethe value to get
int GetInteger ( void  )

Gets an integer from the message buffer

Parameters
valuethe 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

Returns
returns the size of the message buffer in bytes
void GetVariable ( void *const  variable,
const int  size 
)

Gets a variable of a specified size from the message buffer

Parameters
variablethe pointer to the variable
sizethe 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.

Parameters
bufferthe 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.

Parameters
sizeIf < 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.

Parameters
thesize of the message in bytes
void SkipData ( const int  size)

Skips data of a specified size from the message buffer

Parameters
sizethe size of the data