A buffer class that efficiently represents a composite buffer with three sections:
More...
|
| | PacketBuffer ()=default |
| |
| | PacketBuffer (const PacketBuffer &)=delete |
| |
| PacketBuffer & | operator= (const PacketBuffer &)=delete |
| |
| | PacketBuffer (PacketBuffer &&)=default |
| |
| PacketBuffer & | operator= (PacketBuffer &&)=default |
| |
| | PacketBuffer (const uint8_t *data, size_t length) |
| | Construct from a single buffer.
|
| |
| | PacketBuffer (const std::vector< uint8_t > &vec) |
| | Construct from a vector.
|
| |
| | PacketBuffer (std::vector< uint8_t > &&)=delete |
| |
| | PacketBuffer (const uint8_t *pre_data, size_t pre_length, const uint8_t *post_data, size_t post_length) |
| | Construct with pre and post buffers.
|
| |
| | PacketBuffer (const uint8_t *pre_data, size_t pre_length, const PacketBuffer *mid_buffer, const uint8_t *post_data, size_t post_length) |
| | Construct with pre, mid, and post buffers.
|
| |
| size_t | size () const |
| | Get the total size of the buffer.
|
| |
| bool | empty () const |
| | Check if the buffer is empty.
|
| |
| bool | is_contiguous () const |
| | Check if all the data is held in the pre-buffer, so it can be read as one span.
|
| |
| std::span< const uint8_t > | as_span () const |
| | Get the data as one span.
|
| |
| uint8_t | operator[] (size_t index) const |
| | Access a byte at a specific position.
|
| |
| size_t | copy_to (uint8_t *dest, size_t count, size_t offset=0) const |
| | Copy data from the buffer to a destination pointer.
|
| |
A buffer class that efficiently represents a composite buffer with three sections:
- pre_buffer: A pointer to uint8_t data with a length
- mid_buffer: A reference to another PacketBuffer (optional)
- post_buffer: A pointer to uint8_t data with a length
This allows efficient zero-copy composition of buffers without allocating new memory.
WARNING: PacketBuffer holds raw pointers to data. The user must ensure that the data remains valid for the lifetime of the PacketBuffer instance. Storing PacketBuffer instances beyond the scope of the data they reference will lead to dangling pointers and undefined behavior, so to keep a packet, copy it with copy_to() into a buffer allocated in setup().
Definition at line 24 of file packet_buffer.h.