NCBI C++ ToolKit
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
CUTTPReader Class Reference

Search Toolkit Book for CUTTPReader

Class for reading series of chunks sent by a CUTTPWriter instance as a stream of bytes. More...

#include <util/uttp.hpp>

+ Collaboration diagram for CUTTPReader:

Public Types

enum  EStreamParsingEvent {
  eChunkPart , eChunk , eControlSymbol , eNumber ,
  eEndOfBuffer , eFormatError
}
 Enumeration of the input stream parsing events. More...
 

Public Member Functions

 CUTTPReader ()
 Initialize the state machine of this object. More...
 
void Reset ()
 Reinitialize this object. More...
 
void SetOffset (off_t offset)
 Set offset of the current character in the input stream to the specified value. More...
 
off_t GetOffset () const
 Return the offset of the current character in the input stream. More...
 
void SetNewBuffer (const char *buffer, size_t buffer_size)
 Start processing of the next chunk of data. More...
 
EStreamParsingEvent GetNextEvent ()
 Parse the input buffer until a parsing event occurs. More...
 
EStreamParsingEvent ReadRawData (size_t data_size)
 Tell the reader to switch to reading raw data of the specified length. More...
 
char GetControlSymbol () const
 Return the control symbol that has been just read. More...
 
Int8 GetNumber () const
 Return the number that has been just read. More...
 
const char * GetChunkPart () const
 Return a pointer to the buffer that contains a part of the chunk currently being read. More...
 
size_t GetChunkPartSize () const
 Return the size of the buffer returned by the GetChunkPart() method. More...
 

Private Types

enum  EStreamParsingState { eReadControlChars , eReadNumber , eReadChunk }
 

Private Attributes

const char * m_Buffer
 
const char * m_ChunkPart
 
size_t m_BufferSize
 
size_t m_ChunkPartSize
 
off_t m_Offset
 
Int8 m_LengthAcc
 
EStreamParsingState m_State
 
bool m_ChunkContinued
 

Detailed Description

Class for reading series of chunks sent by a CUTTPWriter instance as a stream of bytes.

Objects of this class parse the input byte stream and notify the caller of parsing events.

See also
CUTTPWriter
Example:
Function names starting with ToDo:: are to be implemented by the client class.
bool ProcessParsingEvents(CUTTPReader& reader)
{
for (;;)
switch (reader.GetNextEvent()) {
ToDo::ProcessChunkPart(reader.GetChunkPart(),
reader.GetChunkPartSize());
break;
ToDo::ProcessChunk(reader.GetChunkPart(),
reader.GetChunkPartSize());
break;
ToDo::ProcessControlSymbol(reader.GetControlSymbol());
break;
return true;
default: // case CUTTPReader::eFormatError:
return false;
}
}
void Main()
{
CUTTPReader reader;
while (ToDo::ReadBuffer(buffer, &buffer_size)) {
reader.SetNewBuffer(buffer, buffer_size);
if (!ProcessParsingEvents(reader))
break;
}
}
Class for reading series of chunks sent by a CUTTPWriter instance as a stream of bytes.
Definition: uttp.hpp:94
EStreamParsingEvent GetNextEvent()
Parse the input buffer until a parsing event occurs.
Definition: uttp.cpp:44
char GetControlSymbol() const
Return the control symbol that has been just read.
Definition: uttp.hpp:249
@ eChunk
Notify that the last part of the chunk has been read.
Definition: uttp.hpp:107
@ eEndOfBuffer
Notify that the end of the input buffer has been reached.
Definition: uttp.hpp:120
@ eChunkPart
Notify that a part of a chunk has been read and can be fetched by a call to the GetChunkPart() method...
Definition: uttp.hpp:101
@ eControlSymbol
Notify that a control symbol has been read.
Definition: uttp.hpp:112
const char * GetChunkPart() const
Return a pointer to the buffer that contains a part of the chunk currently being read.
Definition: uttp.hpp:259
void SetNewBuffer(const char *buffer, size_t buffer_size)
Start processing of the next chunk of data.
Definition: uttp.hpp:242
size_t GetChunkPartSize() const
Return the size of the buffer returned by the GetChunkPart() method.
Definition: uttp.hpp:264
int Main(int argc, const char *argv[])
static uint8_t * buffer
Definition: pcre2test.c:1016

Definition at line 93 of file uttp.hpp.

Member Enumeration Documentation

◆ EStreamParsingEvent

Enumeration of the input stream parsing events.

Enumerator
eChunkPart 

Notify that a part of a chunk has been read and can be fetched by a call to the GetChunkPart() method.

eChunk 

Notify that the last part of the chunk has been read.

This event means that the chunk value can be assembled and interpreted now. Use the GetChunkPart() method to retrieve this final part of the chunk.

eControlSymbol 

Notify that a control symbol has been read.

Use the GetChunkPart() method to retrieve its value. Control symbols are always one character width so a call to GetChunkPartSize() will return 1.

eNumber 

Notify that a number has been read.

Use the GetNumber() method to retrieve its value.

eEndOfBuffer 

Notify that the end of the input buffer has been reached.

New buffer processing can be started now by calling SetNewBuffer().

eFormatError 

Indicate a format error in the input stream.

It is advised to stop processing upon receiving this event. A subsequent call to GetChunkPart() will return the position in the input buffer at which the error has occured. A call to GetChunkPartSize() will return the accumulated length of the expected chunk, if any. Note that these two values are not related.

Definition at line 98 of file uttp.hpp.

◆ EStreamParsingState

Enumerator
eReadControlChars 
eReadNumber 
eReadChunk 

Definition at line 206 of file uttp.hpp.

Constructor & Destructor Documentation

◆ CUTTPReader()

CUTTPReader::CUTTPReader ( )
inline

Initialize the state machine of this object.

Definition at line 221 of file uttp.hpp.

Member Function Documentation

◆ GetChunkPart()

const char * CUTTPReader::GetChunkPart ( ) const
inline

Return a pointer to the buffer that contains a part of the chunk currently being read.

Note that this buffer is not zero-terminated. Use the GetChunkPartSize() method to retrieve the length of this buffer. The returned value is only valid after a successful call to the GetNextEvent() method, that is, when this call returned either eChunkPart or eChunk.

Returns
A pointer to the inside part of the buffer passed as an argument to the SetNewBuffer() method.

Definition at line 259 of file uttp.hpp.

References m_ChunkPart.

Referenced by CJsonOverUTTPReader::ReadMessage(), and CNetStorageHandler::x_ReadRawData().

◆ GetChunkPartSize()

size_t CUTTPReader::GetChunkPartSize ( ) const
inline

Return the size of the buffer returned by the GetChunkPart() method.

The returned value is only valid after a successful call to the GetNextEvent() method.

Returns
Size of the buffer returned by a call to the GetChunkPart() method.

Definition at line 264 of file uttp.hpp.

References m_ChunkPartSize.

Referenced by CJsonOverUTTPReader::ReadMessage(), and CNetStorageHandler::x_ReadRawData().

◆ GetControlSymbol()

char CUTTPReader::GetControlSymbol ( ) const
inline

Return the control symbol that has been just read.

The returned value is only valid after a successful call to the GetNextEvent() method, that is, when it returned eControlSymbol.

Definition at line 249 of file uttp.hpp.

References m_ChunkPart.

Referenced by SNetStorageObjectRPC::SIState::ReadConfirmation(), CJsonOverUTTPReader::ReadMessage(), and CNetStorageHandler::x_ReadRawData().

◆ GetNextEvent()

CUTTPReader::EStreamParsingEvent CUTTPReader::GetNextEvent ( )

◆ GetNumber()

Int8 CUTTPReader::GetNumber ( void  ) const
inline

Return the number that has been just read.

The value is only valid when the preceding call to GetNextEvent() returned eNumber. GetChunkPartSize() is not applicable for this event.

Definition at line 254 of file uttp.hpp.

References m_LengthAcc.

Referenced by CJsonOverUTTPReader::ReadMessage().

◆ GetOffset()

off_t CUTTPReader::GetOffset ( void  ) const
inline

Return the offset of the current character in the input stream.

Returns
The current character offset.

Definition at line 237 of file uttp.hpp.

References m_Offset.

◆ ReadRawData()

CUTTPReader::EStreamParsingEvent CUTTPReader::ReadRawData ( size_t  data_size)

Tell the reader to switch to reading raw data of the specified length.

Parameters
data_sizeExpected raw data size.
Returns
One of the following three constants: eChunkPart, eChunk, or eEndOfBuffer.

Definition at line 134 of file uttp.cpp.

References _ASSERT, eChunk, eChunkPart, eEndOfBuffer, eReadChunk, eReadControlChars, m_Buffer, m_BufferSize, m_ChunkContinued, m_ChunkPart, m_ChunkPartSize, m_LengthAcc, m_Offset, and m_State.

Referenced by CJsonOverUTTPReader::ReadMessage().

◆ Reset()

void CUTTPReader::Reset ( void  )
inline

Reinitialize this object.

Definition at line 226 of file uttp.hpp.

References eReadControlChars, m_Offset, and m_State.

◆ SetNewBuffer()

void CUTTPReader::SetNewBuffer ( const char *  buffer,
size_t  buffer_size 
)
inline

Start processing of the next chunk of data.

Parameters
bufferA pointer to the next chunk of data from the stream.
buffer_sizeThe size of the above chunk in bytes.

Definition at line 242 of file uttp.hpp.

References buffer, m_Buffer, and m_BufferSize.

Referenced by CGridCommandLineInterfaceApp::Automation_PipeServer(), CNetStorageHandler::OnRead(), and s_ReadSocket().

◆ SetOffset()

void CUTTPReader::SetOffset ( off_t  offset)
inline

Set offset of the current character in the input stream to the specified value.

Parameters
offsetThe new value for the current character offset.

Definition at line 232 of file uttp.hpp.

References m_Offset, and offset.

Member Data Documentation

◆ m_Buffer

const char* CUTTPReader::m_Buffer
private

Definition at line 212 of file uttp.hpp.

Referenced by GetNextEvent(), ReadRawData(), and SetNewBuffer().

◆ m_BufferSize

size_t CUTTPReader::m_BufferSize
private

Definition at line 213 of file uttp.hpp.

Referenced by GetNextEvent(), ReadRawData(), and SetNewBuffer().

◆ m_ChunkContinued

bool CUTTPReader::m_ChunkContinued
private

Definition at line 218 of file uttp.hpp.

Referenced by GetNextEvent(), and ReadRawData().

◆ m_ChunkPart

const char * CUTTPReader::m_ChunkPart
private

Definition at line 212 of file uttp.hpp.

Referenced by GetChunkPart(), GetControlSymbol(), GetNextEvent(), and ReadRawData().

◆ m_ChunkPartSize

size_t CUTTPReader::m_ChunkPartSize
private

Definition at line 213 of file uttp.hpp.

Referenced by GetChunkPartSize(), GetNextEvent(), and ReadRawData().

◆ m_LengthAcc

Int8 CUTTPReader::m_LengthAcc
private

Definition at line 216 of file uttp.hpp.

Referenced by GetNextEvent(), GetNumber(), and ReadRawData().

◆ m_Offset

off_t CUTTPReader::m_Offset
private

Definition at line 214 of file uttp.hpp.

Referenced by GetNextEvent(), GetOffset(), ReadRawData(), Reset(), and SetOffset().

◆ m_State

EStreamParsingState CUTTPReader::m_State
private

Definition at line 217 of file uttp.hpp.

Referenced by GetNextEvent(), ReadRawData(), and Reset().


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:58:07 2024 by modify_doxy.py rev. 669887