jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Public Member Functions | List of all members
jau::io::ByteInStream_Feed Class Referencefinal

Ringbuffer-Based byte input stream with an externally provisioned data feed. More...

#include <byte_stream.hpp>

Inheritance diagram for jau::io::ByteInStream_Feed:
Collaboration diagram for jau::io::ByteInStream_Feed:

Public Member Functions

 ByteInStream_Feed (const ByteInStream_Feed &)=delete
 
 ByteInStream_Feed (std::string id_name, const jau::fraction_i64 &timeout) noexcept
 Construct a ringbuffer backed externally provisioned byte input stream. More...
 
 ~ByteInStream_Feed () noexcept override
 
bool available (size_t n) noexcept override
 Check whether n bytes are available in the input stream. More...
 
void close () noexcept override
 Close the stream if supported by the underlying mechanism. More...
 
uint64_t content_size () const noexcept override
 Returns the content_size if known. More...
 
bool has_content_size () const noexcept override
 Returns true if implementation is aware of content_size(), otherwise false. More...
 
std::string id () const noexcept override
 return the id of this data source More...
 
void interruptReader () noexcept
 Interrupt a potentially blocked reader. More...
 
bool is_open () const noexcept override
 Checks if the stream has an associated file. More...
 
ByteInStream_Feedoperator= (const ByteInStream_Feed &)=delete
 
size_t peek (void *out, size_t length, size_t peek_offset) noexcept override
 Read from the source but do not modify the internal offset. More...
 
iostate rdstate () const noexcept override
 Returns the current state flags. More...
 
size_t read (void *out, size_t length) noexcept override
 Read from the source. More...
 
void set_content_size (const uint64_t size) noexcept
 Set known content size, informal only. More...
 
void set_eof (const async_io_result_t result) noexcept
 Set end-of-data (EOS), i.e. More...
 
uint64_t tellg () const noexcept override
 Returns the input position indicator, similar to std::basic_istream. More...
 
std::string to_string () const noexcept override
 
bool write (uint8_t in[], size_t length) noexcept
 Write given bytes to the async ringbuffer. More...
 
bool write (uint8_t in[], size_t length, const jau::fraction_i64 &timeout) noexcept
 Write given bytes to the async ringbuffer using explicit given timeout. More...
 
- Public Member Functions inherited from jau::io::ByteInStream
 ByteInStream () noexcept
 
 ByteInStream (const ByteInStream &)=delete
 
 ~ByteInStream () noexcept override=default
 
virtual bool available (size_t n) noexcept=0
 Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source. More...
 
virtual void close () noexcept=0
 Close the stream if supported by the underlying mechanism. More...
 
virtual uint64_t content_size () const noexcept=0
 Returns the content_size if known. More...
 
size_t discard (size_t N) noexcept
 Discard the next N bytes of the data. More...
 
virtual bool has_content_size () const noexcept=0
 Returns true if implementation is aware of content_size(), otherwise false. More...
 
virtual std::string id () const noexcept
 return the id of this data source More...
 
virtual bool is_open () const noexcept=0
 Checks if the stream has an associated file. More...
 
ByteInStreamoperator= (const ByteInStream &)=delete
 
bool peek (uint8_t &out) noexcept
 Peek at one byte. More...
 
virtual size_t peek (void *out, size_t length, size_t peek_offset) noexcept=0
 Read from the source but do not modify the internal offset. More...
 
bool read (uint8_t &out) noexcept
 Read one byte. More...
 
virtual size_t read (void *out, size_t length) noexcept=0
 Read from the source. More...
 
virtual uint64_t tellg () const noexcept=0
 Returns the input position indicator, similar to std::basic_istream. More...
 
virtual std::string to_string () const noexcept=0
 
- Public Member Functions inherited from jau::io::iostate_func
 iostate_func () noexcept
 
 iostate_func (const iostate_func &o) noexcept=default
 
 iostate_func (iostate_func &&o) noexcept=default
 
virtual ~iostate_func () noexcept=default
 
bool bad () const noexcept
 Checks if a non-recoverable error has occurred. More...
 
virtual void clear (const iostate state=iostate::goodbit) noexcept
 Clears state flags by assignment to the given value. More...
 
bool eof () const noexcept
 Checks if end-of-file has been reached. More...
 
bool fail () const noexcept
 Checks if an error has occurred. More...
 
bool good () const noexcept
 Checks if no error nor eof() has occurred i.e. More...
 
 operator bool () const noexcept
 Checks if no error has occurred, synonym of !fail(). More...
 
bool operator! () const noexcept
 Checks if an error has occurred, synonym of fail(). More...
 
iostate_funcoperator= (const iostate_func &o) noexcept=default
 
iostate_funcoperator= (iostate_func &&o) noexcept=default
 
virtual iostate rdstate () const noexcept
 Returns the current state flags. More...
 
void setstate (const iostate state) noexcept
 Sets state flags, by keeping its previous bits. More...
 
bool timeout () const noexcept
 Checks if a timeout (non-recoverable) has occurred. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jau::io::iostate_func
constexpr iostate rdstate_impl () const noexcept
 
constexpr void setstate_impl (iostate state) const noexcept
 

Detailed Description

Ringbuffer-Based byte input stream with an externally provisioned data feed.

Definition at line 565 of file byte_stream.hpp.

Constructor & Destructor Documentation

◆ ByteInStream_Feed() [1/2]

ByteInStream_Feed::ByteInStream_Feed ( std::string  id_name,
const jau::fraction_i64 timeout 
)
noexcept

Construct a ringbuffer backed externally provisioned byte input stream.

Parameters
id_namearbitrary identifier for this instance
timeoutmaximum duration in fractions of seconds to wait @ available() and write(), where fractions_i64::zero waits infinitely

Definition at line 463 of file byte_stream.cpp.

◆ ByteInStream_Feed() [2/2]

jau::io::ByteInStream_Feed::ByteInStream_Feed ( const ByteInStream_Feed )
delete

◆ ~ByteInStream_Feed()

jau::io::ByteInStream_Feed::~ByteInStream_Feed ( )
inlineoverridenoexcept

Definition at line 620 of file byte_stream.hpp.

Member Function Documentation

◆ available()

bool ByteInStream_Feed::available ( size_t  n)
overridevirtualnoexcept

Check whether n bytes are available in the input stream.

Wait up to timeout duration set in constructor until n bytes become available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
nbyte count to wait for
Returns
true if n bytes are available, otherwise false
See also
read()
ByteInStream Properties

Implements jau::io::ByteInStream.

Definition at line 479 of file byte_stream.cpp.

◆ read()

size_t ByteInStream_Feed::read ( void *  out,
size_t  length 
)
overridevirtualnoexcept

Read from the source.

Moves the internal offset so that every call to read will return a new portion of the source.

Use available() to wait and ensure a certain amount of bytes are available.

This method is not blocking beyond the transfer of min(available, length) bytes.

Parameters
outthe byte array to write the result to
lengththe length of the byte array out
Returns
length in bytes that was actually read and put into out
See also
available()
ByteInStream Properties

Implements jau::io::ByteInStream.

Definition at line 510 of file byte_stream.cpp.

◆ peek()

size_t ByteInStream_Feed::peek ( void *  out,
size_t  length,
size_t  peek_offset 
)
overridevirtualnoexcept

Read from the source but do not modify the internal offset.

Consecutive calls to peek() will return portions of the source starting at the same position.

Parameters
outthe byte array to write the output to
lengththe length of the byte array out
peek_offsetthe offset into the stream to read at
Returns
length in bytes that was actually read and put into out

Implements jau::io::ByteInStream.

Definition at line 529 of file byte_stream.cpp.

◆ rdstate()

iostate ByteInStream_Feed::rdstate ( ) const
overridevirtualnoexcept

Returns the current state flags.

Method is marked virtual to allow implementations with asynchronous resources to determine or update the current iostate.

Method is used throughout all query members and setstate(), hence they all will use the updated state from a potential override implementation.

Reimplemented from jau::io::iostate_func.

Definition at line 537 of file byte_stream.cpp.

◆ id()

std::string jau::io::ByteInStream_Feed::id ( ) const
inlineoverridevirtualnoexcept

return the id of this data source

Returns
std::string representing the id of this data source

Reimplemented from jau::io::ByteInStream.

Definition at line 603 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ operator=()

ByteInStream_Feed & jau::io::ByteInStream_Feed::operator= ( const ByteInStream_Feed )
delete

◆ is_open()

bool ByteInStream_Feed::is_open ( ) const
overridevirtualnoexcept

Checks if the stream has an associated file.

Implements jau::io::ByteInStream.

Definition at line 505 of file byte_stream.cpp.

◆ close()

void ByteInStream_Feed::close ( )
overridevirtualnoexcept

Close the stream if supported by the underlying mechanism.

Implements jau::io::ByteInStream.

Definition at line 469 of file byte_stream.cpp.

◆ tellg()

uint64_t jau::io::ByteInStream_Feed::tellg ( ) const
inlineoverridevirtualnoexcept

Returns the input position indicator, similar to std::basic_istream.

Returns
number of bytes read so far.

Implements jau::io::ByteInStream.

Definition at line 622 of file byte_stream.hpp.

◆ has_content_size()

bool jau::io::ByteInStream_Feed::has_content_size ( ) const
inlineoverridevirtualnoexcept

Returns true if implementation is aware of content_size(), otherwise false.

See also
content_size()

Implements jau::io::ByteInStream.

Definition at line 624 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ content_size()

uint64_t jau::io::ByteInStream_Feed::content_size ( ) const
inlineoverridevirtualnoexcept

Returns the content_size if known.

See also
has_content_size()

Implements jau::io::ByteInStream.

Definition at line 626 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ interruptReader()

void jau::io::ByteInStream_Feed::interruptReader ( )
inlinenoexcept

Interrupt a potentially blocked reader.

Call this method if intended to abort streaming and to interrupt the reader thread's potentially blocked available() call, i.e. done at set_eof()

See also
set_eof()

Definition at line 636 of file byte_stream.hpp.

◆ write() [1/2]

bool ByteInStream_Feed::write ( uint8_t  in[],
size_t  length,
const jau::fraction_i64 timeout 
)
noexcept

Write given bytes to the async ringbuffer using explicit given timeout.

Wait up to explicit given timeout duration until ringbuffer space is available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
nbyte count to wait for
inthe byte array to transfer to the async ringbuffer
lengththe length of the byte array in
timeoutexplicit given timeout for async ringbuffer put operation
Returns
true if successful, otherwise false on timeout or stopped feeder and subsequent calls to good() will return false.

Definition at line 549 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ write() [2/2]

bool jau::io::ByteInStream_Feed::write ( uint8_t  in[],
size_t  length 
)
inlinenoexcept

Write given bytes to the async ringbuffer.

Wait up to timeout duration set in constructor until ringbuffer space is available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
nbyte count to wait for
inthe byte array to transfer to the async ringbuffer
lengththe length of the byte array in
Returns
true if successful, otherwise false on timeout or stopped feeder and subsequent calls to good() will return false.

Definition at line 667 of file byte_stream.hpp.

◆ set_content_size()

void jau::io::ByteInStream_Feed::set_content_size ( const uint64_t  size)
inlinenoexcept

Set known content size, informal only.

Parameters
content_lengththe content size in bytes

Definition at line 675 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ set_eof()

void ByteInStream_Feed::set_eof ( const async_io_result_t  result)
noexcept

Set end-of-data (EOS), i.e.

when feeder completed provisioning bytes.

Implementation issues interruptReader() to unblock a potentially blocked reader thread.

Parameters
resultshould be either result_t::FAILED or result_t::SUCCESS.
See also
interruptReader()

Definition at line 572 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ to_string()

std::string ByteInStream_Feed::to_string ( ) const
overridevirtualnoexcept

Implements jau::io::ByteInStream.

Definition at line 587 of file byte_stream.cpp.


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