Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
Base64OutputStream Class Reference

Base64 Stream. More...

#include <Base64OutputStream.h>

Inheritance diagram for Base64OutputStream:
StreamTransformer IDataSourceStream Stream Print

Public Member Functions

 Base64OutputStream (IDataSourceStream *stream, size_t resultSize=500)
 Stream that transforms bytes of data into base64 data stream. More...
 
size_t transform (const uint8_t *source, size_t sourceLength, uint8_t *target, size_t targetLength) override
 Inherited class implements this method to transform a block of data. More...
 
void saveState () override
 A method that backs up the current state. More...
 
void restoreState () override
 A method that restores the last backed up state. More...
 
StreamType getStreamType () const override
 Get the stream type. More...
 
int available () override
 Return the total length of the stream. More...
 
uint16_t readMemoryBlock (char *data, int bufSize) override
 Read a block of memory. More...
 
bool seek (int len) override
 Move read cursor. More...
 
bool isFinished () override
 Check if all data has been read. More...
 
virtual bool isValid () const
 Determine if the stream object contains valid data. More...
 
int read () override
 Read one character and moves the stream pointer. More...
 
int peek () override
 Read a character without advancing the stream pointer. More...
 
size_t write (uint8_t charToWrite) override
 Writes a single character to output stream. More...
 
size_t write (const char *str)
 Writes a c-string to output stream. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
size_t write (const char *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
int length () SMING_DEPRECATED
 Return the total length of the stream. More...
 
void flush () override
 
virtual String id () const
 Returns unique id of the resource. More...
 
virtual String getName () const
 Returns name of the resource. More...
 
void setTimeout (unsigned long timeout)
 
bool find (char *target)
 
bool find (char *target, size_t length)
 
bool findUntil (char *target, char *terminator)
 
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen)
 
long parseInt ()
 
float parseFloat ()
 
size_t readBytes (char *buffer, size_t length)
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
virtual int indexOf (char c)
 
int getWriteError ()
 Gets last error. More...
 
void clearWriteError ()
 Clears the last write error. More...
 
size_t print (char)
 Prints a single character to output stream. More...
 
size_t print (const char[])
 Prints a c-string to output stream. More...
 
size_t print (unsigned long, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (long, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (unsigned int, int base=DEC)
 
size_t print (unsigned char, int base=DEC)
 
size_t print (int, int base=DEC)
 Prints a number to output stream. More...
 
size_t print (double, int digits=2)
 Prints number to output stream. More...
 
size_t print (const Printable &p)
 Prints a Printable object to output stream. More...
 
size_t print (const String &s)
 Prints a String to output stream. More...
 
size_t println (void)
 Prints a newline to output stream. More...
 
size_t println (const char[])
 Prints a c-string to output stream, appending newline. More...
 
size_t println (char)
 Prints a single character to output stream, appending newline. More...
 
size_t println (unsigned char, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (unsigned int, int base=DEC)
 
size_t println (unsigned long, int base=DEC)
 
size_t println (int, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (long, int base=DEC)
 Prints a number to output stream, appending newline. More...
 
size_t println (double, int digits=2)
 Prints a number to output stream, appending newline. More...
 
size_t println (const Printable &p)
 Prints a Printable object to output stream, appending newline. More...
 
size_t println (const String &s)
 Prints a String to output stream, appending newline. More...
 
size_t printf (const char *fmt,...)
 Prints a formatted c-string to output stream. More...
 

Protected Member Functions

int timedRead ()
 
int timedPeek ()
 
int peekNextDigit ()
 
long parseInt (char skipChar)
 
float parseFloat (char skipChar)
 
void setWriteError (int err=1)
 

Protected Attributes

StreamTransformerCallback transformCallback = nullptr
 Callback function to perform transformation. More...
 
unsigned long receiveTimeout = 1000
 
unsigned long startMillis = 0
 

Detailed Description

Base64 Stream.

Constructor & Destructor Documentation

Base64OutputStream::Base64OutputStream ( IDataSourceStream stream,
size_t  resultSize = 500 
)

Stream that transforms bytes of data into base64 data stream.

Parameters
stream- source stream
resultSizeThe size of the intermediate buffer, created once per object and reused multiple times

Member Function Documentation

int StreamTransformer::available ( )
inlineoverridevirtualinherited

Return the total length of the stream.

Return values
int-1 is returned when the size cannot be determined

Reimplemented from IDataSourceStream.

void Print::clearWriteError ( )
inlineinherited

Clears the last write error.

virtual String IDataSourceStream::getName ( ) const
inlinevirtualinherited

Returns name of the resource.

Return values
String
Note
Commonly used to obtain name of file

Reimplemented in TemplateStream, FileStream, and GdbFileStream.

StreamType StreamTransformer::getStreamType ( ) const
inlineoverridevirtualinherited

Get the stream type.

Return values
StreamTypeThe stream type.

Reimplemented from IDataSourceStream.

int Print::getWriteError ( )
inlineinherited

Gets last error.

Return values
intError number of last write error
virtual String IDataSourceStream::id ( ) const
inlinevirtualinherited

Returns unique id of the resource.

Return values
Stringthe unique id of the stream.

Reimplemented in FileStream, GdbFileStream, and CircularBuffer.

bool StreamTransformer::isFinished ( )
overridevirtualinherited

Check if all data has been read.

Return values
boolTrue on success.

Implements IDataSourceStream.

virtual bool IDataSourceStream::isValid ( ) const
inlinevirtualinherited

Determine if the stream object contains valid data.

Return values
booltrue if valid, false if invalid
Note
Where inherited classes are initialised by constructor this method indicates whether that was successful or not (e.g. FileStream)

Reimplemented in FileStream, and GdbFileStream.

int IDataSourceStream::length ( )
inlineinherited

Return the total length of the stream.

Return values
int-1 is returned when the size cannot be determined
Deprecated:
Use available() instead
int IDataSourceStream::peek ( )
overridevirtualinherited

Read a character without advancing the stream pointer.

Return values
intThe character that was read or -1 if none is available

Implements Stream.

Reimplemented in HardwareSerial.

size_t Print::print ( char  )
inherited

Prints a single character to output stream.

Return values
size_tQuantity of characters written to stream
size_t Print::print ( const char  [])
inherited

Prints a c-string to output stream.

Parameters
char[]c-string to print
Return values
size_tQuantity of characters written to output stream
size_tQuantity of characters written to stream
size_t Print::print ( unsigned  char,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
unsigned longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned charNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( long  ,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( int  ,
int  base = DEC 
)
inherited

Prints a number to output stream.

Parameters
intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::print ( double  ,
int  digits = 2 
)
inherited

Prints number to output stream.

Prints a number to output stream.

Parameters
doubleNumber to print
intDecimal places to show
Return values
size_tQuantity of characters written to output stream
Parameters
doubleNumber to print
digitsThe decimal places to print (Default: 2, e.g. 21.35)
Return values
size_tQuantity of characters written to stream
size_t Print::print ( const Printable p)
inherited

Prints a Printable object to output stream.

Parameters
pObject to print
Return values
size_tQuantity of characters written to stream
size_t Print::print ( const String s)
inherited

Prints a String to output stream.

Parameters
sString to print
Return values
size_tQuantity of characters written to stream
size_t Print::printf ( const char *  fmt,
  ... 
)
inherited

Prints a formatted c-string to output stream.

Parameters
fmtPointer to formated c-string to print
...Parameters for placeholders within formated string
Return values
size_tQuantity of characters written to stream
Note
Use standard printf placeholders, e.g. d for integer, s for c-string, etc.
size_t Print::println ( void  )
inherited

Prints a newline to output stream.

Parameters
Printsnewline to output stream
Return values
size_tQuantity of characters written to output stream
size_tQuantity of characters written to stream
size_t Print::println ( const char  [])
inherited

Prints a c-string to output stream, appending newline.

Parameters
char[]c-string to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( char  )
inherited

Prints a single character to output stream, appending newline.

Parameters
charCharacter to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( unsigned  long,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
unsigned charNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
Parameters
unsigned longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( int  ,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
intNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( long  ,
int  base = DEC 
)
inherited

Prints a number to output stream, appending newline.

Parameters
longNumber to print
baseThe base for output (Default: Decimal (base 10))
Return values
size_tQuantity of characters written to stream
size_t Print::println ( double  ,
int  digits = 2 
)
inherited

Prints a number to output stream, appending newline.

Parameters
doubleNumber to print
digitsThe decimal places to print (Default: 2, e.g. 21.35)
Return values
size_tQuantity of characters written to stream
size_t Print::println ( const Printable p)
inherited

Prints a Printable object to output stream, appending newline.

Parameters
pObject to print
Return values
size_tQuantity of characters written to stream
size_t Print::println ( const String s)
inherited

Prints a String to output stream, appending newline.

Parameters
sString to print
Return values
size_tQuantity of characters written to stream
int IDataSourceStream::read ( )
overridevirtualinherited

Read one character and moves the stream pointer.

Return values
Thecharacter that was read or -1 if none is available

Implements Stream.

Reimplemented in HardwareSerial.

uint16_t StreamTransformer::readMemoryBlock ( char *  data,
int  bufSize 
)
overridevirtualinherited

Read a block of memory.

Parameters
dataPointer to the data to be read
bufSizeQuantity of chars to read
Return values
uint16_tQuantity of chars read
Todo:
Should IDataSourceStream::readMemoryBlock return same data type as its bufSize param?

Implements IDataSourceStream.

void Base64OutputStream::restoreState ( )
overridevirtual

A method that restores the last backed up state.

Reimplemented from StreamTransformer.

void Base64OutputStream::saveState ( )
overridevirtual

A method that backs up the current state.

Reimplemented from StreamTransformer.

bool StreamTransformer::seek ( int  len)
overridevirtualinherited

Move read cursor.

Parameters
lenRelative cursor adjustment
Return values
boolTrue on success.

Implements IDataSourceStream.

size_t Base64OutputStream::transform ( const uint8_t *  in,
size_t  inLength,
uint8_t *  out,
size_t  outLength 
)
overridevirtual

Inherited class implements this method to transform a block of data.

Parameters
constuint8_t* in source data
size_tinLength source data length
uint8_t*out output buffer
size_toutLength size of output buffer
Return values
size_tnumber of output bytes written
Note
Called with in = nullptr and inLength = 0 at end of input stream

Reimplemented from StreamTransformer.

size_t Print::write ( const char *  str)
inlineinherited

Writes a c-string to output stream.

Parameters
strPointer to c-string
Return values
size_tQuantity of characters written to stream
size_t Print::write ( const uint8_t *  buffer,
size_t  size 
)
virtualinherited

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream

Reimplemented in HardwareSerial, CircularBuffer, FileStream, MemoryDataStream, LimitedMemoryStream, TwoWire, EndlessMemoryStream, GdbFileStream, rBootItemOutputStream, and ReadWriteStream.

size_t Print::write ( const char *  buffer,
size_t  size 
)
inlineinherited

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream
size_t IDataSourceStream::write ( uint8_t  )
inlineoverridevirtualinherited

Writes a single character to output stream.

Parameters
uint8_tCharacter to write to output stream
Return values
size_tQuantity of characters written to output stream

Implements Print.

Reimplemented in ReadWriteStream.

Member Data Documentation

StreamTransformerCallback StreamTransformer::transformCallback = nullptr
protectedinherited

Callback function to perform transformation.

Deprecated:
Create inherited class and verride transform() method instead