GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ByteBuffer Class Reference

ByteBuffer Class. More...

#include <bytebuffer.h>

Public Member Functions

 ByteBuffer (uint32 capacity)
 Constructor. capacity is a raw guess for the initial size of the buffer.
 
 ByteBuffer (const ByteBuffer &other)
 Copy constructor.
 
const ByteData () const
 Underlying Byte array.
 
void Clear ()
 Empties the buffer.
 
Byte operator[] (uint32 pos) const
 Indexer.
 
template<typename T >
Read (uint32 position) const
 Read a value of type T at a given position.
 
uint32 GetReadPos () const
 Returns the current read position.
 
void SetReadPos (uint32 readPos)
 Updates the current read position.
 
uint32 GetWritePos () const
 Returns the current write position.
 
void SetWritePos (uint32 writePos)
 Updates the current write position.
 
void FinishRead ()
 Advances read position to end of buffer, ignoring all its content.
 
template<typename T >
void ReadSkip ()
 Advances read position by sizeof(T), ignoring those Bytes.
 
void ReadSkip (uint32 size)
 Advances read position by the given size (in Bytes), ignoring those Bytes.
 
uint32 Size () const
 Returns the size of the buffer.
 
bool IsEmpty () const
 True if buffer is currently empty.
 
void Resize (uint32 newSize)
 Resizes the underlying buffer to a new size (adding (nulls) or removing content)
 
void Reserve (uint32 size)
 Reserves space for the underlying buffer (see std::vector<T>::reserve)
 
void Print (std::ostream &stream) const
 Prints the buffer content in an user friendly way (both ascii and hex)
 
void WriteBool (bool value)
 
void WriteUInt8 (uint8 value)
 
void WriteUInt16 (uint16 value)
 
void WriteUInt32 (uint32 value)
 
void WriteUInt64 (uint64 value)
 
void WriteInt8 (int8 value)
 
void WriteInt16 (int16 value)
 
void WriteInt32 (int32 value)
 
void WriteInt64 (int64 value)
 
void WriteFloat (float value)
 
void WriteDouble (double value)
 
void WriteString (const std::string &value)
 Writes a variable length size (4 bytes max) then the string.
 
void WriteString (const char *value)
 
void WriteCString (const char *value)
 Writes a null terminated string.
 
void WriteCString (const std::string &value)
 
void WriteBuffer (const ByteBuffer &other)
 
void WriteBuffer (const char *src, uint32 count)
 
bool ReadBool ()
 
uint8 ReadUInt8 ()
 
uint16 ReadUInt16 ()
 
uint32 ReadUInt32 ()
 
uint64 ReadUInt64 ()
 
int8 ReadInt8 ()
 
int16 ReadInt16 ()
 
int32 ReadInt32 ()
 
int64 ReadInt64 ()
 
float ReadFloat ()
 
double ReadDouble ()
 
std::string ReadString ()
 Reads a string prefixed with a variable length size (4 bytes max)
 
std::string ReadCString ()
 Reads a string until the null terminator is found.
 
ByteBufferoperator<< (bool value)
 
ByteBufferoperator<< (uint8 value)
 
ByteBufferoperator<< (uint16 value)
 
ByteBufferoperator<< (uint32 value)
 
ByteBufferoperator<< (uint64 value)
 
ByteBufferoperator<< (int8 value)
 
ByteBufferoperator<< (int16 value)
 
ByteBufferoperator<< (int32 value)
 
ByteBufferoperator<< (int64 value)
 
ByteBufferoperator<< (float value)
 
ByteBufferoperator<< (double value)
 
ByteBufferoperator<< (const std::string &value)
 
ByteBufferoperator<< (const char *value)
 
ByteBufferoperator<< (const ByteBuffer &value)
 
ByteBufferoperator>> (bool &value)
 
ByteBufferoperator>> (uint8 &value)
 
ByteBufferoperator>> (uint16 &value)
 
ByteBufferoperator>> (uint32 &value)
 
ByteBufferoperator>> (uint64 &value)
 
ByteBufferoperator>> (int8 &value)
 
ByteBufferoperator>> (int16 &value)
 
ByteBufferoperator>> (int32 &value)
 
ByteBufferoperator>> (int64 &value)
 
ByteBufferoperator>> (float &value)
 
ByteBufferoperator>> (double &value)
 
ByteBufferoperator>> (std::string &value)
 
 operator const char * ()
 Implicit conversion to char*.
 
 operator const std::string ()
 Implicit conversion to std::string.
 

Protected Member Functions

template<typename T >
Read ()
 
void Read (Byte *dest, uint32 count)
 
template<typename T >
void Append (T val)
 
template<typename T >
void Append (const T *src, uint32 count)
 
void Append (const ByteBuffer &other)
 
void Append (const Byte *src, uint32 count)
 
template<typename T >
void Put (uint32 pos, T val)
 
void Put (uint32 pos, const Byte *src, uint32 count)
 

Protected Attributes

std::vector< Byte_buffer
 Underlying buffer of Bytes.
 
uint32 _readPos
 Current read position.
 
uint32 _writePos
 Current write position.
 

Private Member Functions

void Append7BitEncodedInt (uint32 value)
 Variable length value.
 
uint32 Read7BitEncodedInt ()
 Variable length value.
 

Detailed Description

ByteBuffer Class.

ByteBuffer is a container of bytes. It allows to represent multiple types (ints, strings, floats, etc) in a binary format (great for any form of communication (files, network, etc.)

Constructor & Destructor Documentation

ByteBuffer::ByteBuffer ( uint32  capacity)

Constructor. capacity is a raw guess for the initial size of the buffer.

ByteBuffer::ByteBuffer ( const ByteBuffer other)

Copy constructor.

Member Function Documentation

template<typename T >
void ByteBuffer::Append ( val)
protected
template<typename T >
void ByteBuffer::Append ( const T *  src,
uint32  count 
)
protected
void ByteBuffer::Append ( const ByteBuffer other)
protected
void ByteBuffer::Append ( const Byte src,
uint32  count 
)
protected
void ByteBuffer::Append7BitEncodedInt ( uint32  value)
private

Variable length value.

void ByteBuffer::Clear ( )

Empties the buffer.

const Byte * ByteBuffer::Data ( ) const

Underlying Byte array.

void ByteBuffer::FinishRead ( )

Advances read position to end of buffer, ignoring all its content.

uint32 ByteBuffer::GetReadPos ( ) const

Returns the current read position.

uint32 ByteBuffer::GetWritePos ( ) const

Returns the current write position.

bool ByteBuffer::IsEmpty ( ) const

True if buffer is currently empty.

ByteBuffer::operator const char * ( )

Implicit conversion to char*.

ByteBuffer::operator const std::string ( )

Implicit conversion to std::string.

ByteBuffer& ByteBuffer::operator<< ( bool  value)
ByteBuffer& ByteBuffer::operator<< ( uint8  value)
ByteBuffer& ByteBuffer::operator<< ( uint16  value)
ByteBuffer& ByteBuffer::operator<< ( uint32  value)
ByteBuffer& ByteBuffer::operator<< ( uint64  value)
ByteBuffer& ByteBuffer::operator<< ( int8  value)
ByteBuffer& ByteBuffer::operator<< ( int16  value)
ByteBuffer& ByteBuffer::operator<< ( int32  value)
ByteBuffer& ByteBuffer::operator<< ( int64  value)
ByteBuffer& ByteBuffer::operator<< ( float  value)
ByteBuffer& ByteBuffer::operator<< ( double  value)
ByteBuffer& ByteBuffer::operator<< ( const std::string &  value)
ByteBuffer& ByteBuffer::operator<< ( const char *  value)
ByteBuffer& ByteBuffer::operator<< ( const ByteBuffer value)
ByteBuffer& ByteBuffer::operator>> ( bool &  value)
ByteBuffer& ByteBuffer::operator>> ( uint8 value)
ByteBuffer& ByteBuffer::operator>> ( uint16 value)
ByteBuffer& ByteBuffer::operator>> ( uint32 value)
ByteBuffer& ByteBuffer::operator>> ( uint64 value)
ByteBuffer& ByteBuffer::operator>> ( int8 value)
ByteBuffer& ByteBuffer::operator>> ( int16 value)
ByteBuffer& ByteBuffer::operator>> ( int32 value)
ByteBuffer& ByteBuffer::operator>> ( int64 value)
ByteBuffer& ByteBuffer::operator>> ( float &  value)
ByteBuffer& ByteBuffer::operator>> ( double &  value)
ByteBuffer& ByteBuffer::operator>> ( std::string &  value)
Byte ByteBuffer::operator[] ( uint32  pos) const

Indexer.

void ByteBuffer::Print ( std::ostream &  stream) const

Prints the buffer content in an user friendly way (both ascii and hex)

template<typename T >
void ByteBuffer::Put ( uint32  pos,
val 
)
protected
void ByteBuffer::Put ( uint32  pos,
const Byte src,
uint32  count 
)
protected
template<typename T >
T ByteBuffer::Read ( uint32  position) const

Read a value of type T at a given position.

template<typename T >
T ByteBuffer::Read ( )
protected
void ByteBuffer::Read ( Byte dest,
uint32  count 
)
protected
uint32 ByteBuffer::Read7BitEncodedInt ( )
private

Variable length value.

bool ByteBuffer::ReadBool ( )
std::string ByteBuffer::ReadCString ( )

Reads a string until the null terminator is found.

double ByteBuffer::ReadDouble ( )
float ByteBuffer::ReadFloat ( )
int16 ByteBuffer::ReadInt16 ( )
int32 ByteBuffer::ReadInt32 ( )
int64 ByteBuffer::ReadInt64 ( )
int8 ByteBuffer::ReadInt8 ( )
template<typename T >
void ByteBuffer::ReadSkip ( )

Advances read position by sizeof(T), ignoring those Bytes.

void ByteBuffer::ReadSkip ( uint32  size)

Advances read position by the given size (in Bytes), ignoring those Bytes.

std::string ByteBuffer::ReadString ( )

Reads a string prefixed with a variable length size (4 bytes max)

uint16 ByteBuffer::ReadUInt16 ( )
uint32 ByteBuffer::ReadUInt32 ( )
uint64 ByteBuffer::ReadUInt64 ( )
uint8 ByteBuffer::ReadUInt8 ( )
void ByteBuffer::Reserve ( uint32  size)

Reserves space for the underlying buffer (see std::vector<T>::reserve)

void ByteBuffer::Resize ( uint32  newSize)

Resizes the underlying buffer to a new size (adding (nulls) or removing content)

void ByteBuffer::SetReadPos ( uint32  readPos)

Updates the current read position.

void ByteBuffer::SetWritePos ( uint32  writePos)

Updates the current write position.

uint32 ByteBuffer::Size ( ) const

Returns the size of the buffer.

void ByteBuffer::WriteBool ( bool  value)
void ByteBuffer::WriteBuffer ( const ByteBuffer other)
void ByteBuffer::WriteBuffer ( const char *  src,
uint32  count 
)
void ByteBuffer::WriteCString ( const char *  value)

Writes a null terminated string.

void ByteBuffer::WriteCString ( const std::string &  value)
void ByteBuffer::WriteDouble ( double  value)
void ByteBuffer::WriteFloat ( float  value)
void ByteBuffer::WriteInt16 ( int16  value)
void ByteBuffer::WriteInt32 ( int32  value)
void ByteBuffer::WriteInt64 ( int64  value)
void ByteBuffer::WriteInt8 ( int8  value)
void ByteBuffer::WriteString ( const std::string &  value)

Writes a variable length size (4 bytes max) then the string.

void ByteBuffer::WriteString ( const char *  value)
void ByteBuffer::WriteUInt16 ( uint16  value)
void ByteBuffer::WriteUInt32 ( uint32  value)
void ByteBuffer::WriteUInt64 ( uint64  value)
void ByteBuffer::WriteUInt8 ( uint8  value)

Member Data Documentation

std::vector<Byte> ByteBuffer::_buffer
protected

Underlying buffer of Bytes.

uint32 ByteBuffer::_readPos
protected

Current read position.

uint32 ByteBuffer::_writePos
protected

Current write position.


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