Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cStreamInput Class Reference

#include <cStream.h>

Inheritance diagram for Gray::cStreamInput:
Gray::cStreamBase Gray::cStream GrayLib::cMailslotReader GrayLib::cOSPipeServer GrayLib::cWaveStreamIn Gray::cFile Gray::cStreamNull Gray::cStreamQueue Gray::cStreamStatic GrayLib::cNetSocket GrayLib::cNetStream GrayLib::cNetTOP GrayLib::cSerialPort GraySSL::cSSLCommon

Public Member Functions

 cStreamInput () noexcept
 
virtual ~cStreamInput ()
 
virtual size_t SetSeekSizeMin (size_t nSizeMin=k_FILE_BLOCK_SIZE)
 
virtual HRESULT ReadX (OUT void *pData, size_t nDataSize)
 
HRESULT ReadAll (OUT cHeapBlock &block, size_t nSizeExtra=0)
 
virtual HRESULT ReadStringLine (OUT char *pszBuffer, StrLen_t iSizeMax)
 
virtual HRESULT ReadStringLine (OUT wchar_t *pszBuffer, StrLen_t iSizeMax)
 
HRESULT ReadT (OUT void *pVal, size_t nSize)
 
template<typename TYPE >
HRESULT ReadT (OUT TYPE &val)
 
template<typename TYPE >
HRESULT ReadTN (OUT TYPE &val)
 
HRESULT ReadSize (OUT size_t &nSize)
 
template<typename TYPE >
HRESULT ReadSizeT (OUT TYPE &n)
 
HRESULT ReadHashCode (OUT UINT32 &nHashCode)
 
HRESULT ReadHashCode (OUT UINT64 &nHashCode)
 
HRESULT ReadN (OUT BYTE *pBuffer, size_t nSizeMax)
 
template<typename _CH >
HRESULT ReadStringN (OUT _CH *pszStr, StrLen_t iSizeMax)
 
virtual HRESULT ReadPeek (void *pData, size_t nDataSize)
 
- Public Member Functions inherited from Gray::cStreamBase
virtual ~cStreamBase ()
 
virtual STREAM_SEEKRET_t Seek (STREAM_OFFSET_t iOffset, SEEK_ORIGIN_TYPE eSeekOrigin=SEEK_Set)
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
virtual STREAM_POS_t GetPosition () const
 
virtual STREAM_POS_t GetLength () const
 

Additional Inherited Members

- Static Public Attributes inherited from Gray::cStreamBase
static const BYTE k_SIZE_MASK = 0x80
 Used for WriteSize() More...
 
static const size_t k_FILE_BLOCK_SIZE = (32 * 1024)
 default arbitrary transfer block size. more than this is NOT more efficient. More...
 

Detailed Description

Generic input stream of data.

Note
Seek() not always available from this interface. ReadX(nullptr) = skip over but not true seek.

Constructor & Destructor Documentation

◆ cStreamInput()

Gray::cStreamInput::cStreamInput ( )
inlinenoexcept

◆ ~cStreamInput()

virtual Gray::cStreamInput::~cStreamInput ( )
inlinevirtual

Member Function Documentation

◆ ReadAll()

HRESULT Gray::cStreamInput::ReadAll ( OUT cHeapBlock block,
size_t  nSizeExtra = 0 
)
inline

Read the whole stream as a single allocated block in memory.

  • nSizeExtra = extra memory allocation.
    Returns
    length read. (Not including nSizeExtra). or < 0 = error.

◆ ReadHashCode() [1/2]

HRESULT Gray::cStreamInput::ReadHashCode ( OUT UINT32 &  nHashCode)
inline

◆ ReadHashCode() [2/2]

HRESULT Gray::cStreamInput::ReadHashCode ( OUT UINT64 &  nHashCode)
inline

◆ ReadN()

HRESULT Gray::cStreamInput::ReadN ( OUT BYTE *  pBuffer,
size_t  nSizeMax 
)
inline

Read a block with a leading size field.

Returns
>= 0 = actual size read.

◆ ReadPeek()

HRESULT Gray::cStreamInput::ReadPeek ( void *  pData,
size_t  nDataSize 
)
virtual

Peek ahead in the stream if possible. Non blocking. just try to read data but not remove from the queue.

Returns
Amount peeked.

Reimplemented in GrayLib::cNetSocket, Gray::cStreamStatic, and Gray::cStreamQueue.

◆ ReadSize()

HRESULT Gray::cStreamInput::ReadSize ( OUT size_t &  nSize)

Packed low to high values. Read a packed (variable length) unsigned size. <0 = error; Bit 7 reserved to indicate more bytes to come. opposite of WriteSize( size_t ) similar to ASN1 Length packing.

Returns
HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = no more data.

◆ ReadSizeT()

template<typename TYPE >
HRESULT Gray::cStreamInput::ReadSizeT ( OUT TYPE n)
inline

◆ ReadStringLine() [1/2]

HRESULT Gray::cStreamInput::ReadStringLine ( OUT char *  pszBuffer,
StrLen_t  iSizeMax 
)
virtual

Read a string up until (including) a "\n" or "\r\n". end of line. FILE_EOL. Some streams can support this better than others. like fgets(FILE*)

  • iSizeMax = Maximum number of characters to be copied into pszBuffer (including room for the the terminating '\0' character).
    Returns
    >= 0 = size of the string in characters not bytes. NOT pointer to pBuffer like fgets() HRESULT < 0 = error. HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = not full line.

Reimplemented in Gray::cStreamTextReader.

◆ ReadStringLine() [2/2]

HRESULT Gray::cStreamInput::ReadStringLine ( OUT wchar_t *  pszBuffer,
StrLen_t  iSizeMax 
)
virtual

Read a string up until (including) a "\n" or "\r\n". end of line. FILE_EOL. Some streams can support this better than others. like fgets(FILE*).

  • iSizeMax = Maximum number of characters to be copied into str (including the terminating null-character).
    Returns
    >= 0 = size of the string in characters not bytes. NOT pointer to pBuffer like fgets() HRESULT < 0 = error.

◆ ReadStringN()

template<typename _CH >
HRESULT Gray::cStreamInput::ReadStringN ( OUT _CH *  pszStr,
StrLen_t  iSizeMax 
)
inline

Read a string that is prefixed by its size. iSizeMax = _countof(pszStr), includes space for '\0'. e.g. _countof("abc") = 4

Returns
The size of the string (in chars) + including '\0'. HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = need more data.

◆ ReadT() [1/2]

template<typename TYPE >
HRESULT Gray::cStreamInput::ReadT ( OUT TYPE val)

◆ ReadT() [2/2]

HRESULT Gray::cStreamInput::ReadT ( OUT void *  pVal,
size_t  nSize 
)
inline

Read all nSize or fail HRESULT_WIN32_C(ERROR_IO_INCOMPLETE).

Returns
>= 0 = actual size read. or < 0 = error HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = need more data.

◆ ReadTN()

template<typename TYPE >
HRESULT Gray::cStreamInput::ReadTN ( OUT TYPE val)
inline

Read a type value in network order. convert to host order.

◆ ReadX()

virtual HRESULT Gray::cStreamInput::ReadX ( OUT void *  pData,
size_t  nDataSize 
)
inlinevirtual

Just read a block from the stream. // must support this. Similar to MFC CFile::Read()

Reimplemented in GraySSL::cSSLCommon.

◆ SetSeekSizeMin()

virtual size_t Gray::cStreamInput::SetSeekSizeMin ( size_t  nSizeMin = k_FILE_BLOCK_SIZE)
inlinevirtual

similar to ReadCommit (put_AutoReadCommitSize) size. Used by cStreamTransaction. Leave a certain amount of data (max message size for current protocol) such that we could Seek() back for incomplete messages.

  • nSizeMin = 0 = don't commit/lost any data until we have a complete message/block.

Reimplemented in GraySSL::cSSLCommon, GrayLib::cNetStream, Gray::cStreamQueue, and Gray::cStreamStatic.


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