StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ suite.
Loading...
Searching...
No Matches
List of all members
StormByte::Buffer::Bridge Class Reference

Pass-through adapter that forwards bytes from an ExternalReader to an ExternalWriter in fixed-size chunks. More...

#include <StormByte/buffer/bridge.hxx>

Public Member Functions

Constructors / destructor / assignment
 Bridge (const ExternalReader &in, const ExternalWriter &out, std::size_t chunk_size=4096) noexcept
 Construct a Bridge by cloning the supplied handlers.
 
 Bridge (ExternalReader &&in, ExternalWriter &&out, std::size_t chunk_size=4096) noexcept
 Construct a Bridge by moving the supplied handlers.
 
 Bridge (const Bridge &)=delete
 Copy constructor (deleted – Bridge is non-copyable).
 
 Bridge (Bridge &&) noexcept=default
 Move constructor.
 
 ~Bridge () noexcept
 Destructor.
 
Bridgeoperator= (const Bridge &)=delete
 Copy assignment (deleted – Bridge is non-copyable).
 
Bridgeoperator= (Bridge &&) noexcept=default
 Move assignment.
 
Configuration and status
std::size_t ChunkSize () const noexcept
 Configured chunk size.
 
std::size_t PendingBytes () const noexcept
 Number of bytes currently waiting in the internal buffer.
 
bool EoF () const noexcept
 Check whether the source has reached end-of-stream.
 
bool IsReadable () const noexcept
 Check whether the source is still readable.
 
bool IsWritable () const noexcept
 Check whether the sink still accepts writes.
 
Lifecycle and error propagation
bool Flush () const noexcept
 Flush any pending bytes to the writer.
 
bool FlushAndClose () const noexcept
 Flush pending bytes and then close the writer.
 
void SetError () const noexcept
 Propagate a permanent error to the writer.
 
Passthrough
bool Passthrough (std::size_t bytes) const noexcept
 Read up to bytes from the source and forward them to the sink (const overload – non-destructive read when the reader supports it).
 
bool Passthrough (std::size_t bytes) noexcept
 Read up to bytes from the source and forward them to the sink (non-const overload – may consume data destructively).
 

Detailed Description

Pass-through adapter that forwards bytes from an ExternalReader to an ExternalWriter in fixed-size chunks.

Overview
The Bridge connects an ExternalReader (source) and an ExternalWriter (sink). It reads data from the reader and forwards it to the writer in blocks of chunk_size bytes. A small internal FIFO accumulates leftovers between calls.
Key behaviour
  • When enough bytes are available (≥ chunk_size) the bridge forwards whole chunks via ExternalWriter::Write().
  • If chunk_size is zero, chunking is disabled: every read is written immediately (no accumulation of leftovers).
  • After a successful passthrough the internal buffer contains at most chunk_size - 1 bytes. Flush() writes any remaining bytes in a single call.
  • The destructor automatically calls Flush().
End-of-stream and error handling
Thread safety
The Bridge is not thread-safe. It is intended for single-threaded use only. Concurrent access requires external synchronization.
Note
The internal buffer is marked mutable so that logically-const operations (const overloads of Passthrough / Flush) may update it. This does not imply thread safety.
See also
ExternalReader, ExternalWriter, FIFO, Pipeline

Constructor & Destructor Documentation

◆ Bridge() [1/4]

StormByte::Buffer::Bridge::Bridge ( const ExternalReader in,
const ExternalWriter out,
std::size_t  chunk_size = 4096 
)
inlinenoexcept

Construct a Bridge by cloning the supplied handlers.

Parameters
inExternal reader used as source.
outExternal writer used as sink.
chunk_sizeSize of each write chunk. If zero, chunking is disabled and every read is forwarded immediately.

◆ Bridge() [2/4]

StormByte::Buffer::Bridge::Bridge ( ExternalReader &&  in,
ExternalWriter &&  out,
std::size_t  chunk_size = 4096 
)
inlinenoexcept

Construct a Bridge by moving the supplied handlers.

Parameters
inExternal reader (will be moved).
outExternal writer (will be moved).
chunk_sizeSize of each write chunk (0 = no chunking).

◆ Bridge() [3/4]

StormByte::Buffer::Bridge::Bridge ( const Bridge )
delete

Copy constructor (deleted – Bridge is non-copyable).

◆ Bridge() [4/4]

StormByte::Buffer::Bridge::Bridge ( Bridge &&  )
defaultnoexcept

Move constructor.

◆ ~Bridge()

StormByte::Buffer::Bridge::~Bridge ( )
inlinenoexcept

Destructor.

Automatically attempts to flush any pending bytes via Flush().

Member Function Documentation

◆ ChunkSize()

std::size_t StormByte::Buffer::Bridge::ChunkSize ( ) const
inlinenoexcept

Configured chunk size.

Returns
Chunk size in bytes (0 means “no chunking”).

◆ EoF()

bool StormByte::Buffer::Bridge::EoF ( ) const
inlinenoexcept

Check whether the source has reached end-of-stream.

Returns
true when the underlying reader reports EoF.

◆ Flush()

bool StormByte::Buffer::Bridge::Flush ( ) const
noexcept

Flush any pending bytes to the writer.

Returns
true on success (or if there was nothing to flush), false on write error.

◆ FlushAndClose()

bool StormByte::Buffer::Bridge::FlushAndClose ( ) const
noexcept

Flush pending bytes and then close the writer.

Returns
true if the flush (and subsequent close) succeeded.

Equivalent to Flush() followed by out.Close(). After this call the writer will reject further writes.

◆ IsReadable()

bool StormByte::Buffer::Bridge::IsReadable ( ) const
inlinenoexcept

Check whether the source is still readable.

Returns
true if the underlying reader is readable; false on error.

◆ IsWritable()

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

Check whether the sink still accepts writes.

Returns
true if the underlying writer is writable; false if closed or in error.

◆ operator=() [1/2]

Bridge & StormByte::Buffer::Bridge::operator= ( Bridge &&  )
defaultnoexcept

Move assignment.

◆ operator=() [2/2]

Bridge & StormByte::Buffer::Bridge::operator= ( const Bridge )
delete

Copy assignment (deleted – Bridge is non-copyable).

◆ Passthrough() [1/2]

bool StormByte::Buffer::Bridge::Passthrough ( std::size_t  bytes) const
noexcept

Read up to bytes from the source and forward them to the sink (const overload – non-destructive read when the reader supports it).

Parameters
bytesNumber of bytes to request (0 = none).
Returns
true on success, false on read or write failure.

Data is written in blocks of chunk_size. Any tail shorter than chunk_size is kept in the internal buffer and will be sent on a later call or by Flush().

◆ Passthrough() [2/2]

bool StormByte::Buffer::Bridge::Passthrough ( std::size_t  bytes)
noexcept

Read up to bytes from the source and forward them to the sink (non-const overload – may consume data destructively).

Parameters
bytesNumber of bytes to request (0 = none).
Returns
true on success, false on read or write failure.

Same chunking rules as the const overload. Prefer this overload when the source should be consumed (e.g. pipeline stages).

◆ PendingBytes()

std::size_t StormByte::Buffer::Bridge::PendingBytes ( ) const
inlinenoexcept

Number of bytes currently waiting in the internal buffer.

Returns
Pending bytes (always < chunk_size when chunking is enabled).

◆ SetError()

void StormByte::Buffer::Bridge::SetError ( ) const
noexcept

Propagate a permanent error to the writer.

Calls SetError() on the underlying ExternalWriter. Subsequent writes will fail and readers may observe the error.


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