Binarydata over QJsonObject becomes to big.
-
Hey guys,
I have a websocket communication where I'm using QJsonDocument for serialization.
I also have to transmit binary-data so I encapsulate it as a base64 String.
I would expect a 33% data-increase over a direct binary transmission but my data becomes nearly 3 times as big:Bin-Data around 236 kByte while Json-Data is around 631 kByte.
Am I doing something wrong?QByteArray ba = qryAtt.value("attachment").toByteArray(); //get data from sql-query qDebug() << "SIZE:" << ba.size(); //236432 QJsonObject obj { {"fileName", qryAtt.value("fileName").toString()}, ... {"attachment", QString(ba.toBase64())} };
THX
mts -
Hey guys,
I have a websocket communication where I'm using QJsonDocument for serialization.
I also have to transmit binary-data so I encapsulate it as a base64 String.
I would expect a 33% data-increase over a direct binary transmission but my data becomes nearly 3 times as big:Bin-Data around 236 kByte while Json-Data is around 631 kByte.
Am I doing something wrong?QByteArray ba = qryAtt.value("attachment").toByteArray(); //get data from sql-query qDebug() << "SIZE:" << ba.size(); //236432 QJsonObject obj { {"fileName", qryAtt.value("fileName").toString()}, ... {"attachment", QString(ba.toBase64())} };
THX
mts -
no, that is not the point.
The base64 itself has the size that I expected.
Binary: 236432
Base64: 315244
33% biggerbut why does my QJson object have a size of around 631000 byte ?
-
that is a little bit strange.
The file itself has an expected size and also the content looks normal.
I created a file before I send the data and when I received the data. Both are identical.BUT:
void ...onBinaryMessageReceived(const QByteArray &message) { qDebug() << "onBinaryMessageReceived" << message.size(); // HERE it tells me 631476 //Json QJsonDocument doc = QJsonDocument::fromBinaryData(message);
-
no, that is not the point.
The base64 itself has the size that I expected.
Binary: 236432
Base64: 315244
33% biggerbut why does my QJson object have a size of around 631000 byte ?
Why do you use QJsonDocument::from/toBinaryData at all? QStrings are utf-16 encoded in binary representation so 2 * 315244 = 630488 bytes + rest.
-
Why do you use QJsonDocument::from/toBinaryData at all? QStrings are utf-16 encoded in binary representation so 2 * 315244 = 630488 bytes + rest.
@Christian-Ehrlicher Yes! You are absolutely right... toJson converts to UTF-8 and so it is working as expected.
Thank you!