ostinato/rpc/pbqtio.h
Srivats P. 90fda499dd RPC now uses stream instead of an array for protobuf parsing and serialization. This change removes the limit on the byte size of a protobuf.
Because we are now using a new protobuf API - ParseFromBoundedZeroCopyStream(), the protobuf version has to be >= 2.2.0

Fixes issue 14
2010-10-18 17:25:27 +05:30

43 lines
965 B
C++

#ifndef _PBQTIO_H
#define _PBQTIO_H
#include <google/protobuf/io/zero_copy_stream_impl.h>
class PbQtInputStream : public google::protobuf::io::CopyingInputStream
{
public:
PbQtInputStream(QIODevice *dev)
: dev_(dev) {};
int Read(void *buffer, int size) {
_top:
if (dev_->bytesAvailable())
return dev_->read(static_cast<char*>(buffer), size);
else
if (dev_->waitForReadyRead(-1))
goto _top;
else
return -1; //return dev_->atEnd() ? 0 : -1;
}
private:
QIODevice *dev_;
};
class PbQtOutputStream : public google::protobuf::io::CopyingOutputStream
{
public:
PbQtOutputStream(QIODevice *dev)
: dev_(dev) {};
bool Write(const void *buffer, int size) {
if (dev_->write(static_cast<const char*>(buffer), size) == size)
return true;
else
return false;
}
private:
QIODevice *dev_;
};
#endif