GridComputing
Job Management in Grid Computing
|
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 Byte * | Data () const |
Underlying Byte array. | |
void | Clear () |
Empties the buffer. | |
Byte | operator[] (uint32 pos) const |
Indexer. | |
template<typename T > | |
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. | |
ByteBuffer & | operator<< (bool value) |
ByteBuffer & | operator<< (uint8 value) |
ByteBuffer & | operator<< (uint16 value) |
ByteBuffer & | operator<< (uint32 value) |
ByteBuffer & | operator<< (uint64 value) |
ByteBuffer & | operator<< (int8 value) |
ByteBuffer & | operator<< (int16 value) |
ByteBuffer & | operator<< (int32 value) |
ByteBuffer & | operator<< (int64 value) |
ByteBuffer & | operator<< (float value) |
ByteBuffer & | operator<< (double value) |
ByteBuffer & | operator<< (const std::string &value) |
ByteBuffer & | operator<< (const char *value) |
ByteBuffer & | operator<< (const ByteBuffer &value) |
ByteBuffer & | operator>> (bool &value) |
ByteBuffer & | operator>> (uint8 &value) |
ByteBuffer & | operator>> (uint16 &value) |
ByteBuffer & | operator>> (uint32 &value) |
ByteBuffer & | operator>> (uint64 &value) |
ByteBuffer & | operator>> (int8 &value) |
ByteBuffer & | operator>> (int16 &value) |
ByteBuffer & | operator>> (int32 &value) |
ByteBuffer & | operator>> (int64 &value) |
ByteBuffer & | operator>> (float &value) |
ByteBuffer & | operator>> (double &value) |
ByteBuffer & | operator>> (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 > | |
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. | |
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.)
ByteBuffer::ByteBuffer | ( | uint32 | capacity | ) |
Constructor. capacity is a raw guess for the initial size of the buffer.
ByteBuffer::ByteBuffer | ( | const ByteBuffer & | other | ) |
Copy constructor.
|
protected |
|
protected |
|
protected |
|
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 | ) |
void ByteBuffer::Print | ( | std::ostream & | stream | ) | const |
Prints the buffer content in an user friendly way (both ascii and hex)
|
protected |
T ByteBuffer::Read | ( | uint32 | position | ) | const |
Read a value of type T at a given position.
|
protected |
|
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 | ( | ) |
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 | ) |
|
protected |
Underlying buffer of Bytes.
|
protected |
Current read position.
|
protected |
Current write position.