libcommonc++  0.7
StreamDataReader Class Reference

A DataReader which reads data from a Stream. More...

#include <StreamDataReader.h++>

Inheritance diagram for StreamDataReader:
Collaboration diagram for StreamDataReader:

Public Member Functions

 StreamDataReader (Stream &stream, size_t bufferSize=BUFFER_SIZE)
 Construct a new StreamDataReader for the given Stream. More...
 
 ~StreamDataReader ()
 Destructor. More...
 
void skip (size_t count)
 Skip past the given number of bytes in the data stream. More...
 
void reset ()
 Reset the encoder. More...
 
void setOffset (int64_t offset)
 Set the current reading/writing offset. More...
 
DataReaderoperator>> (bool &v)
 Read operator. More...
 
DataReaderoperator>> (byte_t &v)
 Read operator. More...
 
DataReaderoperator>> (byte_t *v)
 Read operator. More...
 
DataReaderoperator>> (char &v)
 Read operator. More...
 
DataReaderoperator>> (char *v)
 Read operator. More...
 
DataReaderoperator>> (int16_t &v)
 Read operator. More...
 
DataReaderoperator>> (int16_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint16_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint16_t *v)
 Read operator. More...
 
DataReaderoperator>> (int32_t &v)
 Read operator. More...
 
DataReaderoperator>> (int32_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint32_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint32_t *v)
 Read operator. More...
 
DataReaderoperator>> (int64_t &v)
 Read operator. More...
 
DataReaderoperator>> (int64_t *v)
 Read operator. More...
 
DataReaderoperator>> (uint64_t &v)
 Read operator. More...
 
DataReaderoperator>> (uint64_t *v)
 Read operator. More...
 
DataReaderoperator>> (float &v)
 Read operator. More...
 
DataReaderoperator>> (float *v)
 Read operator. More...
 
DataReaderoperator>> (double &v)
 Read operator. More...
 
DataReaderoperator>> (double *v)
 Read operator. More...
 
DataReaderoperator>> (Blob &v)
 Read operator. More...
 
DataReaderoperator>> (String &v)
 Read operator. More...
 
DataReaderoperator>> (const Manipulator &manip)
 Read operator. More...
 
size_t readBytes (byte_t *buf, size_t len)
 Read raw bytes. More...
 
void readFully (byte_t *buf, size_t len)
 Read raw bytes, throwing an EOFException if the exact number of bytes requested could not be read. More...
 
void pushContext ()
 Push a new encoder context. More...
 
void popContext ()
 Pop the active encoder context. More...
 
bool isTopContext () const
 Determine if the active context is the topmost (and only) context. More...
 
uint_t getContextDepth () const
 Get the current context depth. More...
 
void setEndianness (Endianness endianness)
 Specify the byte-endianness for reading/writing primitive integer types in the active context. More...
 
Endianness getEndianness () const
 Get the byte-endianness in the active context. More...
 
void setLength (size_t length)
 Specify the length of String, Blob, and array values for subsequent reading/writing in the active context. More...
 
size_t getLength () const
 Get the current length for string values. More...
 
void setLimit (int64_t limit)
 Specify the maximum number of bytes that can be read/written in the active context. More...
 
int64_t getLimit () const
 Get the current limit. More...
 
int64_t getOffset () const
 Get the current encoding/decoding offset. More...
 
int64_t getCumulativeOffset () const
 Get the cumulative reading/writing offset. More...
 
int64_t getRemaining () const
 Get the number of bytes between the current offset and the limit, i.e., the number of bytes remaining to be read or written. More...
 
void align (size_t size)
 Skip past enough bytes to re-align the data stream at a specified boundary. More...
 

Static Public Attributes

static const size_t BUFFER_SIZE = 4096
 

Protected Member Functions

size_t read (byte_t *buf, size_t count)
 Read raw data from the input source. More...
 
virtual void readString (String &v, uint32_t length)
 Read a string from the input source. More...
 
bool isSameEndianness () const
 Test if the endianness of the encoder is the same as the endianness of the host system. More...
 
ContextcurrentContext ()
 Get a reference to the current context. More...
 
const ContextcurrentContext () const
 Get a reference to the current context. More...
 
void checkRemaining (const Context &ctx, size_t count) const
 Check if at least the given number of bytes are available to be read or written. More...
 

Detailed Description

A DataReader which reads data from a Stream.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ StreamDataReader()

StreamDataReader ( Stream stream,
size_t  bufferSize = BUFFER_SIZE 
)

Construct a new StreamDataReader for the given Stream.

Parameters
streamThe Stream to read data from.
bufferSizeThe stream buffer size.

◆ ~StreamDataReader()

Destructor.

Member Function Documentation

◆ align()

void align ( size_t  size)
inherited

Skip past enough bytes to re-align the data stream at a specified boundary.

When reading, the bytes are simply skipped over; when writing, the bytes are filled with NULs.

Parameters
sizeThe alignment size. Typical values include 2, 4, or 8. Other values are allowed but are of limited usefulness.
Exceptions
IOExceptionIf an I/O error occurs.

◆ checkRemaining()

void checkRemaining ( const Context ctx,
size_t  count 
) const
protectedinherited

Check if at least the given number of bytes are available to be read or written.

Parameters
ctxThe context to check.
countThe number of bytes.
Exceptions
IOExceptionIf there are not enough bytes remaining.

◆ currentContext() [1/2]

DataEncoder::Context & currentContext ( )
protectedinherited

Get a reference to the current context.

◆ currentContext() [2/2]

const DataEncoder::Context & currentContext ( ) const
protectedinherited

Get a reference to the current context.

◆ getContextDepth()

uint_t getContextDepth ( ) const
inherited

Get the current context depth.

◆ getCumulativeOffset()

int64_t getCumulativeOffset ( ) const
inherited

Get the cumulative reading/writing offset.

This is a sum of the offsets across all contexts.

◆ getEndianness()

Endianness getEndianness ( ) const
inherited

Get the byte-endianness in the active context.

◆ getLength()

size_t getLength ( ) const
inherited

Get the current length for string values.

◆ getLimit()

int64_t getLimit ( ) const
inherited

Get the current limit.

◆ getOffset()

int64_t getOffset ( ) const
inherited

Get the current encoding/decoding offset.

◆ getRemaining()

int64_t getRemaining ( ) const
inherited

Get the number of bytes between the current offset and the limit, i.e., the number of bytes remaining to be read or written.

◆ isSameEndianness()

bool isSameEndianness ( ) const
protectedinherited

Test if the endianness of the encoder is the same as the endianness of the host system.

◆ isTopContext()

bool isTopContext ( ) const
inherited

Determine if the active context is the topmost (and only) context.

◆ operator>>() [1/24]

DataReader & operator>> ( bool &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [2/24]

DataReader & operator>> ( byte_t v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [3/24]

DataReader & operator>> ( byte_t v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [4/24]

DataReader & operator>> ( char &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [5/24]

DataReader & operator>> ( char *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [6/24]

DataReader & operator>> ( int16_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [7/24]

DataReader & operator>> ( int16_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [8/24]

DataReader & operator>> ( uint16_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [9/24]

DataReader & operator>> ( uint16_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [10/24]

DataReader & operator>> ( int32_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [11/24]

DataReader & operator>> ( int32_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [12/24]

DataReader & operator>> ( uint32_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [13/24]

DataReader & operator>> ( uint32_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [14/24]

DataReader & operator>> ( int64_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [15/24]

DataReader & operator>> ( int64_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [16/24]

DataReader & operator>> ( uint64_t &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [17/24]

DataReader & operator>> ( uint64_t *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [18/24]

DataReader & operator>> ( float &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [19/24]

DataReader & operator>> ( float *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [20/24]

DataReader & operator>> ( double &  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [21/24]

DataReader & operator>> ( double *  v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [22/24]

DataReader & operator>> ( Blob v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [23/24]

DataReader & operator>> ( String v)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ operator>>() [24/24]

DataReader & operator>> ( const Manipulator manip)
inherited

Read operator.

Exceptions
IOExceptionIf an I/O error occurs.

◆ popContext()

void popContext ( )
inherited

Pop the active encoder context.

The previous context becomes the active context, and the offset in the current context is incremented by the offset of the popped context.

◆ pushContext()

void pushContext ( )
inherited

Push a new encoder context.

◆ read()

size_t read ( byte_t buf,
size_t  count 
)
protectedvirtual

Read raw data from the input source.

Parameters
bufThe buffer to read into.
countThe number of bytes to read.
Returns
The number of bytes actually read.
Exceptions
IOExceptionIf an I/O error occurs.

Implements DataReader.

◆ readBytes()

size_t readBytes ( byte_t buf,
size_t  len 
)
inherited

Read raw bytes.

The number of bytes read may be less than the number requested, if an end-of-file condition occurs.

Parameters
bufThe buffer in which to place the bytes.
lenThe maximum number of bytes to read.
Returns
The number of bytes actually read.
Exceptions
IOExceptionIf an I/O error occurs.

◆ readFully()

void readFully ( byte_t buf,
size_t  len 
)
inherited

Read raw bytes, throwing an EOFException if the exact number of bytes requested could not be read.

Parameters
bufThe buffer in which to place the bytes.
lenThe exact number of bytes to read.
Exceptions
IOExceptionIf an I/O error occurs.

◆ readString()

void readString ( String v,
uint32_t  length 
)
protectedvirtualinherited

Read a string from the input source.

Parameters
vThe String to read into.
lengthThe length of the string to read, or 0 to read a String that is preceded by a 32-bit length.
Exceptions
IOExceptionIf an I/O error occurs.

Reimplemented in CircularByteBufferDataReader.

◆ reset()

void reset ( )
virtual

Reset the encoder.

Discards all but the topmost context, and resets the topmost context to default values.

Exceptions
IOExceptionIf an I/O error occurs.

Reimplemented from DataEncoder.

◆ setEndianness()

void setEndianness ( Endianness  endianness)
inherited

Specify the byte-endianness for reading/writing primitive integer types in the active context.

◆ setLength()

void setLength ( size_t  length)
inherited

Specify the length of String, Blob, and array values for subsequent reading/writing in the active context.

◆ setLimit()

void setLimit ( int64_t  limit)
inherited

Specify the maximum number of bytes that can be read/written in the active context.

Attempts to read/write past this limit will raise an IOException.

Exceptions
IOExceptionIf an I/O error occurs.

◆ setOffset()

void setOffset ( int64_t  offset)
virtual

Set the current reading/writing offset.

Exceptions
IOExceptionIf an I/O error occurs.

Implements DataEncoder.

◆ skip()

void skip ( size_t  count)
virtual

Skip past the given number of bytes in the data stream.

When reading, the bytes are simply skipped over; when writing, the bytes are filled with NULs.

Parameters
countThe number of bytes to skip.
Exceptions
IOExceptionIf an I/O error occurs.

Implements DataEncoder.

Member Data Documentation

◆ BUFFER_SIZE

const size_t BUFFER_SIZE = 4096
static

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