libfilezilla
Public Member Functions | List of all members
nonowning_buffer Class Referencefinal

Similar to fz::buffer, but does not own memory. More...

#include <nonowning_buffer.hpp>

Public Member Functions

 nonowning_buffer (uint8_t *buffer, size_t capacity) noexcept
 
 nonowning_buffer (uint8_t *buffer, size_t capacity, size_t size) noexcept
 
 nonowning_buffer (nonowning_buffer const &)=default
 
nonowning_bufferoperator= (nonowning_buffer const &)=default
 
 nonowning_buffer (nonowning_buffer &&) noexcept=default
 
nonowning_bufferoperator= (nonowning_buffer &&) noexcept=default
 
size_t capacity () const
 
size_t size () const
 
bool empty () const
 
 operator bool () const
 
void resize (size_t size)
 Resizes the buffer. More...
 
void clear ()
 
uint8_t operator[] (size_t offset)
 Gets element at offset. No safety check.
 
uint8_t const * get () const
 Gets buffer.
 
uint8_t * get ()
 
uint8_t * get (size_t bytes)
 Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done. More...
 
void add (size_t bytes)
 Grows size by passed amount. More...
 
void consume (size_t bytes)
 Removes consumed bytes from the beginning of the buffer. More...
 
void reset ()
 
void append (uint8_t const *data, size_t len)
 
void append (uint8_t c)
 
std::string_view to_view () const
 

Detailed Description

Similar to fz::buffer, but does not own memory.

Needs to be created with a fixed range of memory owned elsewhere. This memory range needs to remain valid for the lifetime of nonowning_buffer. While nonowning_buffer can change in size, it cannot grow past the size of the passed memory.

Note that copying nonowning_buffer is shallow.

Member Function Documentation

◆ add()

void add ( size_t  bytes)

Grows size by passed amount.

Aborts if new size is larger than capacity.

◆ consume()

void consume ( size_t  bytes)

Removes consumed bytes from the beginning of the buffer.

Undefined if consumed > size()

◆ get()

uint8_t* get ( size_t  bytes)

Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done.

The returned pointer is pointing just after the data already stored in the buffer.

Calling this function does not does not affect size().

Aborts if requested size is larger than capacity.

◆ resize()

void resize ( size_t  size)

Resizes the buffer.

If growing, memory isn't cleared. Aborts if size exceeds capacity.


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