Easy Simple Network Library  0.3.7
All Classes Functions Modules
Public Types | Public Member Functions | List of all members
esnlib::MessageCodec Class Reference

Common Message Codec Filter class, a filter who can extract a common message(format: header + body) from incoming bytes. More...

#include <MessageCodec.h>

Inheritance diagram for esnlib::MessageCodec:
esnlib::IoFilter

Public Types

enum  { STATE_WAIT_FOR_HEADER = 0, STATE_WAIT_FOR_BODY = 1 }
 

Public Member Functions

 MessageCodec ()
 Constructor function.
 
 MessageCodec (int headerSize)
 
 MessageCodec (int headerSize, int bodySizePos)
 
 MessageCodec (int headerSize, int bodySizePos, int bodySizeLength)
 
 MessageCodec (int headerSize, int bodySizePos, int bodySizeLength, int maxBodySize)
 
virtual ~MessageCodec ()
 Destructor function.
 
virtual bool Extract (SessionPtr session, IoBufferPtr data, std::vector< IoBufferPtr > &readylist)
 
virtual IoBufferPtr Encode (SessionPtr session, void *data)
 
virtual void * Decode (SessionPtr session, IoBufferPtr data)
 

Detailed Description

Common Message Codec Filter class, a filter who can extract a common message(format: header + body) from incoming bytes.

Constructor & Destructor Documentation

esnlib::MessageCodec::MessageCodec ( int  headerSize)
explicit

Constructor function

Parameters
headerSizeThe size(how many bytes) of the message header
esnlib::MessageCodec::MessageCodec ( int  headerSize,
int  bodySizePos 
)

Constructor function

Parameters
headerSizeThe size(how many bytes) of the message header
bodySizePosAn integer value's position in the message header, this value is the size of the message body
esnlib::MessageCodec::MessageCodec ( int  headerSize,
int  bodySizePos,
int  bodySizeLength 
)

Constructor function

Parameters
headerSizeThe size(how many bytes) of the message header
bodySizePosA value's position in the message header, this value is the size of the message body
bodySizeLengthHow many bytes does the value (which indicates the size of the message body) have
esnlib::MessageCodec::MessageCodec ( int  headerSize,
int  bodySizePos,
int  bodySizeLength,
int  maxBodySize 
)

Constructor function

Parameters
headerSizeThe size(how many bytes) of the message header
bodySizePosA value's position in the message header, this value is the size of the message body
bodySizeLengthHow many bytes does the value (which indicates the size of the message body) have
maxBodySizeThe maximum body size

Member Function Documentation

virtual void* esnlib::MessageCodec::Decode ( SessionPtr  session,
IoBufferPtr  data 
)
virtual

Decode the IO buffer

Parameters
sessionCurrent session
dataThe pointer of the IO buffer encoded
Returns
The original raw buffer (a common pointer)

Implements esnlib::IoFilter.

virtual IoBufferPtr esnlib::MessageCodec::Encode ( SessionPtr  session,
void *  data 
)
virtual

Encode the raw buffer

Parameters
sessionCurrent session
dataThe pointer of the raw buffer
Returns
The pointer of the IO buffer encoded

Implements esnlib::IoFilter.

virtual bool esnlib::MessageCodec::Extract ( SessionPtr  session,
IoBufferPtr  data,
std::vector< IoBufferPtr > &  readylist 
)
virtual

Extract useful data (the message made up of header and body) from the incoming bytes

Parameters
sessionCurrent session
dataThe pointer of the incoming bytes
readylistThe list used to save the useful data extracted
Returns
Return true if some useful data has been extracted successfully

Implements esnlib::IoFilter.


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