Hi,
Flash 10, action script 4 sends strings this way:
int16 describing size
then char * data.
To my knowledge, this type of string is not serialized in QT.
so i made this class:
{
public:
QString ReadUTF8
(qint16 maxsize
= 4096) {
Q_ASSERT(maxsize <= 4096);
static char buffer[4096];
qint16 stringlength;
(*this) >> stringlength;
if (stringlength < maxsize)
{
readRawData(&buffer[0] , stringlength);
}
return QString::fromAscii(buffer, stringlength
);
}
{
(*this) << data.size();
writeRawData((char*)data.data(), data.size());
}
class FlashDataStream : public QDataStream
{
public:
FlashDataStream () : QDataStream() {}
FlashDataStream ( QIODevice * d ) : QDataStream(d) {}
FlashDataStream ( QByteArray * a, QIODevice::OpenMode mode ) : QDataStream(a, mode) {}
FlashDataStream ( const QByteArray & a ) : QDataStream (a ) {}
QString ReadUTF8(qint16 maxsize = 4096)
{
Q_ASSERT(maxsize <= 4096);
static char buffer[4096];
qint16 stringlength;
(*this) >> stringlength;
if (stringlength < maxsize)
{
readRawData(&buffer[0] , stringlength);
}
return QString::fromAscii(buffer, stringlength);
}
void WriteUTF8(QString data)
{
(*this) << data.size();
writeRawData((char*)data.data(), data.size());
}
To copy to clipboard, switch view to plain text mode
Now, my question is; There has got to be a better way of reading the string than having to copy those bytes twice. Is there a way to achieve what i am doing in one operation?
Bookmarks