Use QDataStream directly on QByteArray.

This commit is contained in:
John Preston 2017-08-08 20:25:10 +02:00
parent dd9d604966
commit edbc3f8fde
6 changed files with 9 additions and 44 deletions

View File

@ -54,12 +54,7 @@ QByteArray AuthSessionData::serialize() const {
auto result = QByteArray(); auto result = QByteArray();
result.reserve(size); result.reserve(size);
{ {
QBuffer buffer(&result); QDataStream stream(&result, QIODevice::WriteOnly);
if (!buffer.open(QIODevice::WriteOnly)) {
Unexpected("Can't open data for AuthSessionData::serialize()");
}
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream << static_cast<qint32>(_variables.selectorTab); stream << static_cast<qint32>(_variables.selectorTab);
stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0); stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0);
@ -84,12 +79,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
return; return;
} }
auto readonly = serialized; QDataStream stream(serialized);
QBuffer buffer(&readonly);
if (!buffer.open(QIODevice::ReadOnly)) {
Unexpected("Can't open data for DcOptions::constructFromSerialized()");
}
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji); qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
qint32 lastSeenWarningSeen = 0; qint32 lastSeenWarningSeen = 0;

View File

@ -362,9 +362,7 @@ void UpdateChecker::unpackUpdate() {
quint32 version; quint32 version;
{ {
QBuffer buffer(&uncompressed); QDataStream stream(uncompressed);
buffer.open(QIODevice::ReadOnly);
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream >> version; stream >> version;

View File

@ -1176,10 +1176,7 @@ QByteArray iconMaskValueSize(int width, int height) {
QLatin1String sizeTag("SIZE:"); QLatin1String sizeTag("SIZE:");
result.append(sizeTag.data(), sizeTag.size()); result.append(sizeTag.data(), sizeTag.size());
{ {
QBuffer buffer(&result); QDataStream stream(&result, QIODevice::Append);
buffer.open(QIODevice::Append);
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream << qint32(width) << qint32(height); stream << qint32(width) << qint32(height);
} }

View File

@ -247,13 +247,7 @@ QByteArray DcOptions::serialize() const {
auto result = QByteArray(); auto result = QByteArray();
result.reserve(size); result.reserve(size);
{ {
QBuffer buffer(&result); QDataStream stream(&result, QIODevice::WriteOnly);
if (!buffer.open(QIODevice::WriteOnly)) {
LOG(("MTP Error: Can't open data for DcOptions::serialize()"));
return result;
}
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream << qint32(_data.size()); stream << qint32(_data.size());
for (auto &item : _data) { for (auto &item : _data) {
@ -273,13 +267,7 @@ QByteArray DcOptions::serialize() const {
} }
void DcOptions::constructFromSerialized(const QByteArray &serialized) { void DcOptions::constructFromSerialized(const QByteArray &serialized) {
auto readonly = serialized; QDataStream stream(serialized);
QBuffer buffer(&readonly);
if (!buffer.open(QIODevice::ReadOnly)) {
LOG(("MTP Error: Can't open data for DcOptions::constructFromSerialized()"));
return;
}
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
auto count = qint32(0); auto count = qint32(0);
stream >> count; stream >> count;

View File

@ -84,10 +84,7 @@ QSize readGeneratedSize(const IconMask *mask, DBIScale scale) {
size -= sizeTag.size(); size -= sizeTag.size();
data += sizeTag.size(); data += sizeTag.size();
auto baForStream = QByteArray::fromRawData(reinterpret_cast<const char*>(data), size); auto baForStream = QByteArray::fromRawData(reinterpret_cast<const char*>(data), size);
QBuffer buffer(&baForStream); QDataStream stream(baForStream);
buffer.open(QIODevice::ReadOnly);
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
qint32 width = 0, height = 0; qint32 width = 0, height = 0;

View File

@ -81,9 +81,7 @@ QByteArray FlatTextarea::serializeTagsList(const TagList &tags) {
QByteArray tagsSerialized; QByteArray tagsSerialized;
{ {
QBuffer buffer(&tagsSerialized); QDataStream stream(&tagsSerialized, QIODevice::WriteOnly);
buffer.open(QIODevice::WriteOnly);
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
stream << qint32(tags.size()); stream << qint32(tags.size());
for_const (auto &tag, tags) { for_const (auto &tag, tags) {
@ -99,10 +97,7 @@ FlatTextarea::TagList FlatTextarea::deserializeTagsList(QByteArray data, int tex
return result; return result;
} }
QBuffer buffer(&data); QDataStream stream(data);
buffer.open(QIODevice::ReadOnly);
QDataStream stream(&buffer);
stream.setVersion(QDataStream::Qt_5_1); stream.setVersion(QDataStream::Qt_5_1);
qint32 tagCount = 0; qint32 tagCount = 0;