DataBuffer
DataBuffer

A buffer of bytes extending from the ByteStream class that is used for holding bytes read in from the connection

See Also

ByteStream

Variables
m_data
ByteStream m_data

The underlying ByteStream that holds the data

m_appendPosition
std::size_t m_appendPosition

The current position to use when appending data to the buffer

m_readPosition
std::size_t m_readPosition

The current position in the buffer for reading data

Functions
DataBuffer
explicit DataBuffer(
uint32 size
)

Constructor to create a DataBuffer object

Parameters
size
uint32

The start and final size of the DataBuffer

DataBuffer
explicit DataBuffer(
const Bytes &data
)

Constructor to create a DataBuffer object given existing data as Bytes

Parameters
data
const Bytes&

a Bytes array containing existing data

DataBuffer
explicit DataBuffer(
const ByteStream &data
)

Constructor to create a DataBuffer given an existing ByteStream

Parameters
data
const ByteStream&

a ByteStream containing existing data

~DataBuffer
virtual ~DataBuffer()

Default destructor for the DataBuffer object

peekByte
uint8 peekByte()

Gets the next byte from the buffer without moving the read position

Returns

The next byte in the buffer, based on its current position

Exceptions
read_int8
int8 read_int8()

Reads the next 1-byte signed integer from the buffer

Returns

The next int8 in the buffer, based on its current position

Exceptions
read_uint8
uint8 read_uint8()

Reads the next 1-byte unsigned integer from the buffer

Returns

The next uint8 in the buffer, based on its current position

Exceptions
read_int16
int16 read_int16()

Reads the next 2-byte signed integer from the buffer

Returns

The next int16 in the buffer, based on its current position

Exceptions
read_uint16
uint16 read_uint16()

Reads the next 2-byte unsigned integer from the buffer

Returns

The next uint16 in the buffer, based on its current position

Exceptions
read_uint32
uint32 read_uint32()

Reads the next 4-byte unsigned integer from the buffer

Returns

The next uint32 in the buffer, based on its current position

Exceptions
read_float
float read_float()

Reads the next 4-byte float from the buffer

Returns

The next float in the buffer, based on its current position

Exceptions
read_double
double read_double()

Reads the next 8-byte double from the buffer

Returns

The next double in the buffer, based on its current position

Exceptions
read_string
std::string read_string(
std::size_t length
)

Reads a string of the specified length from the buffer

Parameters
length
std::size_t

The length (number of characters) of the string to read

Returns

The string of the specified length, starting from the current position in the buffer

Exceptions
size
std::size_t size() const

Gets the amount of bytes in the DataBuffer

Returns

The amount of bytes in the DataBuffer

bytesRemanining
Gets the remaining bytes available to read (append position

read position)

Returns

The remaining number of bytes available to read

appendPosition
std::size_t appendPosition() const

Gets the append position of the buffer.

Returns

The append position of the buffer.

readPosition
std::size_t readPosition() const

Gets the read position of the buffer.

Returns

The read position of the buffer.

moreToRead
bool moreToRead() const

Gets whether or not there are more bytes to be read in the DataBuffer

Returns

true if m_moreToRead is true, false otherwise

shiftExtraToStart
std::size_t shiftExtraToStart()

Copies any unparsed data in the DataBuffer to the front of the buffer.  Also resets the readPosition and moves the appendPosition to immediately after the data that was moved.

Returns

The number of bytes that were shifted.

getBufferWriter
BufferWriter getBufferWriter()

Creates a BufferWriter object based on this DataBuffer.

Returns

A BufferWriter object used to add data to this DataBuffer

resetBuffer
void resetBuffer()

Resets the append and read positions in the buffer back to 0.