qi::Buffer, qi::BufferReader¶
Summary¶
class qi::BufferReader
class qi::Buffer
Global Classes
Reference¶
qi::Buffer Class Reference¶
Public Functions¶
-
()Buffer -
(const Buffer& buffer)Buffer -
Buffer&
(const Buffer& buffer)operator= -
(Buffer&& buffer)Buffer -
Buffer&
(Buffer&& buffer)operator= -
bool
(const void* data, size_t size)write -
size_t
(const Buffer& buffer)addSubBuffer -
bool
(size_t offset) consthasSubBuffer -
const Buffer&
(size_t offset) constsubBuffer -
size_t
() constsize -
size_t
() consttotalSize -
const std::vector<std::pair<size_t, Buffer>>&
() constsubBuffers -
void*
(size_t size)reserve -
void
()clear -
void*
()data -
const void*
() constdata -
const void*
(size_t offset, size_t length) constread -
size_t
(void* buffer, size_t offset, size_t length) constread
Detailed Description¶
This class can store buffer and sub-buffers. Here is a representation of internal management of sub-buffers.
Function Documentation¶
-
qi::Buffer::Buffer()¶ Default constructor.
-
qi::Buffer::Buffer(const Buffer& buffer)¶ Brief: Copy constructor.
Parameters: - buffer – The buffer to copy.
As data are store as a shared pointer, the different copy of the same buffer all handle the same data.
-
Buffer&
qi::Buffer::operator=(const Buffer& buffer)¶ Brief: Assignment operator. As data are store as a shared pointer, the different copy of the same buffer all handle the same data.
Parameters: - buffer – The buffer to copy.
-
qi::Buffer::Buffer(Buffer&& buffer)¶ Brief: Move constructor. The moved-from buffer’s state is like a default constructed Buffer.
Parameters: - buffer – The buffer to move from.
-
Buffer&
qi::Buffer::operator=(Buffer&& buffer)¶ Brief: Move assignment operator. The moved-from buffer’s state is like a default constructed Buffer.
Parameters: - buffer – The buffer to move from.
-
bool
qi::Buffer::write(const void* data, size_t size)¶ Brief: Write data in the buffer.
Parameters: - data – The data to write
- size – The size of the data to write
Returns: true if operation succeeded, false otherwise.
-
size_t
qi::Buffer::addSubBuffer(const Buffer& buffer)¶ Brief: Add a sub-buffer to the main buffer. This function add a uint32_t for the size of sub-buffers in main buffer and add the buffer to the list of sub-buffers.
Parameters: - buffer – The buffer to have as sub-buffer.
Returns: return te offset at which sub-buffer have been added.
-
bool
qi::Buffer::hasSubBuffer(size_t offset)const¶ Brief: Check if there is a sub-buffer at given offset.
Parameters: - offset – The offset to look at the presence of sub-buffer.
Returns: true if there is a sub-buffer, false otherwise.
-
const Buffer&
qi::Buffer::subBuffer(size_t offset)const¶ Brief: Return the sub-buffer at given offset. If there is no sub-buffer throw a std::runtime_error.
Parameters: - offset – The offset to look for sub-buffer.
Returns: the sub-buffer.
-
size_t
qi::Buffer::size()const¶ Brief: Return the content size of this buffer not counting sub-buffers.
Returns: the size.
-
size_t
qi::Buffer::totalSize()const¶ Brief: Return the content size of this buffer and of all its sub-buffers.
Returns: the size.
-
const std::vector<std::pair<size_t, Buffer>>&
qi::Buffer::subBuffers()const¶ Brief: Return a vector of sub-buffers of the current buffer.
Returns: a vector of pairs. The first value of the pair is the offset of the sub-buffer into the master buffer. The second value is the sub-buffer itself.
-
void*
qi::Buffer::reserve(size_t size)¶ Brief: Reserve bytes at the end of current buffer.
Parameters: - size – number of new bytes to reserve at the end of buffer.
Returns: a pointer to the data.
-
void*
qi::Buffer::data()¶ Brief: Return a pointer to the raw data storage of this buffer.
Returns: the pointer to the data.
-
const void*
qi::Buffer::data()const¶ Brief: Return a const pointer to the raw data in this buffer.
Returns: the pointer to the data.
-
const void*
qi::Buffer::read(size_t offset = 0, size_t length = 0)const¶ Brief: Read some data from the buffer.
Parameters: - offset – offset at which reading begin in the buffer.
- length – length of the data to read.
Returns: 0 if the buffer is empty or if we try to read data after the end of the buffer. Otherwise return a pointer to the data. Only length bytes can be read in the returned buffer.
-
size_t
qi::Buffer::read(void* buffer, size_t offset = 0, size_t length = 0)const¶ Brief: Read some data in the buffer and store it in a new pre-allocated buffer.
Parameters: - buffer – the pre-allocated buffer to store data.
- offset – Offset in the current buffer to start copy.
- length – Length of the data to be copied.
Returns: -1 if there is no data in buffer or if offset is bigger than total data in buffer. Otherwise return the total length of copied data.
qi::BufferReader Class Reference¶
Introduction¶
Class to read const buffer. This class is intendeed to read buffer. It store an internal data cursor and an internal sub-buffer index. All offset are relative to the current position. More...
#include <qi/buffer.hpp>
Public Functions¶
-
(const Buffer& buf)BufferReader -
()~BufferReader -
size_t
(void* data, size_t length)read -
void*
(size_t offset)read -
bool
(size_t offset)seek -
void*
(size_t offset) constpeek -
bool
() consthasSubBuffer -
const Buffer&
()subBuffer -
size_t
() constposition
Detailed Description¶
Class to read const buffer. This class is intendeed to read buffer. It store an internal data cursor and an internal sub-buffer index. All offset are relative to the current position.
Function Documentation¶
-
qi::BufferReader::BufferReader(const Buffer& buf)¶ Brief: Constructor.
Parameters: - buf – The buffer to copy.
-
qi::BufferReader::~BufferReader()¶ Default destructor.
-
size_t
qi::BufferReader::read(void* data, size_t length)¶ Brief: read and store data from the buffer.
Parameters: - data – A pre-allocated pointer to store read data.
- length – Size of the object pointed by data or size to read.
Returns: size of really read and stored data.
-
void*
qi::BufferReader::read(size_t offset)¶ Brief: read data from buffer.
Parameters: - offset – Number of bytes to read.
Returns: a pointer to data at the given
-
bool
qi::BufferReader::seek(size_t offset)¶ Brief: Move forward the buffer cursor by the given offset.
Parameters: - offset – Value for move forward the cursor.
Returns: Return true if succeed, false otherwise.
-
void*
qi::BufferReader::peek(size_t offset)const¶ Brief: Check if we can read from the actual position toward offset bytes.
Parameters: - offset – The relative offset.
Returns: The pointer if it succeed. If actual position + offset exceed size of buffer return 0.
-
bool
qi::BufferReader::hasSubBuffer()const¶ Brief: Check if there is sub-buffer at the actual position.
Returns: true if there is sub-buffer, false otherwise.
-
const Buffer&
qi::BufferReader::subBuffer()¶ Brief: return the sub-buffer at the actual position. If there is no sub-buffer at actual position throw a std::runtime-error.
Returns: Return the sub-buffer if any.
-
size_t
qi::BufferReader::position()const¶ Brief: Return the actual position in the buffer.
Returns: The current offset.