StormByte C++ Library: Buffer module 0.0.9999
StormByte-Buffer is a StormByte library module for handling buffers
Loading...
Searching...
No Matches
Public Member Functions | List of all members
StormByte::Buffer::Bridge Class Reference

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

#include <bridge.hxx>

Public Member Functions

 Bridge (const ExternalReader &in, const ExternalWriter &out, std::size_t chunk_size=4096) noexcept
 Construct a Bridge with both read and write handlers (copying handlers).
 
 Bridge (ExternalReader &&in, ExternalWriter &&out, std::size_t chunk_size=4096) noexcept
 Construct a Bridge with both read and write handlers (moving handlers).
 
std::size_t ChunkSize () const noexcept
 Gets the configured chunk size for passthrough operations.
 
bool Flush () const noexcept
 Flushes any pending bytes in the internal buffer to the write handler.
 
bool Passthrough (std::size_t bytes) const noexcept
 Passthrough bytes from read handler to write handler (const overload).
 
bool Passthrough (std::size_t bytes) noexcept
 Passthrough bytes from read handler to write handler (non-const overload).
 
std::size_t PendingBytes () const noexcept
 Gets the number of pending bytes in the internal buffer.
 
Special member functions

The Bridge is non-copyable but movable. The destructor attempts to flush any pending bytes by calling Flush().

 Bridge (const Bridge &other)=delete
 Copy constructor (deleted) — Bridge is non-copyable.
 
 Bridge (Bridge &&other) noexcept=default
 Move constructor (defaulted) — transfers handlers.
 
 ~Bridge () noexcept
 Destructor — attempts to flush pending bytes.
 
Bridgeoperator= (const Bridge &other)=delete
 Copy assignment (deleted).
 
Bridgeoperator= (Bridge &&other) noexcept=default
 Move assignment (defaulted).
 

Detailed Description

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

The Bridge connects an ExternalReader (source) and an ExternalWriter (sink). It reads data from the reader and forwards it to the writer in fixed-size chunks specified by chunk_size. The class keeps a small internal SharedFIFO buffer (m_buffer) that accumulates data between calls.

Key behaviour and guarantees:

Thread-safety and constness:

Constructor & Destructor Documentation

◆ Bridge() [1/2]

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

Construct a Bridge with both read and write handlers (copying handlers).

Parameters
inExternal reader used for reads.
outExternal writer used for writes.
chunk_sizeSize of each write chunk. If chunk_size is zero, chunking is disabled and the bridge will attempt to passthrough all read bytes immediately.

◆ Bridge() [2/2]

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

Construct a Bridge with both read and write handlers (moving handlers).

Parameters
inExternal reader used for reads (will be moved).
outExternal writer used for writes (will be moved).
chunk_sizeSize of each write chunk.

Member Function Documentation

◆ ChunkSize()

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

Gets the configured chunk size for passthrough operations.

Returns
Configured chunk size in bytes.

◆ Flush()

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

Flushes any pending bytes in the internal buffer to the write handler.

Returns
true if write succeeded, false otherwise.

◆ Passthrough() [1/2]

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

Passthrough bytes from read handler to write handler (const overload).

Parameters
bytesNumber of bytes to read. If bytes is zero, no bytes are requested.
Returns
true if the operation succeeded, false on failure.

The method requests up to bytes from the configured ExternalReader and forwards data to the ExternalWriter in fixed-size blocks of chunk_size bytes. Full chunks are written immediately; any remaining bytes that are fewer than chunk_size are retained in the bridge's internal m_buffer as leftovers. These leftovers will be combined with data from subsequent Passthrough() calls or flushed via Flush() which will attempt to write any remaining bytes in a single call.

◆ Passthrough() [2/2]

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

Passthrough bytes from read handler to write handler (non-const overload).

Parameters
bytesNumber of bytes to read. If bytes is zero, no bytes are requested.
Returns
true if the operation succeeded, false on failure.

Behaviour mirrors the const overload: data is forwarded in chunk_size increments. Any tail shorter than chunk_size is left in m_buffer and will be sent on the next passthrough or when Flush() is invoked. This design keeps the bridge invariant that m_buffer holds at most chunk_size - 1 bytes of pending data.

◆ PendingBytes()

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

Gets the number of pending bytes in the internal buffer.

Returns
Number of bytes currently stored in the internal FIFO buffer.

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