jaulib v1.4.1
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
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, lb_endian_t byteOrder=lb_endian_t::little) noexcept
 Construct a ringbuffer backed externally provisioned byte input stream.
 
 ~ByteInStream_Feed () noexcept override
 
bool available (size_t n) noexcept override
 Check whether n bytes are available in the input stream.
 
bool canRewind () const noexcept override
 Return true if implementation supports random rewinding the stream, i.e.
 
void close () noexcept override
 Close the stream if supported by the underlying mechanism.
 
size_type contentSize () const noexcept override
 Returns the content_size if known.
 
size_t discard (size_t N) noexcept override
 Implemented by skipping input stream via read.
 
void flush () noexcept override
 Synchronizes all output operations, or do nothing.
 
bool hasContentSize () const noexcept override
 Returns true if implementation is aware of content_size(), otherwise false.
 
std::string id () const noexcept override
 return the id of this data source
 
void interruptReader () noexcept
 Interrupt a potentially blocked reader.
 
bool isOpen () const noexcept override
 Checks if the stream has an associated file.
 
size_type mark () const noexcept override
 Returns the markpos set via setMark() or ByteStream::npos if unset.
 
size_type markReadLimit () const noexcept override
 Returns the readLimit set via setMark().
 
ByteInStream_Feedoperator= (const ByteInStream_Feed &)=delete
 
size_t peek (void *out, size_t length, size_type peek_offset) noexcept override
 Not implemented, returns 0.
 
size_type position () const noexcept override
 Returns the position indicator, similar to e.g.
 
iostate_t rdstate () const noexcept override
 Returns the current state flags.
 
size_t read (void *out, size_t length) noexcept override
 Read from the source.
 
size_type seek (size_type newPos) noexcept override
 newPos < position() limited to markpos, see setMark().
 
bool seekMark () noexcept override
 Seeks stream position to markpos as set via setMark().
 
void setContentSize (const size_type size) noexcept
 Set known content size, informal only.
 
void setEOF (const io_result_t result) noexcept
 Set end-of-data (EOS), i.e.
 
bool setMark (size_type readLimit) noexcept override
 Set markpos to current position, allowing the stream to be seekMark().
 
std::string toString () const noexcept override
 
size_t write (const void *in, size_t length) noexcept override
 Write given bytes to the async ringbuffer, feeding the input stream.
 
size_t write (const void *in, size_t length, const jau::fraction_i64 &timeout) noexcept
 Write given bytes to the async ringbuffer using explicit given timeout.
 
- Public Member Functions inherited from jau::io::ByteStream
 ByteStream (iomode_t mode, lb_endian_t byteOrder=lb_endian_t::little) noexcept
 
 ~ByteStream () noexcept override=default
 
constexpr lb_endian_t byteOrder () const noexcept
 Returns endian byte-order of stream storage.
 
constexpr bool canRead () const noexcept
 Returns true in case stream has iomode::read capabilities.
 
constexpr bool canWrite () const noexcept
 Returns true in case stream has iomode::write capabilities.
 
constexpr iomode_t mode () const noexcept
 
bool peek (uint8_t &out) noexcept
 Peek one byte at current position.
 
bool read (uint8_t &bits) noexcept
 Read one byte, uint8_t
 
bool readS16 (int16_t &bits) noexcept
 Read int16_t.
 
bool readS32 (int32_t &bits) noexcept
 Read int32_t.
 
bool readS64 (int64_t &bits) noexcept
 Read int64_t.
 
bool readU16 (uint16_t &bits) noexcept
 Read uint16_t.
 
bool readU32 (uint32_t &bits) noexcept
 Read incoming uint32_t.
 
bool readU64 (uint64_t &bits) noexcept
 Read incoming uint64_t.
 
bool readU64Raw (uint64_t &bits) noexcept
 Read incoming uint64_t w/o considering bigEndian, i.e.
 
virtual size_type remaining () const noexcept
 Returns the remaining bytes, i.e.
 
void setImmutable () noexcept
 Clears iomode_t::write from mode()
 
bool write (uint8_t in) noexcept
 Write one byte, uint8_t.
 
bool writeS16 (int16_t bits) noexcept
 Write the given int16_t.
 
bool writeS32 (int32_t bits) noexcept
 Write the given int32_t.
 
bool writeS64 (int64_t bits) noexcept
 Write the given int64_t.
 
bool writeU16 (uint16_t bits) noexcept
 Write the given uint16_t.
 
bool writeU32 (uint32_t bits) noexcept
 Write the given uint32_t.
 
bool writeU64 (uint64_t bits) noexcept
 Write the given uint64_t.
 
bool writeU64Raw (uint64_t bits) noexcept
 Write the given uint64_t w/o considering bigEndian, i.e.
 
- Public Member Functions inherited from jau::io::IOStateCap
 IOStateCap () noexcept
 
 IOStateCap (const IOStateCap &o) noexcept=default
 
 IOStateCap (IOStateCap &&o) noexcept=default
 
virtual ~IOStateCap () noexcept=default
 
void addState (const iostate_t state) noexcept
 Adds given state flags to existing rdstate() bits.
 
virtual void assignState (const iostate_t state=iostate_t::goodbit) noexcept
 Assigns given state to current value.
 
bool bad () const noexcept
 Checks if a non-recoverable error has occurred.
 
void clear (const iostate_t state=iostate_t::goodbit) noexcept
 Clears state flags by assignment to the given value.
 
void clearStateFlags (const iostate_t clr) noexcept
 Clears given state flags from current value.
 
bool eof () const noexcept
 Checks if end-of-file has been reached.
 
bool fail () const noexcept
 Checks if an error has occurred.
 
bool good () const noexcept
 Checks if no error nor eof() has occurred i.e.
 
 operator bool () const noexcept
 Checks if no error has occurred, synonym of !fail().
 
bool operator! () const noexcept
 Checks if an error has occurred, synonym of fail().
 
IOStateCapoperator= (const IOStateCap &o) noexcept=default
 
IOStateCapoperator= (IOStateCap &&o) noexcept=default
 
void setstate (const iostate_t state) noexcept
 Sets state flags, by keeping its previous bits.
 
bool timeout () const noexcept
 Checks if a timeout (non-recoverable) has occurred.
 

Additional Inherited Members

- Public Types inherited from jau::io::ByteStream
typedef uint64_t size_type
 uint64_t size data type, bit position and count
 
- Static Public Attributes inherited from jau::io::ByteStream
static constexpr size_type npos = std::numeric_limits<size_type>::max()
 Invalid position constant, denoting unset mark() or invalid position.
 
- Protected Member Functions inherited from jau::io::ByteStream
size_t discardRead (size_t n) noexcept
 Fallback slow discard implementation usind read() in case of unknown stream size.
 
- Protected Member Functions inherited from jau::io::IOStateCap
constexpr void addstate_impl (iostate_t state) const noexcept
 
constexpr iostate_t rdstate_impl () const noexcept
 
- Protected Attributes inherited from jau::io::ByteStream
lb_endian_t m_byteOrder
 
iomode_t m_iomode
 

Detailed Description

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

Definition at line 1073 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,
lb_endian_t byteOrder = lb_endian_t::little )
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
byteOrderendian byte-order of stream storage, defaults to lb_endian_t::little. Only affects multi-byte r/w operations, e.g. readU16(), writeU16(), etc

Definition at line 709 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ 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 1088 of file byte_stream.hpp.

Member Function Documentation

◆ operator=()

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

◆ 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 1098 of file byte_stream.hpp.

◆ setContentSize()

void jau::io::ByteInStream_Feed::setContentSize ( const size_type size)
inlinenoexcept

Set known content size, informal only.

Parameters
content_lengththe content size in bytes

Definition at line 1106 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ setEOF()

void ByteInStream_Feed::setEOF ( const 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 850 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ rdstate()

iostate_t 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 addState(), hence they all will use the updated state from a potential override implementation.

Reimplemented from jau::io::IOStateCap.

Definition at line 814 of file byte_stream.cpp.

◆ isOpen()

bool ByteInStream_Feed::isOpen ( ) const
overridevirtualnoexcept

Checks if the stream has an associated file.

Implements jau::io::ByteStream.

Definition at line 752 of file byte_stream.cpp.

◆ close()

void ByteInStream_Feed::close ( )
overridevirtualnoexcept

Close the stream if supported by the underlying mechanism.

Implements jau::io::ByteStream.

Definition at line 716 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ 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::ByteStream.

Definition at line 1128 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ hasContentSize()

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

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

See also
content_size()

Implements jau::io::ByteStream.

Definition at line 1130 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ contentSize()

size_type jau::io::ByteInStream_Feed::contentSize ( ) const
inlineoverridevirtualnoexcept

Returns the content_size if known.

See also
has_content_size()

Implements jau::io::ByteStream.

Definition at line 1132 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ position()

size_type jau::io::ByteInStream_Feed::position ( ) const
inlineoverridevirtualnoexcept

Returns the position indicator, similar to e.g.

std::basic_istream.

Returns
number of bytes read or written so far.

Implements jau::io::ByteStream.

Definition at line 1134 of file byte_stream.hpp.

◆ canRewind()

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

Return true if implementation supports random rewinding the stream, i.e.

seek() below position().

If random rewind is not supported and method returns false, one can still rewind in range [mark() .. position()).

See also
seek()
setMark()

Implements jau::io::ByteStream.

Definition at line 1136 of file byte_stream.hpp.

◆ seek()

ByteStream::size_type ByteInStream_Feed::seek ( size_type newPos)
nodiscardoverridevirtualnoexcept

newPos < position() limited to markpos, see setMark().

Implements jau::io::ByteStream.

Definition at line 757 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ toString()

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

Implements jau::io::ByteStream.

Definition at line 866 of file byte_stream.cpp.

◆ setMark()

bool ByteInStream_Feed::setMark ( size_type readLimit)
nodiscardoverridevirtualnoexcept

Set markpos to current position, allowing the stream to be seekMark().

seek() will clear markpos if > newPos.

For implementations where seek() doesn't allow random rewinding of the stream, setMark() will allow rewinding back to markpos if not exceeding readLimit.

Parameters
readlimitmaximum number of bytes able to read before invalidating the markpos.
Returns
true if marks is set successfully, otherwise false
See also
seek()
canRewind()

Implements jau::io::ByteStream.

Definition at line 783 of file byte_stream.cpp.

◆ mark()

size_type jau::io::ByteInStream_Feed::mark ( ) const
inlineoverridevirtualnoexcept

Returns the markpos set via setMark() or ByteStream::npos if unset.

Implements jau::io::ByteStream.

Definition at line 1144 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ markReadLimit()

size_type jau::io::ByteInStream_Feed::markReadLimit ( ) const
inlineoverridevirtualnoexcept

Returns the readLimit set via setMark().

If unset either 0 or implicit limit.

Implements jau::io::ByteStream.

Definition at line 1145 of file byte_stream.hpp.

◆ seekMark()

bool ByteInStream_Feed::seekMark ( )
nodiscardoverridevirtualnoexcept

Seeks stream position to markpos as set via setMark().

markpos is kept, hence seekMark() can be called multiple times.

Returns
true if successful (incl eofbit), otherwise false with unchanged position due to I/O failure (iostate::fail set) or setMark() not set.

Implements jau::io::ByteStream.

Definition at line 792 of file byte_stream.cpp.

◆ 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::ByteStream.

Definition at line 726 of file byte_stream.cpp.

◆ read()

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

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::ByteStream.

Definition at line 799 of file byte_stream.cpp.

◆ peek()

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

Not implemented, returns 0.

Implements jau::io::ByteStream.

Definition at line 806 of file byte_stream.cpp.

◆ discard()

size_t ByteInStream_Feed::discard ( size_t N)
nodiscardoverridevirtualnoexcept

Implemented by skipping input stream via read.

Implements jau::io::ByteStream.

Definition at line 779 of file byte_stream.cpp.

◆ write() [1/2]

size_t ByteInStream_Feed::write ( const void * in,
size_t length,
const jau::fraction_i64 & timeout )
nodiscardnoexcept

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 826 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ write() [2/2]

size_t jau::io::ByteInStream_Feed::write ( const void * in,
size_t length )
inlinenodiscardoverridevirtualnoexcept

Write given bytes to the async ringbuffer, feeding the input stream.

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

This method is blocking.

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

Implements jau::io::ByteStream.

Definition at line 1212 of file byte_stream.hpp.

◆ flush()

void jau::io::ByteInStream_Feed::flush ( )
inlineoverridevirtualnoexcept

Synchronizes all output operations, or do nothing.

Implements jau::io::ByteStream.

Definition at line 1216 of file byte_stream.hpp.


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