NCBI C++ ToolKit
|
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>
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 |
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.
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. |
|
private |
|
inline |
|
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.
Definition at line 259 of file uttp.hpp.
References m_ChunkPart.
Referenced by CJsonOverUTTPReader::ReadMessage(), and CNetStorageHandler::x_ReadRawData().
|
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.
Definition at line 264 of file uttp.hpp.
References m_ChunkPartSize.
Referenced by CJsonOverUTTPReader::ReadMessage(), and CNetStorageHandler::x_ReadRawData().
|
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().
CUTTPReader::EStreamParsingEvent CUTTPReader::GetNextEvent | ( | ) |
Parse the input buffer until a parsing event occurs.
Definition at line 44 of file uttp.cpp.
References eChunk, eChunkPart, eControlSymbol, eEndOfBuffer, eFormatError, eNumber, eReadChunk, eReadControlChars, eReadNumber, m_Buffer, m_BufferSize, m_ChunkContinued, m_ChunkPart, m_ChunkPartSize, m_LengthAcc, m_Offset, and m_State.
Referenced by SNetStorageObjectRPC::SIState::ReadConfirmation(), CJsonOverUTTPReader::ReadMessage(), s_ReadMessage(), and CNetStorageHandler::x_ReadRawData().
|
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().
|
inline |
CUTTPReader::EStreamParsingEvent CUTTPReader::ReadRawData | ( | size_t | data_size | ) |
Tell the reader to switch to reading raw data of the specified length.
data_size | Expected raw data size. |
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().
|
inline |
Reinitialize this object.
Definition at line 226 of file uttp.hpp.
References eReadControlChars, m_Offset, and m_State.
|
inline |
Start processing of the next chunk of data.
buffer | A pointer to the next chunk of data from the stream. |
buffer_size | The 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().
|
inline |
|
private |
Definition at line 212 of file uttp.hpp.
Referenced by GetNextEvent(), ReadRawData(), and SetNewBuffer().
|
private |
Definition at line 213 of file uttp.hpp.
Referenced by GetNextEvent(), ReadRawData(), and SetNewBuffer().
|
private |
Definition at line 218 of file uttp.hpp.
Referenced by GetNextEvent(), and ReadRawData().
|
private |
Definition at line 212 of file uttp.hpp.
Referenced by GetChunkPart(), GetControlSymbol(), GetNextEvent(), and ReadRawData().
|
private |
Definition at line 213 of file uttp.hpp.
Referenced by GetChunkPartSize(), GetNextEvent(), and ReadRawData().
|
private |
Definition at line 216 of file uttp.hpp.
Referenced by GetNextEvent(), GetNumber(), and ReadRawData().
|
private |
Definition at line 214 of file uttp.hpp.
Referenced by GetNextEvent(), GetOffset(), ReadRawData(), Reset(), and SetOffset().
|
private |
Definition at line 217 of file uttp.hpp.
Referenced by GetNextEvent(), ReadRawData(), and Reset().