Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
For license and copyright information please follow this link:
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
*/
|
|
#include "storage/serialize_common.h"
|
|
|
|
namespace Serialize {
|
|
|
|
ByteArrayWriter::ByteArrayWriter(int expectedSize)
|
|
: _stream(&_result, QIODevice::WriteOnly) {
|
|
if (expectedSize) {
|
|
_result.reserve(expectedSize);
|
|
}
|
|
_stream.setVersion(QDataStream::Qt_5_1);
|
|
}
|
|
|
|
QByteArray ByteArrayWriter::result() && {
|
|
_stream.device()->close();
|
|
return std::move(_result);
|
|
}
|
|
|
|
ByteArrayReader::ByteArrayReader(QByteArray data)
|
|
: _data(std::move(data))
|
|
, _stream(&_data, QIODevice::ReadOnly) {
|
|
_stream.setVersion(QDataStream::Qt_5_1);
|
|
}
|
|
|
|
void writeColor(QDataStream &stream, const QColor &color) {
|
|
stream << (quint32(uchar(color.red()))
|
|
| (quint32(uchar(color.green())) << 8)
|
|
| (quint32(uchar(color.blue())) << 16)
|
|
| (quint32(uchar(color.alpha())) << 24));
|
|
}
|
|
|
|
QColor readColor(QDataStream &stream) {
|
|
auto value = quint32();
|
|
stream >> value;
|
|
return QColor(
|
|
int(value & 0xFFU),
|
|
int((value >> 8) & 0xFFU),
|
|
int((value >> 16) & 0xFFU),
|
|
int((value >> 24) & 0xFFU));
|
|
}
|
|
|
|
} // namespace Serialize
|