Baseclass for classes that want to provide stream-like access to data.
More...
#include <input_stream.hpp>
|
| | 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.
|
Baseclass for classes that want to provide stream-like access to data.
Definition at line 39 of file input_stream.hpp.
◆ Error
| Enumerator |
|---|
| insufficient_data | |
| failed_to_set_read_position | |
Definition at line 41 of file input_stream.hpp.
◆ InputStream()
| rav::InputStream::InputStream |
( |
| ) |
|
|
default |
◆ ~InputStream()
| virtual rav::InputStream::~InputStream |
( |
| ) |
|
|
virtualdefault |
◆ exhausted()
| virtual bool rav::InputStream::exhausted |
( |
| ) |
|
|
nodiscardpure virtual |
◆ get_read_position()
| virtual size_t rav::InputStream::get_read_position |
( |
| ) |
|
|
nodiscardpure virtual |
◆ 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
-
| buffer | The buffer to read data into. |
| size | The 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
-
| size | The 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
-
| Type | The 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
-
| Type | The 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
-
| Type | The 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 |
◆ size()
| virtual std::optional< size_t > rav::InputStream::size |
( |
| ) |
const |
|
nodiscardpure virtual |
◆ skip()
| bool rav::InputStream::skip |
( |
size_t | size | ) |
|
|
nodiscard |
Skips size amount of bytes in the stream.
- Parameters
-
| size | The 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
-
| e | The 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: