Class to represent scattered memory buffers and in-order segments of that buffered data. More...
#include <llbuffer.h>
Public Member Functions | |
LLBufferArray () | |
bool | append (S32 channel, const U8 *src, S32 len) |
Put data on a channel at the end of this buffer array. | |
S32 | capacity () const |
Return the sum of all allocated bytes. | |
S32 | count (S32 channel) const |
Count all bytes on channel. | |
S32 | countAfter (S32 channel, U8 *start) const |
Count bytes in the buffer array on the specified channel. | |
bool | insertAfter (segment_iterator_t segment, S32 channel, const U8 *src, S32 len) |
Insert data into a buffer array after a particular segment. | |
bool | prepend (S32 channel, const U8 *src, S32 len) |
Put data on a channel at the front of this buffer array. | |
U8 * | readAfter (S32 channel, U8 *start, U8 *dest, S32 &len) const |
Read bytes in the buffer array on the specified channel. | |
U8 * | seek (S32 channel, U8 *start, S32 delta) const |
Find an address in a buffer array. | |
segment_iterator_t | beginSegment () |
Get the first segment in the buffer array. | |
segment_iterator_t | constructSegmentAfter (U8 *address, LLSegment &segment) |
Get a segment iterator after address, and a constructed segment to represent the next linear block of memory. | |
segment_iterator_t | endSegment () |
Get the one-past-the-end segment in the buffer array. | |
bool | eraseSegment (const segment_iterator_t &iter) |
Erase the segment if it is in the buffer array. | |
segment_iterator_t | getSegment (U8 *address) |
Get the segment which holds the given address. | |
const_segment_iterator_t | getSegment (U8 *address) const |
Get the segment which holds the given address. | |
segment_iterator_t | makeSegment (S32 channel, S32 length) |
Make a new segment at the end of buffer array. | |
segment_iterator_t | splitAfter (U8 *address) |
Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel. | |
bool | takeContents (LLBufferArray &source) |
Take the contents of another buffer array. | |
Protected Member Functions | |
bool | copyIntoBuffers (S32 channel, const U8 *src, S32 len, std::vector< LLSegment > &segments) |
Optimally put data in buffers, and reutrn segments. | |
| |
LLChannelDescriptors | nextChannel () |
Generate the next channel descriptor for this buffer array. | |
static LLChannelDescriptors | makeChannelConsumer (const LLChannelDescriptors &channels) |
Generate the a channel descriptor which consumes the output for the channel passed in. |
Class to represent scattered memory buffers and in-order segments of that buffered data.
*NOTE: This class needs to have an iovec interface
LLBufferArray::LLBufferArray | ( | ) |
bool LLBufferArray::append | ( | S32 | channel, | |
const U8 * | src, | |||
S32 | len | |||
) |
Put data on a channel at the end of this buffer array.
The data is copied from src into the buffer array. At least one new segment is created and put on the end of the array. This object will internally allocate new buffers if necessary.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
LLBufferArray::segment_iterator_t LLBufferArray::beginSegment | ( | ) |
Get the first segment in the buffer array.
LLBufferArray::segment_iterator_t LLBufferArray::constructSegmentAfter | ( | U8 * | address, | |
LLSegment & | segment | |||
) |
Get a segment iterator after address, and a constructed segment to represent the next linear block of memory.
This method is a helper by giving you the largest segment possible in the out-value param after the address provided. The iterator will be useful for iteration, while the segment can be used for direct access to memory after address if the return values isnot end. Passing in NULL will return beginSegment() which may be endSegment(). The segment returned will only be zero length if the return value equals end. This is really just a helper method, since all the information returned could be constructed through other methods.
address | An address in the middle of the sought segment. | |
segment[out] | segment to be used for reading or writing |
bool LLBufferArray::copyIntoBuffers | ( | S32 | channel, | |
const U8 * | src, | |||
S32 | len, | |||
std::vector< LLSegment > & | segments | |||
) | [protected] |
Optimally put data in buffers, and reutrn segments.
This is an internal function used to create buffers as necessary, and sequence the segments appropriately for the various ways to copy data from src into this. If this method fails, it may actually leak some space inside buffers, but I am not too worried about the slim possibility that we may have some 'dead' space which will be recovered when the buffer (which we will not lose) is deleted. Addressing this weakness will make the buffers almost as complex as a general memory management system.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy | |
segments | Out-value for the segments created. |
S32 LLBufferArray::count | ( | S32 | channel | ) | const [inline] |
Count all bytes on channel.
Helper method which just calls countAfter().
channel | The channel to count. |
S32 LLBufferArray::countAfter | ( | S32 | channel, | |
U8 * | start | |||
) | const |
Count bytes in the buffer array on the specified channel.
channel | The channel to count. | |
start | The start address in the array for counting. You can specify NULL to start at the beginning. |
LLBufferArray::segment_iterator_t LLBufferArray::endSegment | ( | ) |
Get the one-past-the-end segment in the buffer array.
bool LLBufferArray::eraseSegment | ( | const segment_iterator_t & | iter | ) |
Erase the segment if it is in the buffer array.
iter | An iterator referring to the segment to erase. |
LLBufferArray::segment_iterator_t LLBufferArray::getSegment | ( | U8 * | address | ) |
Get the segment which holds the given address.
As opposed to some methods, passing a NULL will result in returning the end segment.
address | An address in the middle of the sought segment. |
LLBufferArray::const_segment_iterator_t LLBufferArray::getSegment | ( | U8 * | address | ) | const |
Get the segment which holds the given address.
As opposed to some methods, passing a NULL will result in returning the end segment.
address | An address in the middle of the sought segment. |
bool LLBufferArray::insertAfter | ( | segment_iterator_t | segment, | |
S32 | channel, | |||
const U8 * | src, | |||
S32 | len | |||
) |
Insert data into a buffer array after a particular segment.
The data is copied from src into the buffer array. At least one new segment is created and put in the array. This object will internally allocate new buffers if necessary.
segment | The segment in front of the new segments location | |
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
LLBufferArray::segment_iterator_t LLBufferArray::makeSegment | ( | S32 | channel, | |
S32 | length | |||
) |
Make a new segment at the end of buffer array.
This method will attempt to create a new and empty segment of the specified length. The segment created may be shorter than requested.
channel[in] | The channel for the newly created segment. | |
length[in] | The requested length of the segment. |
LLChannelDescriptors LLBufferArray::nextChannel | ( | ) |
Generate the next channel descriptor for this buffer array.
The channel descriptor interface is how the buffer array clients can know where to read and write data. Use this interface to get the 'next' channel set for usage. This is a bit of a simple hack until it's utility indicates it should be extended.
bool LLBufferArray::prepend | ( | S32 | channel, | |
const U8 * | src, | |||
S32 | len | |||
) |
Put data on a channel at the front of this buffer array.
The data is copied from src into the buffer array. At least one new segment is created and put in the front of the array. This object will internally allocate new buffers if necessary.
channel | The channel for this data | |
src | The start of memory for the data to be copied | |
len | The number of bytes of data to copy |
U8 * LLBufferArray::readAfter | ( | S32 | channel, | |
U8 * | start, | |||
U8 * | dest, | |||
S32 & | len | |||
) | const |
Read bytes in the buffer array on the specified channel.
You should prefer iterating over segments is possible since this method requires you to allocate large buffers - precisely what this class is trying to prevent. This method will skip any segments which are not on the given channel, so this method would usually be used to read a channel and copy that to a log or a socket buffer or something.
channel | The channel to read. | |
start | The start address in the array for reading. You can specify NULL to start at the beginning. | |
dest | The destination of the data read. This must be at least len bytes long. | |
len[in,out] | in How many bytes to read. out How many bytes were read. |
U8 * LLBufferArray::seek | ( | S32 | channel, | |
U8 * | start, | |||
S32 | delta | |||
) | const |
Find an address in a buffer array.
channel | The channel to seek in. | |
start | The start address in the array for the seek operation. You can specify NULL to start the seek at the beginning, or pass in npos to start at the end. | |
delta | How many bytes to seek through the array. |
LLBufferArray::segment_iterator_t LLBufferArray::splitAfter | ( | U8 * | address | ) |
Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel.
After this method call, getLastSegmentAddress(*getSegment(address)) == address
should be true. This call will only create a new segment if the statement above is false before the call. Since you usually call splitAfter() to change a segment property, use getSegment() to perform those operations.
address | The address which will become the last address of the segment it is in. |
address
which is endSegment()
on failure. bool LLBufferArray::takeContents | ( | LLBufferArray & | source | ) |
Take the contents of another buffer array.
This method simply strips the contents out of the source buffery array - segments, buffers, etc, and appends them to this instance. After this operation, the source is empty and ready for reuse.
source | The source buffer |