SafeString  4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
SafeStringStream Class Reference

The SafeStringStream class allows you to test your code with data read from a given SafeString as though it was a serial stream with a given baud rate, see the detailed description. More...

#include <SafeStringStream.h>

Inherits Stream.

Public Member Functions

 SafeStringStream ()
 SafeStringStream empty constructor, nothing to read yet. More...
 
 SafeStringStream (SafeString &sf)
 SafeStringStream constructor with data to be read from this stream. More...
 
 SafeStringStream (SafeString &sf, SafeString &sfRxBuffer)
 SafeStringStream constructor with data to be read from this stream and an RX buffer to be used. More...
 
void begin (const uint32_t baudRate=0)
 Enable SafeStringStream to start delivering data when read() called. More...
 
void begin (SafeString &sf, const uint32_t baudRate=0)
 Enable SafeStringStream to start delivering data from this SafeString when read() called. More...
 
size_t write (uint8_t b)
 Write a byte to this stream, the data is appended to the SafeString that is supplying data for this stream's read(). More...
 
int available ()
 How many bytes are currently available to be read. More...
 
int read ()
 Read the next byte, returns -1 if none available. More...
 
int peek ()
 Peek at the next byte, returns -1 if none available. More...
 
void flush ()
 flush any buffered writes, does nothing here except release next byte at current baud rate. More...
 
int availableForWrite ()
 How may bytes can be written to this stream before its underlying SafeString is full. More...
 
size_t RxBufferOverflow ()
 How may bytes have been dropped due to this stream's RX buffer being full. More...
 

Protected Attributes

SafeStringsfPtr
 

Detailed Description

The SafeStringStream class allows you to test your code with data read from a given SafeString as though it was a serial stream with a given baud rate, see the detailed description.

The data is released at the baud rate specified in the begin( ) to the RX buffer.
The default RX buffer size is 8 chars. A SafeString can be specified in the constructor to use as the RX buffer.
The data to be read can be written to the SafeStringStream, if the the SafeStringReader has echoON()
Any char written to the stream is appended to the back of the current data, if there is room in the SafeString the data is being read from.

See SafeStringStream, Automated Text Input Testing for an example of its use.

Definition at line 28 of file SafeStringStream.h.

Constructor & Destructor Documentation

◆ SafeStringStream() [1/3]

SafeStringStream::SafeStringStream ( )
explicit

SafeStringStream empty constructor, nothing to read yet.

Sets a default 8 char RX buffer.

◆ SafeStringStream() [2/3]

SafeStringStream::SafeStringStream ( SafeString sf)
explicit

SafeStringStream constructor with data to be read from this stream.

Sets a default 8 char RX buffer.

Parameters
sf- the SafeString containing the chars to be read from this stream. This sf can be replaced with begin( )
You can specify any empty SafeString and the later write the data to be read to the SafeStringStream.

◆ SafeStringStream() [3/3]

SafeStringStream::SafeStringStream ( SafeString sf,
SafeString sfRxBuffer 
)
explicit

SafeStringStream constructor with data to be read from this stream and an RX buffer to be used.

If the data is not available yet and you just want to increase the RX buffer, you can specify a small data SafeString and replace it later in begin( ) with the real data
OR you can specify the final data SafeString and fill it later when the data is available.
The data to be read can be written to the SafeStringStream.

Parameters
sf- the SafeString containing the chars to be read from this stream. This sf can be replaced with begin( )
sfRxBuffer– the SafeString to use a the RX buffer for this stream

Member Function Documentation

◆ available()

int SafeStringStream::available ( )

How many bytes are currently available to be read.

This is limited by the size of the RX buffer and the baud rate set

◆ availableForWrite()

int SafeStringStream::availableForWrite ( )

How may bytes can be written to this stream before its underlying SafeString is full.

◆ begin() [1/2]

void SafeStringStream::begin ( const uint32_t  baudRate = 0)

Enable SafeStringStream to start delivering data when read() called.

Parameters
baudRate- how fast to make the chars available, default 0 means infinitely fast, i.e. all data can be read immediately

◆ begin() [2/2]

void SafeStringStream::begin ( SafeString sf,
const uint32_t  baudRate = 0 
)

Enable SafeStringStream to start delivering data from this SafeString when read() called.

Parameters
sf- the SafeString containing the chars to be read from this stream. This replaces any data set in the constructor
baudRate- how fast to make the chars available, default 0 means infinitely fast, i.e. all data can be read immediately

◆ flush()

void SafeStringStream::flush ( )

flush any buffered writes, does nothing here except release next byte at current baud rate.

◆ peek()

int SafeStringStream::peek ( )

Peek at the next byte, returns -1 if none available.

◆ read()

int SafeStringStream::read ( )

Read the next byte, returns -1 if none available.

◆ RxBufferOverflow()

size_t SafeStringStream::RxBufferOverflow ( )

How may bytes have been dropped due to this stream's RX buffer being full.

The count is reset to zero by this call.

◆ write()

size_t SafeStringStream::write ( uint8_t  b)

Write a byte to this stream, the data is appended to the SafeString that is supplying data for this stream's read().

If the SafeString if full the byte is dropped and an error raised.

Parameters
b- the byte of data to write

Member Data Documentation

◆ sfPtr

SafeString* SafeStringStream::sfPtr
protected

Definition at line 122 of file SafeStringStream.h.