RAVENNAKIT
Loading...
Searching...
No Matches
rav::InputStreamView Class Reference

A non-owning view of some data that can be read from. More...

#include <input_stream_view.hpp>

Inheritance diagram for rav::InputStreamView:
rav::InputStream

Public Member Functions

 InputStreamView (const uint8_t *data, size_t size)
 Constructs a new input stream view pointing to the given data.
template<class T>
 InputStreamView (const T &container)
 Constructs a new input stream view pointing to the given container.
 ~InputStreamView () override=default
 InputStreamView (const InputStreamView &)=default
InputStreamView & operator= (const InputStreamView &)=default
 InputStreamView (InputStreamView &&) noexcept=default
InputStreamView & operator= (InputStreamView &&) noexcept=default
void reset ()
 Resets the stream to its initial state by setting the read position to 0.
tl::expected< size_t, Error > read (uint8_t *buffer, size_t size) override
 Reads data from the stream into the given buffer.
bool set_read_position (size_t position) override
 Sets the read position in the stream.
size_t get_read_position () override
std::optional< size_t > size () const override
bool exhausted () override
Public Member Functions inherited from rav::InputStream
 InputStream ()=default
virtual ~InputStream ()=default
std::optional< size_t > remaining ()
bool skip (size_t size)
 Skips size amount of bytes in the stream.
tl::expected< std::string, Error > read_as_string (size_t size)
 Reads size amount of bytes from the stream and returns it as a string.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > read_ne ()
 Reads a value from the given stream in native byte order (not to be confused with network-endian).
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > read_be ()
 Reads a big-endian value from the given stream.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > read_le ()
 Reads a little-endian value from the given stream.

Additional Inherited Members

Public Types inherited from rav::InputStream
enum class  Error { insufficient_data , failed_to_set_read_position }
Static Public Member Functions inherited from rav::InputStream
static const char * to_string (const Error e)

Detailed Description

A non-owning view of some data that can be read from.

Definition at line 34 of file input_stream_view.hpp.

Constructor & Destructor Documentation

◆ InputStreamView() [1/4]

rav::InputStreamView::InputStreamView ( const uint8_t * data,
size_t size )

Constructs a new input stream view pointing to the given data.

It doesn't take ownership of the data so make sure that the data outlives the stream.

Parameters
dataThe data to read from. Must not be nullptr.
sizeThe size of the data.

◆ InputStreamView() [2/4]

template<class T>
rav::InputStreamView::InputStreamView ( const T & container)
inlineexplicit

Constructs a new input stream view pointing to the given container.

It doesn't take ownership of the container so make sure that the container outlives the stream.

Template Parameters
TThe container type.
Parameters
containerThe container to read from. Must not be empty.

Definition at line 51 of file input_stream_view.hpp.

◆ ~InputStreamView()

rav::InputStreamView::~InputStreamView ( )
overridedefault

◆ InputStreamView() [3/4]

rav::InputStreamView::InputStreamView ( const InputStreamView & )
default

◆ InputStreamView() [4/4]

rav::InputStreamView::InputStreamView ( InputStreamView && )
defaultnoexcept

Member Function Documentation

◆ exhausted()

bool rav::InputStreamView::exhausted ( )
nodiscardoverridevirtual
Returns
True if the stream has no more data to read.

Implements rav::InputStream.

◆ get_read_position()

size_t rav::InputStreamView::get_read_position ( )
nodiscardoverridevirtual
Returns
The current read position in the stream.

Implements rav::InputStream.

◆ operator=() [1/2]

InputStreamView & rav::InputStreamView::operator= ( const InputStreamView & )
default

◆ operator=() [2/2]

InputStreamView & rav::InputStreamView::operator= ( InputStreamView && )
defaultnoexcept

◆ read()

tl::expected< size_t, Error > rav::InputStreamView::read ( uint8_t * buffer,
size_t size )
nodiscardoverridevirtual

Reads data from the stream into the given buffer.

If the stream doesn't have enough data, then nothing will be read.

Parameters
bufferThe buffer to read data into.
sizeThe number of bytes to read.
Returns
The number of bytes read.

Implements rav::InputStream.

◆ reset()

void rav::InputStreamView::reset ( )

Resets the stream to its initial state by setting the read position to 0.

◆ set_read_position()

bool rav::InputStreamView::set_read_position ( size_t position)
nodiscardoverridevirtual

Sets the read position in the stream.

Parameters
positionThe new read position.
Returns
True if the read position was successfully set.

Implements rav::InputStream.

◆ size()

std::optional< size_t > rav::InputStreamView::size ( ) const
nodiscardoverridevirtual
Returns
The total number of bytes in this stream. Not all streams support this operation, in which case an empty optional is returned.

Implements rav::InputStream.


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