Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MinWriteStream Class Reference

Stream wrapper that contains a small internal buffer to ensure that all writes are at least a certain minimum size long. More...

#include <SyncStream.hxx>

Inheritance diagram for MinWriteStream:
WrappedStream SyncStream

Public Member Functions

 MinWriteStream (unsigned min_write_length, uint8_t fill_byte, SyncStream *delegate)
 
 MinWriteStream (unsigned min_write_length, SyncStream *delegate)
 
ssize_t write (const void *data, size_t len) override
 Main entry point to the data consumption.
 
int finalize (int status) override
 Called once after all data has been written to close the stream and release resources.
 
- Public Member Functions inherited from WrappedStream
 WrappedStream (SyncStream *delegate)
 
void set_delegate (SyncStream *delegate)
 Overrides the target where to send the incoming data onwards.
 
int finalize (int status) override
 Called once after all data has been written to close the stream and release resources.
 
- Public Member Functions inherited from SyncStream
ssize_t write_all (const void *data, size_t len)
 Repeatedly writes until all data has been consumed or an error occurs.
 

Private Attributes

uint8_t * buffer_
 
unsigned bufLength_
 Number of used bytes in the buffer.
 
unsigned minWriteLength_
 Total length of the buffer.
 
uint8_t fillByte_
 What byte to append to the stream at finalize time when we still have bytes to send onwards.
 
uint8_t needsFill_
 Whether to do fill (1: yes, 0: no).
 

Additional Inherited Members

- Static Protected Member Functions inherited from SyncStream
static const uint8_t * to_8 (const void *d)
 Converts a void pointer to an equivalent byte pointer.
 
static uint8_t * to_8 (void *d)
 Converts a void pointer to an equivalent byte pointer.
 
- Protected Attributes inherited from WrappedStream
std::unique_ptr< SyncStreamdelegate_
 Where to write the data to.
 

Detailed Description

Stream wrapper that contains a small internal buffer to ensure that all writes are at least a certain minimum size long.

The delegate has to guarantee that it will always accept a min_size length write.

Definition at line 228 of file SyncStream.hxx.

Constructor & Destructor Documentation

◆ MinWriteStream() [1/2]

MinWriteStream::MinWriteStream ( unsigned  min_write_length,
uint8_t  fill_byte,
SyncStream delegate 
)
inline

Definition at line 231 of file SyncStream.hxx.

◆ MinWriteStream() [2/2]

MinWriteStream::MinWriteStream ( unsigned  min_write_length,
SyncStream delegate 
)
inline

Definition at line 242 of file SyncStream.hxx.

◆ ~MinWriteStream()

MinWriteStream::~MinWriteStream ( )
inline

Definition at line 252 of file SyncStream.hxx.

Member Function Documentation

◆ finalize()

int MinWriteStream::finalize ( int  status)
inlineoverridevirtual

Called once after all data has been written to close the stream and release resources.

Return 0 on success, <0 on failure.

Parameters
statusis an error code seen by wrapping streams. Default 0 (OK), if negative, streams might want to roll back their changes.

Reimplemented from SyncStream.

Definition at line 299 of file SyncStream.hxx.

◆ write()

ssize_t MinWriteStream::write ( const void *  data,
size_t  len 
)
inlineoverridevirtual

Main entry point to the data consumption.

Parameters
datais the pointer to a block of data to consume.
lenis the number of bytes to consume.
Returns
0 if the stream is completed/EOF (not consuming data anymore); negative value if there is an error; or the number of bytes consumed from the stream.

Implements SyncStream.

Definition at line 258 of file SyncStream.hxx.

Member Data Documentation

◆ buffer_

uint8_t* MinWriteStream::buffer_
private

Definition at line 315 of file SyncStream.hxx.

◆ bufLength_

unsigned MinWriteStream::bufLength_
private

Number of used bytes in the buffer.

Definition at line 317 of file SyncStream.hxx.

◆ fillByte_

uint8_t MinWriteStream::fillByte_
private

What byte to append to the stream at finalize time when we still have bytes to send onwards.

Definition at line 323 of file SyncStream.hxx.

◆ minWriteLength_

unsigned MinWriteStream::minWriteLength_
private

Total length of the buffer.

All writes to the downstream object will be at least this long.

Definition at line 320 of file SyncStream.hxx.

◆ needsFill_

uint8_t MinWriteStream::needsFill_
private

Whether to do fill (1: yes, 0: no).

Definition at line 325 of file SyncStream.hxx.


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