libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
BufferView Class Reference

Lightweight view into a region of a shared Buffer. More...

#include <bufferview.h>

Inheritance diagram for BufferView:

Public Types

using List = promeki::List< BufferView >
 List of BufferView values.
 

Public Member Functions

 BufferView ()=default
 Default constructor. Creates an empty view with no buffer.
 
 BufferView (Buffer::Ptr buf, size_t offset, size_t size)
 Constructs a BufferView referencing a region of a shared buffer.
 
const Buffer::Ptrbuffer () const
 Returns the shared backing buffer.
 
size_t offset () const
 Returns the byte offset into the buffer.
 
size_t size () const
 Returns the byte size of this view.
 
const uint8_tdata () const
 Returns a const pointer to this view's data.
 
uint8_tdata ()
 Returns a mutable pointer to this view's data.
 
bool isNull () const
 Returns true if no buffer is set.
 
bool isValid () const
 Returns true if a buffer is set.
 

Detailed Description

Lightweight view into a region of a shared Buffer.

BufferView is a simple value type that references a contiguous region (offset + size) of a shared Buffer. Multiple BufferViews can reference different regions of the same underlying Buffer::Ptr, avoiding per-view allocation when slicing large buffers into smaller pieces.

Common uses include RTP packet fragmentation, scatter/gather I/O, and any scenario where a large buffer is logically divided into sub-regions without copying data.

Example
auto buf = Buffer::Ptr::create(65536);
BufferView view1(buf, 0, 1400);
BufferView view2(buf, 1400, 1400);
// Both views share the same buffer
CHECK(view1.buffer().ptr() == view2.buffer().ptr());
CHECK(view1.data() != view2.data());
Lightweight view into a region of a shared Buffer.
Definition bufferview.h:41
promeki::List< BufferView > List
List of BufferView values.
Definition bufferview.h:44

Constructor & Destructor Documentation

◆ BufferView()

BufferView::BufferView ( Buffer::Ptr  buf,
size_t  offset,
size_t  size 
)
inline

Constructs a BufferView referencing a region of a shared buffer.

Parameters
bufThe shared backing buffer.
offsetByte offset into the buffer where this view begins.
sizeByte size of this view.
Note
The caller must ensure that offset + size does not exceed the buffer's allocated size. No bounds checking is performed.

Member Function Documentation

◆ data() [1/2]

uint8_t * BufferView::data ( )
inline

Returns a mutable pointer to this view's data.

Returns
Pointer to the data, or nullptr if no buffer is set.

◆ data() [2/2]

const uint8_t * BufferView::data ( ) const
inline

Returns a const pointer to this view's data.

Returns
Pointer to the data, or nullptr if no buffer is set.

The documentation for this class was generated from the following file: