Files
pip/src_main/core/pichunkstream.cpp

56 lines
1.7 KiB
C++

#include "pichunkstream.h"
/*! \class PIChunkStream
* \brief Class for binary serialization
*
* \section PIChunkStream_sec0 Synopsis
* This class provides very handly mechanism to store and restore values to and from
* \a PIByteArray. The main advantage of using this class is that your binary data
* become independent from order and collection of your values.
*
* \section PIChunkStream_sec1 Mechanism
* %PIChunkStream works with items called "chunk". Chunk is an ID and any value that
* can be stored and restored to \a PIByteArray with stream operators << and >>.
* You can place chunks to stream and read chunks from stream.
*
* To construct %PIChunkStream for writing data use any constructor. Empty constructor
* creates internal empty buffer that can be accessed by function \a data().
* Non-empty constructor works with given byte array.
*
* To read chunks from byte array use function \a read() that returns ID of
* next chunk. Then you can get value of this chunk with function \a getData(),
* but you should definitely know type of this value. You can read from byte array
* while \a atEnd() if false.
*
* \section PIChunkStream_ex0 Example
* Prepare your structs to work with %PIChunkStream
* \snippet pichunkstream.cpp struct
* Writing to %PIChunkStream
* \snippet pichunkstream.cpp write
* Reading from %PIChunkStream
* \snippet pichunkstream.cpp read
*/
void PIChunkStream::setSource(const PIByteArray & data) {
data_ = const_cast<PIByteArray*>(&data);
_init();
}
void PIChunkStream::setSource(PIByteArray * data) {
data_ = (data ? data : &tmp_data);
_init();
}
PIChunkStream::~PIChunkStream() {
}
void PIChunkStream::_init() {
last_id = -1;
last_data.clear();
}