#include <ByteBuffer.h>

The class is not meant to be subclassed by library users, but it needs to be documented publicly so you can use its methods in its subclasses.
ByteBuffer maintains a current offset into the buffer where reads and writes will start. The offset is not updated when the buffer is resized.
Definition at line 44 of file ByteBuffer.h.
Public Types | |
| typedef char | value_type |
| typedef value_type & | reference |
| typedef const reference | const_reference |
| typedef value_type * | pointer |
| typedef const pointer | const_pointer |
Public Member Functions | |
| ByteBuffer (const unsigned int capacity) | |
| Creates a buffer with the specified capacity and sets its size and offset to zero. | |
| ByteBuffer (const ByteBuffer &buffer) | |
| Creates a copy of a ByteBuffer, including its contents, its read/write position, size, and its capacity. | |
| ByteBuffer & | operator= (const ByteBuffer &buffer) |
| Copies the contents of a ByteBuffer, its read/write position, and its size, but does not necessarily copy its capacity. | |
| unsigned int | offset () const throw () |
| Returns the current read/write position. | |
| unsigned int | seek (const unsigned int offset) |
| Sets the read/write position to the specified value if the value is less than or equal to the size of the buffer. | |
| void | rewind () |
| Same as seek(0). | |
| void | clear () |
| Rewinds the read/write position befor resizing the buffer to zero. | |
| void | write (const void *data, const unsigned int size) |
| Writes the specified number of bytes from the provided data into the buffer at the current read/write position. | |
| unsigned int | read (void *data, unsigned int size) |
| Reads the specified number of bytes from the buffer into the provided destination starting from the current read/write position. | |
| unsigned int | capacity () const throw () |
| Returns the maximum number of elements that can be written to the buffer without reallocating memory. | |
| reference | operator[] (const unsigned int index) |
| Returns the element at the specified index. | |
| const_reference | operator[] (const unsigned int index) const |
| Returns the element at the specified index. | |
| void | reserve (const unsigned int capacity) |
| Increases the buffer capacity to the specified size. | |
| void | resize (const unsigned int size) |
| Resizes the buffer to the specified size. | |
| unsigned int | size () const throw () |
| Returns the number of elements contained in the buffer. | |
| void | add (const char &value) |
| Appends a value to the end of the buffer and increments the size by one. | |
typedef char sava::spread::detail::Buffer< char >::value_type [inherited] |
typedef value_type& sava::spread::detail::Buffer< char >::reference [inherited] |
typedef const reference sava::spread::detail::Buffer< char >::const_reference [inherited] |
typedef value_type* sava::spread::detail::Buffer< char >::pointer [inherited] |
typedef const pointer sava::spread::detail::Buffer< char >::const_pointer [inherited] |
| sava::spread::detail::ByteBuffer::ByteBuffer | ( | const unsigned int | capacity | ) | [inline, explicit] |
Creates a buffer with the specified capacity and sets its size and offset to zero.
| capacity | The initial capacity of the buffer. |
Definition at line 57 of file ByteBuffer.h.
| sava::spread::detail::ByteBuffer::ByteBuffer | ( | const ByteBuffer & | buffer | ) | [inline] |
Creates a copy of a ByteBuffer, including its contents, its read/write position, size, and its capacity.
| buffer | The ByteBuffer to copy. |
Definition at line 67 of file ByteBuffer.h.
References sava::spread::detail::Buffer< type >::capacity(), offset(), and sava::spread::detail::Buffer< type >::size().
| ByteBuffer& sava::spread::detail::ByteBuffer::operator= | ( | const ByteBuffer & | buffer | ) | [inline] |
Copies the contents of a ByteBuffer, its read/write position, and its size, but does not necessarily copy its capacity.
| buffer | The ByteBuffer to copy. |
Definition at line 80 of file ByteBuffer.h.
References offset(), and sava::spread::detail::Buffer< type >::size().
| unsigned int sava::spread::detail::ByteBuffer::offset | ( | ) | const throw () [inline] |
Returns the current read/write position.
Definition at line 94 of file ByteBuffer.h.
Referenced by ByteBuffer(), and operator=().
| unsigned int sava::spread::detail::ByteBuffer::seek | ( | const unsigned int | offset | ) | [inline] |
Sets the read/write position to the specified value if the value is less than or equal to the size of the buffer.
Otherwise, the current offset is left unchanged.
| offset | The buffer offset of the new read/write position. |
Definition at line 106 of file ByteBuffer.h.
| void sava::spread::detail::ByteBuffer::rewind | ( | ) | [inline] |
| void sava::spread::detail::ByteBuffer::clear | ( | ) | [inline] |
Rewinds the read/write position befor resizing the buffer to zero.
Reimplemented from sava::spread::detail::Buffer< char >.
Reimplemented in sava::spread::Message.
Definition at line 120 of file ByteBuffer.h.
| void sava::spread::detail::ByteBuffer::write | ( | const void * | data, | |
| const unsigned int | size | |||
| ) | [inline] |
Writes the specified number of bytes from the provided data into the buffer at the current read/write position.
If the buffer is not large enough to hold the data, it is resized automatically to the current offset plus the size of the data to be written. After writing the data, the read/write position is incremented by the size of the data written.
| data | A pointer to the data to be written. | |
| size | The number of bytes to write. |
Definition at line 136 of file ByteBuffer.h.
| unsigned int sava::spread::detail::ByteBuffer::read | ( | void * | data, | |
| unsigned int | size | |||
| ) | [inline] |
Reads the specified number of bytes from the buffer into the provided destination starting from the current read/write position.
If the number of bytes to be read would result in running off the end of the buffer, the read is truncated at the end of the buffer.
| data | A pointer to the read destination. | |
| size | The number of bytes to read. |
Definition at line 158 of file ByteBuffer.h.
| unsigned int sava::spread::detail::Buffer< char >::capacity | ( | ) | const throw () [inline, inherited] |
| reference sava::spread::detail::Buffer< char >::operator[] | ( | const unsigned int | index | ) | [inline, inherited] |
| const_reference sava::spread::detail::Buffer< char >::operator[] | ( | const unsigned int | index | ) | const [inline, inherited] |
| void sava::spread::detail::Buffer< char >::reserve | ( | const unsigned int | capacity | ) | [inline, inherited] |
Increases the buffer capacity to the specified size.
If the new size is less than or equal to the buffer capacity, no action is performed. If the size is greater than the capacity, new memory is reserved, increasing the capacity while preserving the existing buffer contents.
| capacity | The new buffer capacity. |
| void sava::spread::detail::Buffer< char >::resize | ( | const unsigned int | size | ) | [inline, inherited] |
Resizes the buffer to the specified size.
If the new size is less than or equal to the buffer capacity, the size is simply set to the new value. If the size is greater than the capacity, new memory is reserved—preserving the existing buffer contents—before setting the size to the new value.
| size | The new buffer size. |
| unsigned int sava::spread::detail::Buffer< char >::size | ( | ) | const throw () [inline, inherited] |
Returns the number of elements contained in the buffer.
Reimplemented in sava::spread::Message.
| void sava::spread::detail::Buffer< char >::add | ( | const char & | value | ) | [inline, inherited] |
Appends a value to the end of the buffer and increments the size by one.
If the buffer is at full capacity, its capacity is increased to be able to hold more data. Currently, this is done by doubling the current capacity, but you should not rely on that behavior.
| value | The value to append to the buffer. |