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

View File

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

View File

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

View File

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

View File

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

View File

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