A QDataStream is almost certainly not the tool for the job. Assuming that the I/O has to be Qt then get the data into a QByteArray directly from the underlying QIODevice (socket, file, whatever) and then use some generic C++ code to make an in-memory buffer for a std::istream sub-class. Something like this example from Stack Overflow:
#include <streambuf>
#include <istream>
struct membuf: std::streambuf {
membuf(char const* base, size_t size) {
char* p(const_cast<char*>(base));
this->setg(p, p, p + size);
}
};
struct imemstream: virtual membuf, std::istream {
imemstream(char const* base, size_t size)
: membuf(base, size)
, std::istream(static_cast<std::streambuf*>(this)) {
}
};
#include <streambuf>
#include <istream>
struct membuf: std::streambuf {
membuf(char const* base, size_t size) {
char* p(const_cast<char*>(base));
this->setg(p, p, p + size);
}
};
struct imemstream: virtual membuf, std::istream {
imemstream(char const* base, size_t size)
: membuf(base, size)
, std::istream(static_cast<std::streambuf*>(this)) {
}
};
To copy to clipboard, switch view to plain text mode
In your Qt code:
QByteArray buffer;
// << contains the data from whatever source imemstream stream(buffer.constData(), buffer.size());
// Pass &stream to the Google ParseFromIstream(istream* input) function.
// Be careful of object lifetime: buffer has to stay in existence until the parse is complete
QByteArray buffer; // << contains the data from whatever source
imemstream stream(buffer.constData(), buffer.size());
// Pass &stream to the Google ParseFromIstream(istream* input) function.
// Be careful of object lifetime: buffer has to stay in existence until the parse is complete
To copy to clipboard, switch view to plain text mode
Bookmarks