# MessageBuffer Class Reference

MessageBuffer is a class managing a byte buffer for Message exchange. More...

`#include <MessageBuffer.hh>`

List of all members.

## Public Member Functions
| MessageBuffer ()
| Default message buffer constructor.
| MessageBuffer (uint32_t bufferMaxSize)
| Constructor with size.
| ~MessageBuffer ()
| Destructor.
uint32_t | size () const
| Return the current buffer size (in bytes).
uint32_t | maxSize () const
| Return the current maximum buffer size (in bytes).
void | assumeBufferIsBigEndian ()
| Assume the buffer is big endian.
void | assumeBufferIsLittleEndian ()
| Assume the buffer is little endian.
void | reset ()
| Reset buffer state This method should be called if ones want to re-use a buffer in order to avoid reallocation.
void | seek_write (uint32_t offset)
| Seek buffer in order to write at specified place Will set the write pointer to the seeked offset.
uint32_t | resize (uint32_t newSize)
| Resize the current maximum buffer size (in bytes).
void | assumeSize (uint32_t size)
| Assume that the underlying buffer has the specified size.
void | assumeSizeFromReservedBytes ()
int32_t | write_uint8s (const uint8_t *data, uint32_t n)
int32_t | read_uint8s (uint8_t *data, uint32_t n)
int32_t | write_chars (const char *data, uint32_t n)
int32_t | read_chars (char *data, uint32_t n)
int32_t | write_uint16s (const uint16_t *data, uint32_t n)
int32_t | read_uint16s (uint16_t *data, uint32_t n)
int32_t | write_uint32s (const uint32_t *data, uint32_t n)
int32_t | read_uint32s (uint32_t *data, uint32_t n)
int32_t | write_uint64s (const uint64_t *data, uint32_t n)
int32_t | read_uint64s (uint64_t *data, uint32_t n)
int32_t | write_floats (const float *data, uint32_t n)
int32_t | read_floats (float *data, uint32_t n)
int32_t | write_doubles (const double *data, uint32_t n)
int32_t | read_doubles (double *data, uint32_t n)
int32_t | write_string (const std::string &str)
std::string | read_string ()
int32_t | write_bool (const bool toggle)
bool | read_bool ()
MessageBuffer & | operator<< (const uint8_t data)
void | updateReservedBytes ()
void * | operator() (uint32_t offset)
## Static Public Member Functions
static const bool | HostIsBigEndian ()
| Return true if the host is BidEndian.
static const bool | HostIsLittleEndian ()
| Return true if the host is LittleEndian.
static void | show (const void *data, uint32_t n)
| Show n bytes of data content in hexa on stdout.
## Static Public Attributes
static const uint8_t | reservedBytes = 5
## Private Member Functions
void | initialize ()
void | reallocate (uint32_t n)
void | setSizeInReservedBytes (uint32_t n)
## Private Attributes
uint8_t * | buffer
| The buffer itself.
uint32_t | bufferMaxSize
| The provisioned buffer size.
bool | bufferHasMyEndianness
| Endianness toggle.
uint32_t | writeOffset
| The write offset is the offset of the buffer where the next write operation will write to.
uint32_t | readOffset
| The read offset is the offset of the buffer where the next read operation will read from.

## Detailed Description

MessageBuffer is a class managing a byte buffer for Message exchange.

It provides member functions to read and write basics types [unsigned] int 8/16/32/64, float, double, byte etc... The message buffer will encode the written [type] data with proper byte ordering and padding. A message buffer handles heterogeneous write/read pair, in fact it the central class for heterogeneity handling. One must read from the buffer in the exact order the write was done. MessageBuffer is dynamically sized.

Definition at line 42 of file MessageBuffer.hh.

## Constructor & Destructor Documentation

MessageBuffer | ( |  | ) |

Default message buffer constructor.

The default message buffer size is DEFAULT_MESSAGE_BUFFER_SIZE.

Definition at line 74 of file MessageBuffer.cc.

References DEFAULT_MESSAGE_BUFFER_SIZE, MessageBuffer::initialize(), and MessageBuffer::reallocate().

Here is the call graph for this function:

MessageBuffer | ( | uint32_t | bufferMaxSize | ) |

Constructor with size.

Build a MessageBuffer with provisionned bufSize buffer.

Parameters:

  `[in]` | bufferMaxSize,the | [initial] maixmum size of the buffer

Definition at line 79 of file MessageBuffer.cc.

References MessageBuffer::initialize(), and MessageBuffer::reallocate().

Here is the call graph for this function:

~MessageBuffer | ( |  | ) |

Destructor.

Definition at line 115 of file MessageBuffer.cc.

References MessageBuffer::buffer.

## Member Function Documentation

const bool HostIsBigEndian | ( |  | ) | `[static]`

Return true if the host is BidEndian.

Definition at line 35 of file MessageBuffer.cc.

Referenced by MessageBuffer::assumeBufferIsBigEndian(), and MessageBuffer::updateReservedBytes().

const bool HostIsLittleEndian | ( |  | ) | `[static]`

Return true if the host is LittleEndian.

Definition at line 44 of file MessageBuffer.cc.

Referenced by MessageBuffer::assumeBufferIsLittleEndian(), and MessageBuffer::updateReservedBytes().

void show | ( | const void * | data,
|  | uint32_t | n |
| ) |  |  | `[static]`

Show n bytes of data content in hexa on stdout.

Definition at line 53 of file MessageBuffer.cc.

uint32_t size | ( |  | ) | const

Return the current buffer size (in bytes).

This is the size in bytes of the element that were written to the buffer.

Returns:
  the current buffer size

Definition at line 121 of file MessageBuffer.cc.

References MessageBuffer::writeOffset.

Referenced by MessageBuffer::updateReservedBytes().

uint32_t maxSize | ( |  | ) | const

Return the current maximum buffer size (in bytes).

This is the size of the allocated buffer.

Returns:
  the current buffer maximum size

Definition at line 125 of file MessageBuffer.cc.

References MessageBuffer::bufferMaxSize.

void assumeBufferIsBigEndian | ( |  | ) |

Assume the buffer is big endian.

Definition at line 129 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, and MessageBuffer::HostIsBigEndian().

Referenced by MessageBuffer::assumeSizeFromReservedBytes().

Here is the call graph for this function:

void assumeBufferIsLittleEndian | ( |  | ) |

Assume the buffer is little endian.

Definition at line 134 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, and MessageBuffer::HostIsLittleEndian().

Referenced by MessageBuffer::assumeSizeFromReservedBytes().

Here is the call graph for this function:

void reset | ( |  | ) |

Reset buffer state This method should be called if ones want to re-use a buffer in order to avoid reallocation.

Definition at line 139 of file MessageBuffer.cc.

References MessageBuffer::bufferHasMyEndianness, MessageBuffer::readOffset, MessageBuffer::reservedBytes, MessageBuffer::updateReservedBytes(), and MessageBuffer::writeOffset.

Here is the call graph for this function:

void seek_write | ( | uint32_t | offset | ) |

Seek buffer in order to write at specified place Will set the write pointer to the seeked offset.

uint32_t resize | ( | uint32_t | newSize | ) |

Resize the current maximum buffer size (in bytes).

This is the size of the allocated buffer.

Parameters:

  `[in]` | the | new buffer maximum size

Returns:
  the new buffer maximum size

Definition at line 146 of file MessageBuffer.cc.

References MessageBuffer::bufferMaxSize, and MessageBuffer::reallocate().

Here is the call graph for this function:

void assumeSize | ( | uint32_t | size | ) |

Assume that the underlying buffer has the specified size.

This may be used after ones get raw pointer to the underlying buffer and has written to the buffer using memcpy/recv.

Parameters:

  `[in]` | size | the assumed size

Definition at line 151 of file MessageBuffer.cc.

References MessageBuffer::bufferMaxSize, and MessageBuffer::writeOffset.

Referenced by MessageBuffer::assumeSizeFromReservedBytes().

void assumeSizeFromReservedBytes | ( |  | ) |

Definition at line 163 of file MessageBuffer.cc.

References MessageBuffer::assumeBufferIsBigEndian(), MessageBuffer::assumeBufferIsLittleEndian(), MessageBuffer::assumeSize(), MessageBuffer::buffer, MessageBuffer::readOffset, and MessageBuffer::reallocate().

Referenced by NM_Factory::receive().

Here is the call graph for this function:

int32_t write_uint8s | ( | const uint8_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 191 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferMaxSize, certi::D, DEFAULT_MESSAGE_BUFFER_SIZE, PrettyDebug::Out(), pdTrace, MessageBuffer::reallocate(), and MessageBuffer::writeOffset.

Here is the call graph for this function:

int32_t read_uint8s | ( | uint8_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 206 of file MessageBuffer.cc.

References MessageBuffer::buffer, certi::D, PrettyDebug::Out(), pdTrace, MessageBuffer::readOffset, and MessageBuffer::writeOffset.

Here is the call graph for this function:

int32_t write_chars | ( | const char * | data,
|  | uint32_t | n |
| ) |  |  | `[inline]`

Definition at line 189 of file MessageBuffer.hh.

Referenced by MessageBuffer::write_string().

int32_t read_chars | ( | char * | data,
|  | uint32_t | n |
| ) |  |  | `[inline]`

Definition at line 194 of file MessageBuffer.hh.

Referenced by MessageBuffer::read_string().

int32_t write_uint16s | ( | const uint16_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 222 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, MessageBuffer::bufferMaxSize, CERTI_UINT16_SWAP_BYTES, certi::D, DEFAULT_MESSAGE_BUFFER_SIZE, PrettyDebug::Out(), pdTrace, MessageBuffer::reallocate(), and MessageBuffer::writeOffset.

Here is the call graph for this function:

int32_t read_uint16s | ( | uint16_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 247 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, CERTI_UINT16_SWAP_BYTES, certi::D, PrettyDebug::Out(), pdTrace, MessageBuffer::readOffset, and MessageBuffer::writeOffset.

Here is the call graph for this function:

int32_t write_uint32s | ( | const uint32_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 276 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, MessageBuffer::bufferMaxSize, CERTI_UINT32_SWAP_BYTES, certi::D, DEFAULT_MESSAGE_BUFFER_SIZE, PrettyDebug::Out(), pdTrace, MessageBuffer::reallocate(), and MessageBuffer::writeOffset.

Referenced by MessageBuffer::write_floats().

Here is the call graph for this function:

int32_t read_uint32s | ( | uint32_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 301 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, CERTI_UINT32_SWAP_BYTES, certi::D, PrettyDebug::Out(), pdTrace, MessageBuffer::readOffset, and MessageBuffer::writeOffset.

Referenced by MessageBuffer::read_floats().

Here is the call graph for this function:

int32_t write_uint64s | ( | const uint64_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 329 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, MessageBuffer::bufferMaxSize, CERTI_UINT32_SWAP_BYTES, certi::D, DEFAULT_MESSAGE_BUFFER_SIZE, PrettyDebug::Out(), pdTrace, MessageBuffer::reallocate(), and MessageBuffer::writeOffset.

Referenced by MessageBuffer::write_doubles().

Here is the call graph for this function:

int32_t read_uint64s | ( | uint64_t * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 363 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, CERTI_UINT32_SWAP_BYTES, certi::D, PrettyDebug::Out(), pdTrace, MessageBuffer::readOffset, and MessageBuffer::writeOffset.

Referenced by MessageBuffer::read_doubles().

Here is the call graph for this function:

int32_t write_floats | ( | const float * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 401 of file MessageBuffer.cc.

References certi::D, PrettyDebug::Out(), pdTrace, and MessageBuffer::write_uint32s().

Here is the call graph for this function:

int32_t read_floats | ( | float * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 408 of file MessageBuffer.cc.

References certi::D, PrettyDebug::Out(), pdTrace, and MessageBuffer::read_uint32s().

Here is the call graph for this function:

int32_t write_doubles | ( | const double * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 415 of file MessageBuffer.cc.

References certi::D, PrettyDebug::Out(), pdTrace, and MessageBuffer::write_uint64s().

Here is the call graph for this function:

int32_t read_doubles | ( | double * | data,
|  | uint32_t | n |
| ) |  |  |

Definition at line 422 of file MessageBuffer.cc.

References certi::D, PrettyDebug::Out(), pdTrace, and MessageBuffer::read_uint64s().

Here is the call graph for this function:

int32_t write_string | ( | const std::string & | str | ) |

Definition at line 430 of file MessageBuffer.cc.

References MessageBuffer::write_chars().

Referenced by NM_Get_FED_File::serialize(), NM_Send_Interaction::serialize(), NM_Update_Attribute_Values::serialize(), NM_Join_Federation_Execution::serialize(), NM_Destroy_Federation_Execution::serialize(), NM_Create_Federation_Execution::serialize(), NetworkMessage::serialize(), Message::writeBody(), Message::writeFederationName(), Message::writeFEDid(), and Message::writeValueArray().

Here is the call graph for this function:

std::string read_string | ( |  | ) |

Definition at line 436 of file MessageBuffer.cc.

References MessageBuffer::read_chars().

Referenced by NM_Get_FED_File::deserialize(), NM_Send_Interaction::deserialize(), NM_Update_Attribute_Values::deserialize(), NM_Join_Federation_Execution::deserialize(), NM_Destroy_Federation_Execution::deserialize(), NM_Create_Federation_Execution::deserialize(), NetworkMessage::deserialize(), Message::readBody(), Message::readFederateName(), Message::readFederationName(), Message::readFEDid(), Message::readLabel(), Message::readName(), Message::readTag(), and Message::readValueArray().

Here is the call graph for this function:

int32_t write_bool | ( | const bool | toggle | ) | `[inline]`

Definition at line 253 of file MessageBuffer.hh.

Referenced by NM_DDM_Subscribe_Interaction::serialize(), NM_DDM_Subscribe_Attributes::serialize(), NM_DDM_Register_Object::serialize(), NM_DDM_Associate_Region::serialize(), NM_Register_Federation_Synchronization_Point::serialize(), NM_Set_Attribute_Scope_Advisory_Switch::serialize(), NM_Set_Attribute_Relevance_Advisory_Switch::serialize(), NM_Set_Interaction_Relevance_Advisory_Switch::serialize(), NM_Set_Class_Relevance_Advisory_Switch::serialize(), NM_Set_Time_Constrained::serialize(), NM_Set_Time_Regulating::serialize(), NetworkMessage::serialize(), and Message::writeBody().

bool read_bool | ( |  | ) | `[inline]`

Definition at line 262 of file MessageBuffer.hh.

Referenced by NM_DDM_Subscribe_Interaction::deserialize(), NM_DDM_Subscribe_Attributes::deserialize(), NM_DDM_Register_Object::deserialize(), NM_DDM_Associate_Region::deserialize(), NM_Register_Federation_Synchronization_Point::deserialize(), NM_Set_Attribute_Scope_Advisory_Switch::deserialize(), NM_Set_Attribute_Relevance_Advisory_Switch::deserialize(), NM_Set_Interaction_Relevance_Advisory_Switch::deserialize(), NM_Set_Class_Relevance_Advisory_Switch::deserialize(), NM_Set_Time_Constrained::deserialize(), NM_Set_Time_Regulating::deserialize(), NetworkMessage::deserialize(), and Message::readBody().

MessageBuffer& operator<< | ( | const uint8_t | data | ) | `[inline]`

Definition at line 266 of file MessageBuffer.hh.

void updateReservedBytes | ( |  | ) |

Definition at line 449 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, MessageBuffer::HostIsBigEndian(), MessageBuffer::HostIsLittleEndian(), MessageBuffer::setSizeInReservedBytes(), and MessageBuffer::size().

Referenced by MessageBuffer::reallocate(), and MessageBuffer::reset().

Here is the call graph for this function:

void * operator() | ( | uint32_t | offset | ) |

Definition at line 462 of file MessageBuffer.cc.

References MessageBuffer::buffer.

void initialize | ( |  | ) | `[private]`

Definition at line 66 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferHasMyEndianness, MessageBuffer::bufferMaxSize, DEFAULT_MESSAGE_BUFFER_SIZE, MessageBuffer::readOffset, MessageBuffer::reservedBytes, and MessageBuffer::writeOffset.

Referenced by MessageBuffer::MessageBuffer().

void reallocate | ( | uint32_t | n | ) | `[private]`

Definition at line 88 of file MessageBuffer.cc.

References MessageBuffer::buffer, MessageBuffer::bufferMaxSize, MessageBuffer::updateReservedBytes(), and MessageBuffer::writeOffset.

Referenced by MessageBuffer::assumeSizeFromReservedBytes(), MessageBuffer::MessageBuffer(), MessageBuffer::resize(), MessageBuffer::write_uint16s(), MessageBuffer::write_uint32s(), MessageBuffer::write_uint64s(), and MessageBuffer::write_uint8s().

Here is the call graph for this function:

void setSizeInReservedBytes | ( | uint32_t | n | ) | `[private]`

Definition at line 179 of file MessageBuffer.cc.

References certi::D, PrettyDebug::Out(), pdTrace, and MessageBuffer::writeOffset.

Referenced by MessageBuffer::updateReservedBytes().

Here is the call graph for this function:

## Member Data Documentation

const uint8_t reservedBytes = 5`[static]`

Definition at line 68 of file MessageBuffer.hh.

Referenced by MessageBuffer::initialize(), and MessageBuffer::reset().

uint8_t* buffer`[private]`

The buffer itself.

Definition at line 283 of file MessageBuffer.hh.

Referenced by MessageBuffer::assumeBufferIsBigEndian(), MessageBuffer::assumeBufferIsLittleEndian(), MessageBuffer::assumeSizeFromReservedBytes(), MessageBuffer::initialize(), MessageBuffer::operator()(), MessageBuffer::read_uint16s(), MessageBuffer::read_uint32s(), MessageBuffer::read_uint64s(), MessageBuffer::read_uint8s(), MessageBuffer::reallocate(), MessageBuffer::updateReservedBytes(), MessageBuffer::write_uint16s(), MessageBuffer::write_uint32s(), MessageBuffer::write_uint64s(), MessageBuffer::write_uint8s(), and MessageBuffer::~MessageBuffer().

uint32_t bufferMaxSize`[private]`

The provisioned buffer size.

Definition at line 285 of file MessageBuffer.hh.

Referenced by MessageBuffer::assumeSize(), MessageBuffer::initialize(), MessageBuffer::maxSize(), MessageBuffer::reallocate(), MessageBuffer::resize(), MessageBuffer::write_uint16s(), MessageBuffer::write_uint32s(), MessageBuffer::write_uint64s(), and MessageBuffer::write_uint8s().

bool bufferHasMyEndianness`[private]`

Endianness toggle.

Definition at line 287 of file MessageBuffer.hh.

Referenced by MessageBuffer::assumeBufferIsBigEndian(), MessageBuffer::assumeBufferIsLittleEndian(), MessageBuffer::initialize(), MessageBuffer::read_uint16s(), MessageBuffer::read_uint32s(), MessageBuffer::read_uint64s(), MessageBuffer::reset(), MessageBuffer::updateReservedBytes(), MessageBuffer::write_uint16s(), MessageBuffer::write_uint32s(), and MessageBuffer::write_uint64s().

uint32_t writeOffset`[private]`

The write offset is the offset of the buffer where the next write operation will write to.

Definition at line 292 of file MessageBuffer.hh.

Referenced by MessageBuffer::assumeSize(), MessageBuffer::initialize(), MessageBuffer::read_uint16s(), MessageBuffer::read_uint32s(), MessageBuffer::read_uint64s(), MessageBuffer::read_uint8s(), MessageBuffer::reallocate(), MessageBuffer::reset(), MessageBuffer::setSizeInReservedBytes(), MessageBuffer::size(), MessageBuffer::write_uint16s(), MessageBuffer::write_uint32s(), MessageBuffer::write_uint64s(), and MessageBuffer::write_uint8s().

uint32_t readOffset`[private]`

The read offset is the offset of the buffer where the next read operation will read from.

Definition at line 298 of file MessageBuffer.hh.

Referenced by MessageBuffer::assumeSizeFromReservedBytes(), MessageBuffer::initialize(), MessageBuffer::read_uint16s(), MessageBuffer::read_uint32s(), MessageBuffer::read_uint64s(), MessageBuffer::read_uint8s(), and MessageBuffer::reset().

The documentation for this class was generated from the following files:

- MessageBuffer.hh
- MessageBuffer.cc