A class that keeps ownership of a chain of linked DataBuffer references.
More...
#include <DataBuffer.hxx>
|
| void | clear () |
| | Internal helper function of constructors and reset functions.
|
| |
|
| DataBuffer * | head_ {nullptr} |
| | First buffer in the chain. This is the root of the ownership.
|
| |
| DataBuffer * | tail_ {nullptr} |
| | Last buffer in the chain. This is where we can extend the owned bytes.
|
| |
| size_t | size_ {0} |
| | How many bytes we have filled in (counting starts at head.data() + skip_).
|
| |
| uint16_t | skip_ {0} |
| | How many bytes to skip in the head buffer.
|
| |
| int16_t | free_ {0} |
| | If >= 0: How many free bytes are there in the tail buffer.
|
| |
A class that keeps ownership of a chain of linked DataBuffer references.
Definition at line 205 of file DataBuffer.hxx.
◆ LinkedDataBufferPtr() [1/3]
| LinkedDataBufferPtr::LinkedDataBufferPtr |
( |
| ) |
|
|
inline |
◆ ~LinkedDataBufferPtr()
| LinkedDataBufferPtr::~LinkedDataBufferPtr |
( |
| ) |
|
|
inline |
◆ LinkedDataBufferPtr() [2/3]
Move constructor. Takes the ownership that o has. Leaves o as empty.
Definition at line 221 of file DataBuffer.hxx.
◆ LinkedDataBufferPtr() [3/3]
We do not permit default copy operation.
Use the reset() function for that.
◆ append_empty_buffer()
| void LinkedDataBufferPtr::append_empty_buffer |
( |
DataBuffer * |
buf | ) |
|
|
inline |
Adds an empty buffer to the end of this buffer chain.
- Parameters
-
| buf | is a new, empty DataBuffer. Ownership will be taken. The size() value of it has to be denoting the amount of available bytes. |
Definition at line 311 of file DataBuffer.hxx.
◆ append_to()
| void LinkedDataBufferPtr::append_to |
( |
std::string * |
recvd | ) |
const |
|
inline |
Appends all content in this buffer to an std::string.
- Parameters
-
| recvd | string to append data to. |
Definition at line 509 of file DataBuffer.hxx.
◆ clear()
| void LinkedDataBufferPtr::clear |
( |
| ) |
|
|
inlineprivate |
Internal helper function of constructors and reset functions.
Clears the current structure (references have to have been dealt with before).
Definition at line 616 of file DataBuffer.hxx.
◆ data_read_advance()
| void LinkedDataBufferPtr::data_read_advance |
( |
size_t |
len | ) |
|
|
inline |
Advances the head pointer.
Typically used after a successful read happened.
- Parameters
-
| len | how many bytes to advance the read pointer. |
Definition at line 397 of file DataBuffer.hxx.
◆ data_read_pointer()
| const uint8_t * LinkedDataBufferPtr::data_read_pointer |
( |
size_t * |
len | ) |
|
|
inline |
Retrieves a pointer where data can be read out of the buffer.
- Parameters
-
| len | will be filled in with the number of available bytes to read at this point. |
- Returns
- the read pointer, or nullptr if there is no data in this buffer.
Definition at line 376 of file DataBuffer.hxx.
◆ data_write_advance()
| void LinkedDataBufferPtr::data_write_advance |
( |
size_t |
len | ) |
|
|
inline |
Advances the tail pointer after a write occurred into the tail.
- Parameters
-
Definition at line 363 of file DataBuffer.hxx.
◆ data_write_pointer()
| uint8_t * LinkedDataBufferPtr::data_write_pointer |
( |
| ) |
|
|
inline |
- Returns
- the pointer where data can be appended into the tail of this buffer chain. Use free() to know how many bytes can be written here.
Definition at line 351 of file DataBuffer.hxx.
◆ free()
| size_t LinkedDataBufferPtr::free |
( |
| ) |
const |
|
inline |
◆ head()
◆ operator=()
Move assignment operator.
Takes the ownership that o has. Leaves o as empty.
Definition at line 233 of file DataBuffer.hxx.
◆ reset() [1/4]
| void LinkedDataBufferPtr::reset |
( |
| ) |
|
|
inline |
Deallocates the current content (by releasing the references).
Definition at line 333 of file DataBuffer.hxx.
◆ reset() [2/4]
Takes a reference of o, taking a prefix of len size (or all the data).
The current buffer becomes non-extensible.
- Parameters
-
| o | an owned LinkedDataBufferPtr |
| size | is non-negative, this is how many bytes from the beginning of o will be copied. If default (negative), takes all bytes that are filled. |
Definition at line 255 of file DataBuffer.hxx.
◆ reset() [3/4]
| void LinkedDataBufferPtr::reset |
( |
DataBuffer * |
buf | ) |
|
|
inline |
Clears the current contents and replaces it with the empty buf.
- Parameters
-
| buf | is a new, empty DataBuffer. Ownership will be taken. The size() value of it has to be denoting the amount of available bytes. |
Definition at line 283 of file DataBuffer.hxx.
◆ reset() [4/4]
| void LinkedDataBufferPtr::reset |
( |
DataBuffer * |
buf, |
|
|
unsigned |
skip, |
|
|
unsigned |
size |
|
) |
| |
|
inline |
Set to a single data buffer.
- Parameters
-
| buf | is a filled-in data buffer. Takes ownership. Must be a single (non-chained) buffer. |
| skip | how many bytes to skip at the beginning |
| size | how many bytes to take after skip bytes. |
Definition at line 298 of file DataBuffer.hxx.
◆ size()
| unsigned LinkedDataBufferPtr::size |
( |
| ) |
const |
|
inline |
- Returns
- how many bytes are filled in the current buffer.
Definition at line 451 of file DataBuffer.hxx.
◆ skip()
| unsigned LinkedDataBufferPtr::skip |
( |
| ) |
const |
|
inline |
- Returns
- how many bytes to skip from the head buffer.
Definition at line 445 of file DataBuffer.hxx.
◆ tail()
◆ transfer_head()
Transfers the ownership of the prefix of this buffer.
The tail will remain in the current buffer chain as an extra reference. Any free space in the tail will also remain in the current bufferptr.
- Parameters
-
| len | how many bytes at the beginning (starting at skip_) to transfer. Must reach into the tail buffer, meaning that at least one byte from the tail buffer must be transferred. |
- Returns
- a new (moveable) LinkedDataBufferPtr that will get the ownership of the head. It will be non-extendible.
Definition at line 475 of file DataBuffer.hxx.
◆ try_append_from()
Attempt to combine *this with o into a single LinkedDataBufferPtr this.
This tries to do *this += o. It will succeed if o.head() == this->tail() and the bytes in these buffers are back to back.
- Parameters
-
| o | a LinkedDataBuffer with data payload. |
| add_link | creates a tail-to-head link if none exist yet between *this and o.head_. This is fundamentally dangerous, do it only if there is no shared ownership of this->tail_. |
- Returns
- true if append succeeded. If false, nothing was changed.
Definition at line 538 of file DataBuffer.hxx.
◆ free_
| int16_t LinkedDataBufferPtr::free_ {0} |
|
private |
If >= 0: How many free bytes are there in the tail buffer.
If < 0: non-appendable buffer, the -offset of the first byte in the tail buffer that's after the payload. In other words, -1 * the skip() of the next linked buffer. In other words, -1 * the end pointer in the tail buffer.
Definition at line 635 of file DataBuffer.hxx.
◆ head_
First buffer in the chain. This is the root of the ownership.
Definition at line 623 of file DataBuffer.hxx.
◆ size_
| size_t LinkedDataBufferPtr::size_ {0} |
|
private |
How many bytes we have filled in (counting starts at head.data() + skip_).
Definition at line 628 of file DataBuffer.hxx.
◆ skip_
| uint16_t LinkedDataBufferPtr::skip_ {0} |
|
private |
How many bytes to skip in the head buffer.
Definition at line 630 of file DataBuffer.hxx.
◆ tail_
Last buffer in the chain. This is where we can extend the owned bytes.
Definition at line 625 of file DataBuffer.hxx.
The documentation for this class was generated from the following file: