本文整理汇总了C++中qCompress函数的典型用法代码示例。如果您正苦于以下问题:C++ qCompress函数的具体用法?C++ qCompress怎么用?C++ qCompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qCompress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qWarning
QByteArray SimpleCrypt::encryptToByteArray(QByteArray plaintext)
{
if (m_keyParts.isEmpty()) {
qWarning() << "No key set.";
m_lastError = ErrorNoKeySet;
return QByteArray();
}
QByteArray ba = plaintext;
CryptoFlags flags = CryptoFlagNone;
if (m_compressionMode == CompressionAlways) {
ba = qCompress(ba, 9); //maximum compression
flags |= CryptoFlagCompression;
} else if (m_compressionMode == CompressionAuto) {
QByteArray compressed = qCompress(ba, 9);
if (compressed.count() < ba.count()) {
ba = compressed;
flags |= CryptoFlagCompression;
}
}
QByteArray integrityProtection;
if (m_protectionMode == ProtectionChecksum) {
flags |= CryptoFlagChecksum;
QDataStream s(&integrityProtection, QIODevice::WriteOnly);
s << qChecksum(ba.constData(), ba.length());
} else if (m_protectionMode == ProtectionHash) {
flags |= CryptoFlagHash;
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(ba);
integrityProtection += hash.result();
}
//prepend a random char to the string
char randomChar = char(qrand() & 0xFF);
ba = randomChar + integrityProtection + ba;
int pos(0);
char lastChar(0);
int cnt = ba.count();
while (pos < cnt) {
ba[pos] = ba.at(pos) ^ m_keyParts.at(pos % 8) ^ lastChar;
lastChar = ba.at(pos);
++pos;
}
QByteArray resultArray;
resultArray.append(char(0x03)); //version for future updates to algorithm
resultArray.append(char(flags)); //encryption flags
resultArray.append(ba);
m_lastError = ErrorNoError;
return resultArray;
}
示例2: generateReport
void BugReportForm::generateReport(const QByteArray &buf)
{
Messagebox msgbox;
QFile output;
QString filename=QFileInfo(QString(output_edt->text() +
GlobalAttributes::DIR_SEPARATOR +
GlobalAttributes::BUG_REPORT_FILE)
.arg(QDateTime::currentDateTime().toString(QString("_yyyyMMdd_hhmm")))).absoluteFilePath();
//Opens the file for writting
output.setFileName(filename);
output.open(QFile::WriteOnly);
if(!output.isOpen())
msgbox.show(Exception::getErrorMessage(ERR_FILE_DIR_NOT_WRITTEN).arg(filename), Messagebox::ERROR_ICON);
else
{
QByteArray comp_buf;
//Compress the buffer (using zlib) in a compression rate at 8
comp_buf=qCompress(buf, 8);
//Saves the buffer
output.write(comp_buf.data(), comp_buf.size());
output.close();
msgbox.show(trUtf8("Bug report successfuly generated! Please, send the file <strong>%1</strong> to <em>%2</em> in order be analyzed. Thank you for the collaboration!").arg(filename).arg(GlobalAttributes::BUG_REPORT_EMAIL),
Messagebox::INFO_ICON);
}
}
示例3: slotSaveAs
void KMoneyThingMainWidget::slotSave()
{
KTempFile temp;
QString fileName = mCurrentFile->kurl().path();
if (fileName == "")
{
slotSaveAs();
return;
}
if (!mCurrentFile->kurl().isLocalFile())
{
fileName = temp.name();
}
emit(setStatus(i18n("Saving file...")));
QByteArray dump = qCompress(mCurrentFile->dump());
QFile file(fileName);
file.open(IO_WriteOnly);
QDataStream stream(&file);
stream << (QString) "KMoneyThingFile" << dump;
file.close();
if (!mCurrentFile->kurl().isLocalFile())
{
emit(setStatus(i18n("Uploading file...")));
if (!KIO::NetAccess::upload(fileName, mCurrentFile->kurl(), this))
KMessageBox::error(this, i18n("Failed to upload file."));
}
temp.unlink();
emit(setStatus(i18n("Ready.")));
}
示例4: writeData
bool JArchive::writeData(const QString &key,const QByteArray &data,bool compress,const QString &data_type) {
QByteArray data2;
if (compress) data2=qCompress(data);
QString tmp=key;
if (!d->m_group_prefix.isEmpty())
tmp=d->m_group_prefix+"/"+key;
QByteArray key2=tmp.toAscii();
QByteArray data_type2=data_type.toAscii();
qint32 length_of_header=4+4+4+4+4+key2.count()+4+4+data_type2.count();
qint32 length_of_data=data.count();
qint32 compressed_length_of_data=length_of_data;
if (compress) {
compressed_length_of_data=data2.count();
}
qint32 length_of_key=key2.count();
qint32 is_compressed=0;
if (compress) is_compressed=1;
qint32 code=JARCHIVE_BEGIN_RECORD_CODE;
qint32 length_of_data_type=data_type2.count();
d->write_int32(code); //4
d->write_int32(length_of_header); //4
d->write_int32(compressed_length_of_data); //4
d->write_int32(length_of_data); //4
d->write_int32(length_of_key); //4
d->write_bytes(key2); //length_of_key
d->write_int32(is_compressed); //4
d->write_int32(length_of_data_type); //4
d->write_bytes(data_type2); //length_of_data_type
if (compress) d->write_bytes(data2);
else d->write_bytes(data);
return true;
}
示例5: qCompress
void Socket::sendData(const QByteArray &content)
{
if(socket->state() == QAbstractSocket::ConnectedState){
QByteArray buffer;
if(compressed_){
buffer = qCompress(content);
}else{
buffer = content;
}
quint32 length = buffer.length()+1; // one more byte to
// store extra information
uchar c1, c2, c3, c4;
c1 = length & 0xFF;
length >>= 8;
c2 = length & 0xFF;
length >>= 8;
c3 = length & 0xFF;
length >>= 8;
c4 = length & 0xFF;
socket->putChar(c4);
socket->putChar(c3);
socket->putChar(c2);
socket->putChar(c1);
// lowest bit for compressed or not
if(compressed_){
socket->putChar(0x1);
}else{
socket->putChar(0);
}
socket->write(buffer);
}
示例6: prepName
// Save the prepared API information.
bool QsciAPIs::savePrepared(const QString &filename) const
{
QString pname = prepName(filename, true);
if (pname.isEmpty())
return false;
// Write the prepared data to a memory buffer.
QByteArray pdata;
QDataStream pds(&pdata, QIODevice::WriteOnly);
// Use a serialisation format supported by Qt v3.0 and later.
pds.setVersion(QDataStream::Qt_3_0);
pds << PreparedDataFormatVersion;
pds << lexer()->lexer();
pds << prep->wdict;
pds << prep->raw_apis;
// Compress the data and write it.
QFile pf(pname);
if (!pf.open(QIODevice::WriteOnly|QIODevice::Truncate))
return false;
if (pf.write(qCompress(pdata)) < 0)
{
pf.close();
return false;
}
pf.close();
return true;
}
示例7: out
bool Vocabulary::save( const QString& filename ) const {
QByteArray data;
QDataStream out( &data, QIODevice::WriteOnly );
out.setVersion( QDataStream::Qt_2_1 );
// 0x0010 means 0.10.x version.
out << qint32( Vocabulary::magicNumber ) << qint16( 0x0010 ) << *this;
QByteArray compressedData( qCompress( data ) );
QFile dataFile( filename );
QFileInfo dataFileInfo( dataFile );
QDir dataFileDir( dataFileInfo.absoluteDir() );
if( !dataFileDir.mkpath( dataFileDir.path() ) )
return( false );
if( !dataFile.open( QIODevice::WriteOnly ) )
return( false );
int ret = dataFile.write( compressedData );
dataFile.close();
if( ret == -1 || dataFile.error() != QFile::NoError ) {
dataFile.unsetError();
return( false );
}
return( true );
}
示例8: s
bool Emu::saveState(const QString &statePath)
{
emsl.save = true;
QByteArray data;
data.reserve(10*1024*1024);
QDataStream s(&data, QIODevice::WriteOnly);
s.setByteOrder(QDataStream::LittleEndian);
s.setFloatingPointPrecision(QDataStream::SinglePrecision);
if (!saveInternal(&s))
return false;
QFile file(statePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
emsl.error = tr("Could not open file for writing.");
return false;
}
s.setDevice(&file);
s << frame().copy(videoSrcRect().toRect());
QByteArray compressed = qCompress(data);
bool ok = (file.write(compressed) == compressed.size());
file.close();
if (!ok)
file.remove();
return ok;
}
示例9: out
QByteArray ourtrackserv::Serialize(const QVector<MainListItem> &items)
{
// Результирующий буффер
QByteArray buffer;
QDataStream out(&buffer, QIODevice::WriteOnly);
QMap<quint16, QVariant> m; // Карта для записи элементов класса для последующей сериализации
int counter = 0; // Количество записей в карту (используется как ключ)
// Добавляем количество элементов (потребуется для десериализации)
m.insert(counter++, items.size());
// Добавляем все элементы
for (auto it = items.begin(); it != items.end(); ++it)
{
m.insert(counter++, it->id);
m.insert(counter++, it->category);
m.insert(counter++, it->name);
m.insert(counter++, it->description);
m.insert(counter++, it->size);
m.insert(counter++, it->reg_time);
m.insert(counter++, it->hash);
m.insert(counter++, it->user_id);
m.insert(counter++, it->download);
m.insert(counter++, it->liked);
}
out << m;
return qCompress(buffer, 0);
}
示例10: embedData
static ulong embedData( QTextStream& out, const uchar* input, int nbytes )
{
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
QByteArray bazip( qCompress( input, nbytes ) );
ulong len = bazip.size();
#else
ulong len = nbytes;
#endif
static const char hexdigits[] = "0123456789abcdef";
QString s;
for ( int i=0; i<(int)len; i++ ) {
if ( (i%14) == 0 ) {
s += "\n ";
out << (const char*)s;
s.truncate( 0 );
}
uint v = (uchar)
#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
bazip
#else
input
#endif
[i];
s += "0x";
s += hexdigits[(v >> 4) & 15];
s += hexdigits[v & 15];
if ( i < (int)len-1 )
s += ',';
}
if ( s.length() )
out << (const char*)s;
return len;
}
示例11: warn
bool OctreePacketData::compressContent() {
PerformanceWarning warn(false, "OctreePacketData::compressContent()", false, &_compressContentTime, &_compressContentCalls);
// without compression, we always pass...
if (!_enableCompression) {
return true;
}
_bytesInUseLastCheck = _bytesInUse;
bool success = false;
const int MAX_COMPRESSION = 9;
// we only want to compress the data payload, not the message header
const uchar* uncompressedData = &_uncompressed[0];
int uncompressedSize = _bytesInUse;
QByteArray compressedData = qCompress(uncompressedData, uncompressedSize, MAX_COMPRESSION);
if (compressedData.size() < (int)MAX_OCTREE_PACKET_DATA_SIZE) {
_compressedBytes = compressedData.size();
for (int i = 0; i < _compressedBytes; i++) {
_compressed[i] = compressedData[i];
}
_dirty = false;
success = true;
}
return success;
}
示例12: out
void Buddha::saveScreenshot ( QString fileName ) {
QImage out( (uchar*) RGBImage, w, h, QImage::Format_RGB32 );
out.save( fileName, "PNG" );
QByteArray compress = qCompress( (const uchar*) RGBImage, w * h * sizeof(int), 9 );
cout << "Compressed size vs Full: " << compress.size() << " " << w * h * sizeof(int) << endl;
}
示例13: ds
bool TSessionRedisStore::store(TSession &session)
{
QByteArray data;
QDataStream ds(&data, QIODevice::WriteOnly);
ds << *static_cast<const QVariantMap *>(&session);
data = qCompress(data, 1).toBase64();
#ifndef TF_NO_DEBUG
{
QByteArray badummy;
QDataStream dsdmy(&badummy, QIODevice::ReadWrite);
dsdmy << *static_cast<const QVariantMap *>(&session);
TSession dummy;
dsdmy.device()->seek(0);
dsdmy >> *static_cast<QVariantMap *>(&dummy);
if (dsdmy.status() != QDataStream::Ok) {
tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized.");
}
}
#endif
TRedis redis;
tSystemDebug("TSessionRedisStore::store id:%s", session.id().data());
return redis.setEx('_' + session.id(), data, lifeTimeSecs());
}
示例14: writeVector
void writeVector(QDataStream& out, char ch, QVector<T> vec) {
// Minimum number of bytes to consider compressing
const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000;
out.device()->write(&ch, 1);
out << (int32_t)vec.length();
auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) };
if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) {
auto compressedDataWithLength { qCompress(data) };
// qCompress packs a length uint32 at the beginning of the buffer, but the FBX format
// does not expect it. This removes it.
auto compressedData = QByteArray::fromRawData(
compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t));
if (compressedData.size() < data.size()) {
out << FBX_PROPERTY_COMPRESSED_FLAG;
out << (int32_t)compressedData.size();
out.writeRawData(compressedData.constData(), compressedData.size());
return;
}
}
out << FBX_PROPERTY_UNCOMPRESSED_FLAG;
out << (int32_t)0;
out.writeRawData(data.constData(), data.size());
}
示例15: uncompressed
void MTcpSocket::sendPacketInternal(const Mara::MPacket *pPacket)
{
QByteArray data;
bool compressed = pPacket->compressed();
if(compressed)
{
QByteArray uncompressed(*(pPacket->serialize()));
data = qCompress(uncompressed);
qDebug("Compression Ratio: %d/%d", data.size(), uncompressed.size());
}
else
{
data = *(pPacket->serialize());
}
{
QMutexLocker lock(&_mutex);
write(_packetHeaderBytes);
_socketStream << data.length();
_socketStream << pPacket->type();
write(data);
_socketStream << qChecksum(data.constData(), data.length());
_socketStream << compressed;
}
if(pPacket->deleteOnSend()) delete pPacket;
}