ImFusion SDK 4.3
ByteBufferView Class Reference

#include <ImFusion/Core/ByteBuffer.h>

Const view onto a sized buffer of raw binary data. More...

+ Inheritance diagram for ByteBufferView:

Detailed Description

Const view onto a sized buffer of raw binary data.

This class can be used to represent any kind of raw data independent of encoding or other limitations. For instance, in contrast to a std::string it can properly represents 0-bytes (\0) at any location. It annotates the raw buffer pointer with the size of the data and offers convenience functions.

This most base class of the ByteBuffer-class hierarchy that represents const read access to a contiguous buffer of raw bytes and can for instance be used as argument type for non-mutating processing functions. Two specializations of this class exist:

ByteBuffer(Mutable)View does not own the underlying buffer. All copies/assignments of a ByteBuffer(Mutable)View will be shallow and not copy the underlying buffer. However, comparison of multiple ByteBuffer(Views) will always perform a deep comparison of the underlying data in a byte-wise fashion independent of the concrete specialized type.

See also
ByteBufferStream
Examples
NetworkCommunication.cpp.

Public Member Functions

 ByteBufferView ()=default
 Create an empty (invalid) buffer.
 
 ByteBufferView (const char *data, size_t size)
 Create a non-owning buffer of the given size wrapping around the given array.
 
 ByteBufferView (const std::string &string)
 Create a new buffer referencing the content from string.
 
 ByteBufferView (std::string_view string)
 
 ByteBufferView (const ByteBufferView &rhs)=default
 
 ByteBufferView (ByteBufferView &&rhs) noexcept=default
 
ByteBufferViewoperator= (const ByteBufferView &rhs)=default
 
ByteBufferViewoperator= (ByteBufferView &&rhs) noexcept=default
 
const char & operator[] (size_t which) const
 
const char * data () const
 Return the pointer to the buffer data.
 
ByteSize size () const
 Return the number of bytes stored in the buffer.
 
std::string toString ()
 Copy the data to a new std::string.
 
std::string_view toStringView ()
 Create a std::string_view onto the underlying buffer.
 
bool isEmpty () const
 Check whether the buffer is empty.
 
ByteBuffer copy () const
 Create an owning deep copy of this buffer.
 
ByteBuffer subCopy (size_t offset, size_t size) const
 Create an owning deep copy of a subregion of this buffer.
 
ByteBufferView view () const
 Return a const view onto this buffer, same effect as calling the copy constructor.
 
ByteBufferView subView (size_t offset, size_t size) const
 Create a read-only view onto a subregion of this buffer.
 
const char * begin () const
 Return iterator to the beginning of the buffer.
 
const char * end () const
 Return iterator to one past the end of the buffer.
 
 ByteBufferView (ByteBuffer &&rhs)=delete
 
ByteBufferViewoperator= (ByteBuffer &&rhs)=delete
 

Protected Attributes

char * m_data = nullptr
 Raw pointer to the buffer data.
 
size_t m_size = 0
 Number of bytes stored in m_data.
 

Constructor & Destructor Documentation

◆ ByteBufferView()

ByteBufferView ( const char * data,
size_t size )
explicit

Create a non-owning buffer of the given size wrapping around the given array.

Note
data must remain valid for the entire lifetime of this object instance.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close