StormByte-Buffer 2.0.0
C++26 buffer module of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Buffer::Consumer Class Referencefinal

Read-oriented handle over a shared Ring. More...

#include <StormByte/buffer/consumer.hxx>

Inheritance diagram for StormByte::Buffer::Consumer:
Collaboration diagram for StormByte::Buffer::Consumer:

Public Member Functions

Constructors / destructor / assignment
 Consumer () noexcept
 Empty Consumer.
 
 Consumer (const Consumer &other) noexcept
 Copy constructor.
 
 Consumer (Consumer &&other) noexcept
 Move constructor.
 
 ~Consumer () noexcept override
 Destructor.
 
Consumer & operator= (const Consumer &other) noexcept
 Copy assignment.
 
Consumer & operator= (Consumer &&other) noexcept
 Move assignment.
 
Comparison
bool operator== (const Consumer &other) const noexcept
 Equality comparison.
 
bool operator!= (const Consumer &other) const noexcept
 Inequality comparison.
 
Queries
StormByte::ByteSize Available () const noexcept override
 Number of bytes available for reading from the current position.
 
const StormByte::BinaryData & Data () const noexcept override
 Access a snapshot of the underlying data (implementation-defined).
 
bool Empty () const noexcept override
 Whether the shared Ring holds no stored bytes.
 
bool EoF () const noexcept override
 End-of-stream condition.
 
bool IsReadable () const noexcept override
 Whether the shared Ring can still be read.
 
bool IsWritable () const noexcept
 Whether the shared Ring still accepts writes.
 
bool HasError () const noexcept
 Whether the shared Ring is in a permanent error state.
 
StormByte::ByteSize Size () const noexcept override
 Total number of bytes stored in the shared Ring.
 
class Producer Producer () const noexcept
 Writer on the same Ring.
 
Maintenance / lifecycle
void Clean () noexcept override
 Discard already-consumed data (from start up to the read position).
 
void Clear () noexcept override
 Clear all buffer contents.
 
void Close () noexcept
 Close the shared Ring for further writes.
 
bool Drop (const StormByte::ByteSize &count) noexcept override
 Discard count bytes from the current read position.
 
void Seek (const std::ptrdiff_t &offset, const Position &mode) const noexcept override
 Move the logical read position for non-destructive reads.
 
Extract (destructive read)
bool Extract (const StormByte::ByteSize &count, StormByte::BinaryData &out) noexcept override
 Extract bytes into a StormByte::BinaryData (consumes data from the Ring).
 
bool Extract (const StormByte::ByteSize &count, WriteOnly &out) noexcept override
 Extract bytes into a WriteOnly store.
 
void ExtractUntilEoF (StormByte::BinaryData &out) noexcept override
 Extract until EoF into a StormByte::BinaryData.
 
void ExtractUntilEoF (WriteOnly &out) noexcept override
 Extract until EoF into a WriteOnly store.
 
Read (non-destructive)
bool Read (const StormByte::ByteSize &count, StormByte::BinaryData &out) const noexcept override
 Read bytes into a StormByte::BinaryData.
 
bool Read (const StormByte::ByteSize &count, WriteOnly &out) const noexcept override
 Read bytes into a WriteOnly store.
 
void ReadUntilEoF (StormByte::BinaryData &out) const noexcept override
 Read until EoF into a StormByte::BinaryData.
 
void ReadUntilEoF (WriteOnly &out) const noexcept override
 Read until EoF into a WriteOnly store.
 
Peek
bool Peek (const StormByte::ByteSize &count, StormByte::BinaryData &out) const noexcept override
 Peek bytes into a StormByte::BinaryData.
 
bool Peek (const StormByte::ByteSize &count, WriteOnly &out) const noexcept override
 Peek bytes into a WriteOnly store.
 
- Public Member Functions inherited from StormByte::Buffer::ReadOnly
 ReadOnly () noexcept
 Default constructor.
 
 ReadOnly (const ReadOnly &other) noexcept=default
 Copy constructor.
 
 ReadOnly (ReadOnly &&other) noexcept=default
 Move constructor.
 
virtual ~ReadOnly () noexcept
 Destructor.
 
ReadOnly & operator= (const ReadOnly &other)=default
 Copy assignment.
 
ReadOnly & operator= (ReadOnly &&other) noexcept=default
 Move assignment.
 
bool Extract (StormByte::BinaryData &outBuffer) noexcept
 Extract all available bytes into a StormByte::BinaryData.
 
bool Extract (WriteOnly &outBuffer) noexcept
 Extract all available bytes into a WriteOnly.
 
bool Read (StormByte::BinaryData &outBuffer) const noexcept
 Read all available bytes into a StormByte::BinaryData.
 
bool Read (WriteOnly &outBuffer) const noexcept
 Read all available bytes into a WriteOnly.
 
- Public Member Functions inherited from StormByte::Buffer::Generic
 Generic () noexcept=default
 Default constructor.
 
 Generic (const Generic &other) noexcept=default
 Copy constructor.
 
 Generic (Generic &&other) noexcept=default
 Move constructor.
 
virtual ~Generic () noexcept=0
 Pure virtual destructor.
 
Generic & operator= (const Generic &other)=default
 Copy assignment.
 
Generic & operator= (Generic &&other) noexcept=default
 Move assignment.
 

Friends

class Producer
 

Additional Inherited Members

- Static Protected Member Functions inherited from StormByte::Buffer::Generic
template<Type::ByteInputRange Src>
static BinaryData DataConvert (const Src &src) noexcept
 Convert an lvalue input range to StormByte::BinaryData.
 
template<Type::ByteInputRange Src>
static BinaryData DataConvert (Src &&src) noexcept
 Convert an rvalue input range to StormByte::BinaryData.
 
static BinaryData DataConvert (std::string_view sv) noexcept
 Convert a string view to StormByte::BinaryData.
 
static BinaryData DataConvert (const char *s) noexcept
 Convert a C string to StormByte::BinaryData.
 

Detailed Description

Read-oriented handle over a shared Ring.

Multiple Consumer instances may share the same underlying Ring, allowing concurrent reads in a fully thread-safe manner.

An empty Consumer (Consumer()) creates its own Ring. Producer() then returns a writer on that Ring. A Consumer may also be obtained from Producer::Consumer().

All operations are thread-safe and delegate to the shared Ring. Blocking semantics match Ring. Read / Extract / Peek block until data is available or the buffer is closed / in error.

Lifecycle signalling
Although Consumer is primarily a ReadOnly view, it also exposes:
See also
Producer, Ring, ReadOnly

Constructor & Destructor Documentation

◆ Consumer() [1/3]

StormByte::Buffer::Consumer::Consumer ( )
inlinenoexcept

Empty Consumer.

Creates a new shared Ring.

Producer() returns a writer on that Ring. Use this when the owner only reads and still needs a write tip for a Bridge.

◆ Consumer() [2/3]

StormByte::Buffer::Consumer::Consumer ( const Consumer &  other)
inlinenoexcept

Copy constructor.

Parameters
otherSource Consumer; both share the same Ring.

◆ Consumer() [3/3]

StormByte::Buffer::Consumer::Consumer ( Consumer &&  other)
inlinenoexcept

Move constructor.

Parameters
otherSource Consumer (left in a valid but unspecified state).

◆ ~Consumer()

StormByte::Buffer::Consumer::~Consumer ( )
overridenoexcept

Destructor.

Member Function Documentation

◆ Available()

StormByte::ByteSize StormByte::Buffer::Consumer::Available ( ) const
overridevirtualnoexcept

Number of bytes available for reading from the current position.

Returns
Available byte count.

Implements StormByte::Buffer::ReadOnly.

◆ Clean()

void StormByte::Buffer::Consumer::Clean ( )
overridevirtualnoexcept

Discard already-consumed data (from start up to the read position).

Implements StormByte::Buffer::ReadOnly.

◆ Clear()

void StormByte::Buffer::Consumer::Clear ( )
overridevirtualnoexcept

Clear all buffer contents.

Does not clear closed / error flags on the shared Ring.

Implements StormByte::Buffer::ReadOnly.

◆ Close()

void StormByte::Buffer::Consumer::Close ( )
inlinenoexcept

Close the shared Ring for further writes.

Equivalent to Producer::Close on the same underlying buffer. Readers may still drain remaining data until EoF.

◆ Data()

const StormByte::BinaryData & StormByte::Buffer::Consumer::Data ( ) const
overridevirtualnoexcept

Access a snapshot of the underlying data (implementation-defined).

Returns
Constant reference to the Ring’s StormByte::BinaryData view.
Warning
Not intended for concurrent mutation; prefer Read / Extract.

Implements StormByte::Buffer::ReadOnly.

◆ Drop()

bool StormByte::Buffer::Consumer::Drop ( const StormByte::ByteSize &  count)
overridevirtualnoexcept

Discard count bytes from the current read position.

Parameters
countNumber of bytes to drop.
Returns
true on success, false if fewer bytes were available.

Implements StormByte::Buffer::ReadOnly.

◆ Empty()

bool StormByte::Buffer::Consumer::Empty ( ) const
overridevirtualnoexcept

Whether the shared Ring holds no stored bytes.

Returns
true if empty.
Note
With a non-zero read position, Empty() may still be false even when Available() is zero.

Implements StormByte::Buffer::ReadOnly.

◆ EoF()

bool StormByte::Buffer::Consumer::EoF ( ) const
overridevirtualnoexcept

End-of-stream condition.

Returns
true when the Ring is closed (or in error) and no bytes remain.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [1/2]

bool StormByte::Buffer::Consumer::Extract ( const StormByte::ByteSize &  count,
StormByte::BinaryData &  out 
)
overridevirtualnoexcept

Extract bytes into a StormByte::BinaryData (consumes data from the Ring).

Parameters
countNumber of bytes to extract; 0 extracts all available.
outDestination (appended to).
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ Extract() [2/2]

bool StormByte::Buffer::Consumer::Extract ( const StormByte::ByteSize &  count,
WriteOnly &  out 
)
overridevirtualnoexcept

Extract bytes into a WriteOnly store.

Parameters
countNumber of bytes to extract; 0 extracts all available.
outDestination.
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ ExtractUntilEoF() [1/2]

void StormByte::Buffer::Consumer::ExtractUntilEoF ( StormByte::BinaryData &  out)
overridevirtualnoexcept

Extract until EoF into a StormByte::BinaryData.

Parameters
outDestination.

Implements StormByte::Buffer::ReadOnly.

◆ ExtractUntilEoF() [2/2]

void StormByte::Buffer::Consumer::ExtractUntilEoF ( WriteOnly &  out)
overridevirtualnoexcept

Extract until EoF into a WriteOnly store.

Parameters
outDestination.

Implements StormByte::Buffer::ReadOnly.

◆ HasError()

bool StormByte::Buffer::Consumer::HasError ( ) const
inlinenoexcept

Whether the shared Ring is in a permanent error state.

Returns
true after Producer::SetError on any handle to the same Ring.

◆ IsReadable()

bool StormByte::Buffer::Consumer::IsReadable ( ) const
overridevirtualnoexcept

Whether the shared Ring can still be read.

Returns
false if the Ring is in a permanent error state.

Implements StormByte::Buffer::ReadOnly.

◆ IsWritable()

bool StormByte::Buffer::Consumer::IsWritable ( ) const
inlinenoexcept

Whether the shared Ring still accepts writes.

Returns
false if closed or in error.

Observes producer-side lifecycle on the same Ring (e.g. wait until a pipeline stage calls Close()).

◆ operator!=()

bool StormByte::Buffer::Consumer::operator!= ( const Consumer &  other) const
inlinenoexcept

Inequality comparison.

Parameters
otherOther Consumer.
Returns
true if the underlying Ring instances differ.

◆ operator=() [1/2]

Consumer & StormByte::Buffer::Consumer::operator= ( const Consumer &  other)
inlinenoexcept

Copy assignment.

Parameters
otherSource Consumer; both share the same Ring afterwards.
Returns
Reference to this Consumer.

◆ operator=() [2/2]

Consumer & StormByte::Buffer::Consumer::operator= ( Consumer &&  other)
inlinenoexcept

Move assignment.

Parameters
otherSource Consumer.
Returns
Reference to this Consumer.

◆ operator==()

bool StormByte::Buffer::Consumer::operator== ( const Consumer &  other) const
inlinenoexcept

Equality comparison.

Parameters
otherOther Consumer.
Returns
true if both refer to the same underlying Ring instance.

◆ Peek() [1/2]

bool StormByte::Buffer::Consumer::Peek ( const StormByte::ByteSize &  count,
StormByte::BinaryData &  out 
) const
overridevirtualnoexcept

Peek bytes into a StormByte::BinaryData.

Does not advance the cursor.

Parameters
countNumber of bytes to peek; 0 peeks all available.
outDestination (appended to).
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ Peek() [2/2]

bool StormByte::Buffer::Consumer::Peek ( const StormByte::ByteSize &  count,
WriteOnly &  out 
) const
overridevirtualnoexcept

Peek bytes into a WriteOnly store.

Does not advance the cursor.

Parameters
countNumber of bytes to peek; 0 peeks all available.
outDestination.
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ Producer()

class Producer StormByte::Buffer::Consumer::Producer ( ) const
noexcept

Writer on the same Ring.

Returns
Producer that shares this Consumer’s store.

Inverse of Producer::Consumer. The Ring already exists (Consumer() or a Producer-born Consumer).

◆ Read() [1/2]

bool StormByte::Buffer::Consumer::Read ( const StormByte::ByteSize &  count,
StormByte::BinaryData &  out 
) const
overridevirtualnoexcept

Read bytes into a StormByte::BinaryData.

Advances the cursor.

Parameters
countNumber of bytes to read; 0 reads all available.
outDestination (appended to).
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ Read() [2/2]

bool StormByte::Buffer::Consumer::Read ( const StormByte::ByteSize &  count,
WriteOnly &  out 
) const
overridevirtualnoexcept

Read bytes into a WriteOnly store.

Advances the cursor.

Parameters
countNumber of bytes to read; 0 reads all available.
outDestination.
Returns
true on success.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoF() [1/2]

void StormByte::Buffer::Consumer::ReadUntilEoF ( StormByte::BinaryData &  out) const
overridevirtualnoexcept

Read until EoF into a StormByte::BinaryData.

Parameters
outDestination.

Implements StormByte::Buffer::ReadOnly.

◆ ReadUntilEoF() [2/2]

void StormByte::Buffer::Consumer::ReadUntilEoF ( WriteOnly &  out) const
overridevirtualnoexcept

Read until EoF into a WriteOnly store.

Parameters
outDestination.

Implements StormByte::Buffer::ReadOnly.

◆ Seek()

void StormByte::Buffer::Consumer::Seek ( const std::ptrdiff_t &  offset,
const Position &  mode 
) const
overridevirtualnoexcept

Move the logical read position for non-destructive reads.

Parameters
offsetOffset value.
modePosition::Absolute or Position::Relative.

Implements StormByte::Buffer::ReadOnly.

◆ Size()

StormByte::ByteSize StormByte::Buffer::Consumer::Size ( ) const
overridevirtualnoexcept

Total number of bytes stored in the shared Ring.

Returns
Size in bytes.

Implements StormByte::Buffer::Generic.

Friends And Related Symbol Documentation

◆ Producer

friend class Producer
friend

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