DataBuffer

Used to easily read a container of bytes

BufferWriter
BufferWriter

Class used to interface with a DataBuffer and append data to it

Functions
BufferWriter
BufferWriter(
uint8 *buffer,
std::size_t size,
std::size_t *offset
)

Constructor to create a BufferWriter object

Variables
m_buffer
uint8* m_buffer

The buffer to write to, at the specific position to start writing data

m_size
std::size_t m_size

The size available to write

m_writeOffset
std::size_t* m_writeOffset

A pointer to the current position to start writing in the buffer

Functions
buffer
uint8* buffer()

Gets the buffer to write to

Returns

The buffer to write to, as a byte reference

size
std::size_t size()

Gets the size of the buffer available to write

Returns

The size of the buffer available to write

commit
void commit(
std::size_t numBytesAdded
)

Commits a number of bytes that were added to the buffer by moving the current offset.

This function must be called after bytes are added to the buffer, or else they will be ignored as if they were never added.

Parameters
numBytesAdded
std::size_t

The number of bytes added to the buffer

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.

ReadBufferSavePoint
ReadBufferSavePoint

Acts as a save point so that bytes can be read out of a DataBuffer and the read point reverted

See Also

DataBuffer

Functions
ReadBufferSavePoint
ReadBufferSavePoint(
DataBuffer *data
)

Creates a ReadBufferSavePoint based on the DataBuffer passed in

Parameters
data

the data that will be updated or reverted

ReadBufferSavePoint
~ReadBufferSavePoint()

Destroying a ReadBufferSavePoint object, reverting any uncommited data

Variables
m_data
DataBuffer* m_data

The DataBuffer of data to be accessed

m_savePosition
std::size_t m_savePosition

The current save position in the DataBuffer

Functions
revert
void revert()

reverts the read position of the DataBuffer back to its saved position

commit
void commit()

commits all the currently read data so that it will not be reverted