MCS
0.3.3-alpha7
|
Serialize memory buffers or files into chunks. More...
#include <mcs.hh>
Public Member Functions | |
void * | getEntireBuffer (unsigned int &size) |
bool | knowSize () |
Reinitialize internal data. More... | |
unsigned int | maxChunkSize () |
Return the max size allowed for a chunk. More... | |
unsigned int | nChunk () |
If knowSize() is true, return how many chunks are required to send all data. More... | |
void * | nextChunk (unsigned int &chunksize) |
Fills a buffer with next chunk to be sent. More... | |
Serializable & | operator= (const Serializable &) |
Declared to avoid using of default assignment operator. More... | |
Serializable (const Serializable &) | |
Declared to avoid using of default copy constructor. More... | |
Serializable (unsigned int lmaxChunksize=16384) | |
Constructor, for custom data (type = SERIAL_UNKNOWN). More... | |
Serializable (void *from, unsigned int size, bool freeAfterUse, unsigned int lmaxChunksize=16384) | |
Constructor, for memory buffers (type = SERIAL_BUFFER). More... | |
Serializable (string filename, unsigned int lmaxChunksize=16384) | |
Constructor, for files (type = SERIAL_FILENAME). More... | |
Serializable (int type, unsigned int lmaxChunksize=16384) | |
unsigned int | size () |
If knowSize() is true, return the size of the entire block of data. More... | |
virtual | ~Serializable () |
Destructor. More... | |
Private Member Functions | |
void | init (int type, unsigned int lmaxChunksize) |
Common initialization. More... | |
virtual char * | nextChunk_unknown (char *userdata, char *buf, unsigned int &chunksize, bool firstTime) |
Custom routine to fill a buffer with a chunk. More... | |
void | serialize () |
virtual bool | serialize_buffer (char *&from, unsigned int &size) |
void | serialize_end () |
virtual string | serialize_filename () |
virtual char * | serialize_unknown () |
Private Attributes | |
char * | buf |
Pointer to temporary buffer containing the next chunk. More... | |
string | filename |
Filename of the file being sent, if type = MCS_SERIAL_FILENAME. More... | |
bool | firstTime |
bool | freeAfterUse |
If true the external buffer will be automatically freed, used when type = MCS_SERIAL_BUFFER. More... | |
char * | from |
Pointer to source buffer, if type = MCS_SERIAL_BUFFER. More... | |
unsigned int | lsize |
Size of the actual chunk. More... | |
unsigned int | maxChunksize |
Maximum size of the chunk. More... | |
MCS_DEBUG_ALLOC | |
ifstream * | stream |
Pointer to an ifstream, if type = MCS_SERIAL_FILENAME. More... | |
int | type |
Type of data to be sent. More... | |
char * | userdata |
Serialize memory buffers or files into chunks.
This class is used from the Socket class to split data buffers into chunks of a maximum size, so they can be sent across the network. Objects that must be sent through the network must derive this class and eventually implement its virtual methods.
Chunks are extracted from the source using the serialize_buffer() virtual method.
This class has an internal type specification which is used to determine how to retrieve data, this specification can be one of MCS_SERIAL_BUFFER (for memory buffers), MCS_SERIAL_FILENAME (for files) and MCS_SERIAL_UNKNOWN (for custom data). In this last case the user must implement the serialize_unknown() and nextChunk_unknown() virtual methods to properly read data into the internal buffer.
mcs::Serializable::Serializable | ( | const Serializable & | ) |
Declared to avoid using of default copy constructor.
mcs::Serializable::Serializable | ( | unsigned int | lmaxChunksize = 16384 | ) |
Constructor, for custom data (type = SERIAL_UNKNOWN).
lmaxChunksize | Max allowed size for a chunk, default is MCS_CHUNKSIZE bytes. |
Definition at line 59 of file Serializable.cc.
mcs::Serializable::Serializable | ( | void * | from, |
unsigned int | size, | ||
bool | freeAfterUse, | ||
unsigned int | lmaxChunksize = 16384 |
||
) |
Constructor, for memory buffers (type = SERIAL_BUFFER).
buf | Address of the buffer containing data to be sent. |
size | Size of the buffer. |
lmaxChunksize | Max allowed size for a chunk, default is MCS_CHUNKSIZE. |
Definition at line 64 of file Serializable.cc.
mcs::Serializable::Serializable | ( | string | filename, |
unsigned int | lmaxChunksize = 16384 |
||
) |
Constructor, for files (type = SERIAL_FILENAME).
filename | File to be sent. |
lmaxChunksize | Max allowed size for a chunk, default is MCS_CHUNKSIZE. |
Definition at line 74 of file Serializable.cc.
|
virtual |
Destructor.
Definition at line 88 of file Serializable.cc.
|
private |
Common initialization.
lmaxChunksize | Max allowed size for a chunk. |
Definition at line 31 of file Serializable.cc.
bool mcs::Serializable::knowSize | ( | ) |
Reinitialize internal data.
Reinitialize internal data, so that next call to fillBuffer() will read data from the beginning of the buffer or the file. If type = SERIAL_UNKNOWN the next call to fillBuffer will have firstTime = true.
Tells if the object is in use.
If a call to fillBuffer() has already be done, and data are not yet finished this will return true. Otherwise return false.
Tells if we already know the size of entire block of data.
If type = SERIAL_FILENAME or SERIAL_BUFFER, we already know the size of the entire block of data, and this return true. If type = SERIAL_UNKNOWN return false.
Definition at line 232 of file Serializable.cc.
unsigned int mcs::Serializable::maxChunkSize | ( | ) |
Return the max size allowed for a chunk.
Definition at line 251 of file Serializable.cc.
unsigned int mcs::Serializable::nChunk | ( | ) |
If knowSize() is true, return how many chunks are required to send all data.
Definition at line 237 of file Serializable.cc.
void * mcs::Serializable::nextChunk | ( | unsigned int & | chunksize | ) |
Fills a buffer with next chunk to be sent.
chunksize | Upon exit contains the size of the chunk. |
Definition at line 169 of file Serializable.cc.
|
privatevirtual |
Custom routine to fill a buffer with a chunk.
This virtual method should be overloadd in derived class, to fill the internal buffer when type = SERIAL_UNKNOWN. This method is called automatically by fillBuffer().
buf | Address of the buffer to fill with the chunk. |
chunksize | Upon exit must contain the size of the chunk. |
firstTime | Tell if it is the first time the method is called. |
Definition at line 93 of file Serializable.cc.
Serializable& mcs::Serializable::operator= | ( | const Serializable & | ) |
Declared to avoid using of default assignment operator.
unsigned int mcs::Serializable::size | ( | ) |
If knowSize() is true, return the size of the entire block of data.
Definition at line 245 of file Serializable.cc.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha7
|