RAVENNAKIT
Loading...
Searching...
No Matches
rav::InputStream Class Referenceabstract

Baseclass for classes that want to provide stream-like access to data. More...

#include <input_stream.hpp>

Inheritance diagram for rav::InputStream:
rav::ByteStream rav::FileInputStream rav::InputStreamView

Public Types

enum class  Error { insufficient_data , failed_to_set_read_position }

Public Member Functions

 InputStream ()=default
virtual ~InputStream ()=default
virtual tl::expected< size_t, Error > read (uint8_t *buffer, size_t size)=0
 Reads data from the stream into the given buffer.
virtual bool set_read_position (size_t position)=0
 Sets the read position in the stream.
virtual size_t get_read_position ()=0
virtual std::optional< size_t > size () const =0
std::optional< size_t > remaining ()
virtual bool exhausted ()=0
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.

Static Public Member Functions

static const char * to_string (const Error e)

Detailed Description

Baseclass for classes that want to provide stream-like access to data.

Definition at line 39 of file input_stream.hpp.

Member Enumeration Documentation

◆ Error

enum class rav::InputStream::Error
strong
Enumerator
insufficient_data 
failed_to_set_read_position 

Definition at line 41 of file input_stream.hpp.

Constructor & Destructor Documentation

◆ InputStream()

rav::InputStream::InputStream ( )
default

◆ ~InputStream()

virtual rav::InputStream::~InputStream ( )
virtualdefault

Member Function Documentation

◆ exhausted()

virtual bool rav::InputStream::exhausted ( )
nodiscardpure virtual
Returns
True if the stream has no more data to read.

Implemented in rav::ByteStream, rav::FileInputStream, and rav::InputStreamView.

◆ get_read_position()

virtual size_t rav::InputStream::get_read_position ( )
nodiscardpure virtual
Returns
The current read position in the stream.

Implemented in rav::ByteStream, rav::FileInputStream, and rav::InputStreamView.

◆ read()

virtual tl::expected< size_t, Error > rav::InputStream::read ( uint8_t * buffer,
size_t size )
nodiscardpure virtual

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.

Implemented in rav::ByteStream, rav::FileInputStream, and rav::InputStreamView.

◆ read_as_string()

tl::expected< std::string, Error > rav::InputStream::read_as_string ( size_t size)
nodiscard

Reads size amount of bytes from the stream and returns it as a string.

Note: returned string might contain non-printable characters.

Parameters
sizeThe number of bytes to read.
Returns
The string read from the stream.

◆ read_be()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > rav::InputStream::read_be ( )
inlinenodiscard

Reads a big-endian value from the given stream.

Template Parameters
TypeThe type of the value to read.
Returns
The decoded value.

Definition at line 126 of file input_stream.hpp.

◆ read_le()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > rav::InputStream::read_le ( )
inlinenodiscard

Reads a little-endian value from the given stream.

Template Parameters
TypeThe type of the value to read.
Returns
The decoded value.

Definition at line 138 of file input_stream.hpp.

◆ read_ne()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > rav::InputStream::read_ne ( )
inlinenodiscard

Reads a value from the given stream in native byte order (not to be confused with network-endian).

Template Parameters
TypeThe type of the value to read.
Returns
The decoded value.

Definition at line 108 of file input_stream.hpp.

◆ remaining()

std::optional< size_t > rav::InputStream::remaining ( )
nodiscard
Returns
The number of bytes remaining to read in this stream. Not all streams support this operation, in which case an empty optional is returned.

◆ set_read_position()

virtual bool rav::InputStream::set_read_position ( size_t position)
nodiscardpure virtual

Sets the read position in the stream.

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

Implemented in rav::ByteStream, rav::FileInputStream, and rav::InputStreamView.

◆ size()

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

Implemented in rav::ByteStream, rav::FileInputStream, and rav::InputStreamView.

◆ skip()

bool rav::InputStream::skip ( size_t size)
nodiscard

Skips size amount of bytes in the stream.

Parameters
sizeThe number of bytes to skip.
Returns
True if the skip was successful.

◆ to_string()

const char * rav::InputStream::to_string ( const Error e)
inlinestatic
Parameters
eThe error to convert to a string.
Returns
The string representation of the error.

Definition at line 148 of file input_stream.hpp.


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