ProtoStream reviewed

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1270 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
hellwig
2012-05-24 12:03:23 +00:00
parent 03d8688241
commit c5848a9c6d
2 changed files with 67 additions and 59 deletions

View File

@ -1,3 +1,17 @@
/** brief One way to manage large protobuf-messages
*
* Google protobuf is not designed for large messages.
* That leads to much memory which is consumed by processing large
* messages. To solve this problem the ProtoStream class stores the
* protobuf-messages in an other way.
* Instead of using the repeat-function the data is written
* sequentially in a file.
* Written in the format:
* |4 bytes length-information of the first message | first message
* |4 bytes length-information of the second message| second message
* | ...
*/
#ifndef __PROTOSTREAM_HPP__
#define __PROTOSTREAM_HPP__
@ -11,34 +25,22 @@
using namespace std;
/**
* \class ProtoStream
* \class ProtoOStream
*
*
* \brief One way to manage large protobuf-messages
*
* Google protobuf is not designed for large messages.
* That leads to much memory which is consumed by processing large messages.
* To solve this problem the ProtoStream class stores the protobuf-messages in an other way.
* Instead of using the repeat-function the data is written sequentially in a file.
* Written in the format:
* |4 bytes length-information of the first message| first message | 4 bytes length-information of second message | second message | ...
* This class can be used to write messages in a file.
*
*/
class ProtoStream
class ProtoOStream
{
private:
bool m_write_mode;
uint32_t m_size;
Logger m_log;
ostream* m_outfile;
istream* m_infile;
public:
ProtoStream(ostream * outfile);
ProtoStream(istream * infile);
virtual ~ProtoStream() {};
ProtoOStream(ostream * outfile);
virtual ~ProtoOStream() {};
/**
* Writes a message to a file.
* This works only if the constructor was called wit a pointer
@ -47,14 +49,35 @@ class ProtoStream
* @return Returns true if data was written.
*/
bool writeMessage(google::protobuf::Message* m);
};
/**
* \class ProtoIStream
*
* This class can be used to read messages sequentially from a file.
*
*/
class ProtoIStream
{
private:
uint32_t m_size;
long m_sizeOfInfile;
Logger m_log;
istream* m_infile;
public:
ProtoIStream(istream * infile);
virtual ~ProtoIStream() {};
/**
* Resets the position of the get pointer. After that getNext
* delivers the first message again.
* This works only if the constructor was called wit a pointer
* of an istream.
* @return Returns true if the pointer is reset.
*/
bool reset();
void reset();
/**
* Delivers the protobuf-messages sequentially from file.
* This works only if the constructor was called wit a pointer