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 ()
MessageBufferoperator<< (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 (  ) 

int32_t write_uint8s ( const uint8_t *  data,
uint32_t  n 
)

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 
)

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 
)

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  ) 

std::string read_string (  ) 

int32_t write_bool ( const bool  toggle  )  [inline]

bool read_bool (  )  [inline]

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

Definition at line 266 of file MessageBuffer.hh.

void updateReservedBytes (  ) 

void * operator() ( uint32_t  offset  ) 

Definition at line 462 of file MessageBuffer.cc.

References MessageBuffer::buffer.

void initialize (  )  [private]

void reallocate ( uint32_t  n  )  [private]

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]

uint32_t bufferMaxSize [private]

bool bufferHasMyEndianness [private]

uint32_t writeOffset [private]

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:

Generated on Thu Apr 30 15:55:28 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5