本文整理汇总了C++中QDataStream::writeRawData方法的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream::writeRawData方法的具体用法?C++ QDataStream::writeRawData怎么用?C++ QDataStream::writeRawData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDataStream
的用法示例。
在下文中一共展示了QDataStream::writeRawData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: write
void Frame::write(QDataStream &stream)
{
QByteArray lenbuf;
if (!encodeLength(lenbuf, _data.size()))
{
qCritical("qmqtt: Control packet bigger than 256 MB, dropped!");
return;
}
stream << (quint8)_header;
if(_data.size() == 0) {
stream << (quint8)0;
return;
}
if (stream.writeRawData(lenbuf.data(), lenbuf.size()) != lenbuf.size())
{
qCritical("qmqtt: Control packet write error!");
return;
}
if (stream.writeRawData(_data.data(), _data.size()) != _data.size())
{
qCritical("qmqtt: Control packet write error!");
}
}
示例3: writeIconToCache
bool IconCacheCreator::writeIconToCache(QDataStream &out, const QFileInfo &fileInfo) {
QFile in(fileInfo.absoluteFilePath());
if (!in.open(QIODevice::ReadOnly)) {
return false;
}
char buf[4096];
QDataStream inStream(&in);
qint64 size = in.size();
out.writeRawData((const char *)&size, sizeof(qint64));
while (!inStream.atEnd()) {
out.writeRawData(buf, inStream.readRawData(buf, 4096));
}
in.close();
//QPixmap pixmap(f.absoluteFilePath());
//out << pixmap;
//out << null;
//QIcon iconFile(f.absoluteFilePath());
//out << iconFile;
//out << null;
//DPRINT("cache icon: %s", qPrintable(f.absoluteFilePath()));
return true;
}
示例4:
/** Erases loaded data from memory */
PwHeaderV3::ErrorCode PwHeaderV3::write(QDataStream& outStream) {
outStream << SIGNATURE_1 << SIGNATURE_2 << flags << DB_VERSION;
outStream.writeRawData(masterSeed.constData(), masterSeed.size());
outStream.writeRawData(initialVector.constData(), initialVector.size());
outStream << groupCount << entryCount;
outStream.writeRawData(contentHash.constData(), contentHash.size());
outStream.writeRawData(transformSeed.constData(), transformSeed.size());
outStream << transformRounds;
return SUCCESS;
}
示例5: write
void Frame::write(QDataStream &stream)
{
QByteArray lenbuf;
stream << (quint8)_header;
if(_data.size() == 0) {
stream << (quint8)0;
return;
}
encodeLength(lenbuf, _data.size());
stream.writeRawData(lenbuf.data(), lenbuf.size());
stream.writeRawData(_data.data(), _data.size());
}
示例6: iter
template<typename T> void storeBulk(const RawConverter& converter, QDataStream& stream, StreamConnector *streamconnector, const BoundingBox& box, const IRasterCoverage& raster){
quint64 count = streamconnector->position();
if ( streamconnector->isFileBased()){
const UPGrid& grid = raster->grid();
quint32 blockCount = grid->blocks();
stream << blockCount;
for(quint32 i = 0; i < blockCount; ++i){
const char * data = grid->blockAsMemory(i, false);
quint64 blockSize = 8 * grid->blockSize(i);
stream << i;
stream << blockSize;
stream.writeRawData(data, blockSize);
}
streamconnector->flush(true);
}else {
PixelIterator iter(raster, box);
while(iter != iter.end()){
if ( count >= STREAMBLOCKSIZE - 9 ) {
streamconnector->flush(false);
count = 0;
}
count += sizeof(T);
stream << (T)converter.real2raw(*iter);
++iter;
}
}
}
示例7: writeMaskList
void MaskChan::writeMaskList(QDataStream& dataOut, QList<MaskRay*>& list)
{
for (int i=0;i<list.size();i++) {
dataOut.writeRawData( (const char *)&(list[i]->skipCount), sizeof(long));
long pairListSize=list[i]->endList.size();
dataOut.writeRawData( (const char *)&pairListSize, sizeof(long));
//qDebug() << "skip=" << list[i]->skipCount << " pairs=" << pairListSize;
for(int j=0;j<list[i]->endList.size();j++) {
long start=list[i]->startList[j];
dataOut.writeRawData( (const char *)&start, sizeof(long));
long end=list[i]->endList[j];
dataOut.writeRawData( (const char *)&end, sizeof(long));
//qDebug() << "start=" << start << " end=" << end;
}
}
}
示例8: out
ContestantConnection::ContestantConnection ( ServerNetwork* sn, QTcpSocket* socket ) : QObject ( sn ) {
m_snet = sn;
m_answer_capable = true;
m_hdr = NULL;
m_authenticated = false;
m_socket = socket;
connect ( m_socket, SIGNAL ( error ( QAbstractSocket::SocketError ) ),
this, SLOT ( error ( QAbstractSocket::SocketError ) ) );
connect ( m_socket, SIGNAL ( readyRead() ), this, SLOT ( ready() ) );
connect ( m_socket, SIGNAL ( disconnected() ), this, SLOT ( disconnected() ) );
// reply to client of the now established connection
QByteArray block;
QDataStream out ( &block, QIODevice::WriteOnly );
out.setVersion ( QDataStream::Qt_4_5 );
// construct the header
p_header hdr;
hdr.length = sizeof ( ushort );
hdr.command = NET_CONNECTION_RESULT;
out.writeRawData ( ( const char* ) &hdr, sizeof ( p_header ) );
out << ( ushort ) true;
m_socket->write ( block );
m_socket->flush();
m_qnum = m_snet->getQNumber();
m_qtime = m_snet->getQTime();
m_qstatus = m_snet->getQStatus();
}
示例9: stream
QByteArray IQSMPPOptionalParameter<QString>::encode() const
{
QByteArray result;
//Если не устанавливали значения для данной опции, то вернем пустой массив, т.к. данная опция
//не используется
if (!_valueSets)
return result;
if (tag() == IQSMPP::UndefinedOptionalParameter)
return result;
if (maxLength() == 0)
return result;
QDataStream stream (&result, QIODevice::WriteOnly);
stream << (quint16) tag();
stream << (quint16) 0;
//Запишим данные
//Если это строка
QByteArray stringBA = _value.toLatin1();
const char * stringShar = stringBA.constData();
int stringLength = stringBA.length();
stream.writeRawData(stringShar, stringLength);
if (_cOctetString)
stream << (quint8)0x00;
//Сохраним размер
stream.device()->seek(2);
stream << (quint16) result.size() - 4;
return result;
}
示例10: writeData
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int AvizoUniformCoordinateWriter::writeData(QDataStream& out)
{
QString start("@1\n");
out << start;
if(true == m_WriteBinaryFile)
{
out.writeRawData(reinterpret_cast<char*>(m_FeatureIds), m_FeatureIdsPtr.lock()->getNumberOfTuples() * sizeof(int32_t));
}
else
{
// The "20 Items" is purely arbitrary and is put in to try and save some space in the ASCII file
int64_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples();
int count = 0;
for (int64_t i = 0; i < totalPoints; ++i)
{
out << m_FeatureIds[i];
if(count < 20)
{
out << " ";
count++;
}
else
{
out << "\n";
count = 0;
}
}
// Pick up any remaining data that was not written because we did not have 20 items on a line.
out << "\n";
}
return 1;
}
示例11: writeCatesToCache
bool IconCacheCreator::writeCatesToCache(QDataStream &out, const QList<QString> &cates) {
for (int i = 0; i < cates.size(); i++) {
//out << qPrintable(cates.at(i));
out.writeRawData(qPrintable(cates.at(i)), cates.at(i).size() + 1);
}
return true;
}
示例12: serializeString
void ClientMessage::serializeString(const QString &string, QDataStream &stream){
//serializeByteArray(QByteArray(str.toStdString().c_str()), stream);
//serializeByteArray(str.toUtf8(), stream);
QByteArray dataArray = string.toUtf8();
stream.writeRawData(dataArray.data(), dataArray.size());
stream << quint8('\0'); // NUL TERMINATED
}
示例13: writeSizeToCache
bool IconCacheCreator::writeSizeToCache(QDataStream &out, const QList<int> &sizes) {
for (int i = 0; i < sizes.size(); i++) {
//out << sizes.at(i);
DPRINT("size: %d", out.device()->size());
out.writeRawData((const char *)&(sizes.at(i)), sizeof(int));
DPRINT("size: %d", out.device()->size());
}
return true;
}
示例14: serializeDynamicData
void QVRVNCViewer::serializeDynamicData(QDataStream& ds) const
{
ds << _vncWidth << _vncHeight;
ds << _vncDirtyRectangles;
for (int i = 0; i < _vncDirtyRectangles.size(); i++) {
QRect r = _vncDirtyRectangles[i];
for (int y = r.y(); y < r.y() + r.height(); y++) {
ds.writeRawData(reinterpret_cast<const char *>(&_vncFrame[y * _vncWidth]),
r.width() * sizeof(unsigned int));
}
}
}
示例15: ShortSave
/** Save a QByteArray to a stream with only one leading byte instead of 4. */
void ShortSave (QDataStream &s, const QByteArray &str )
{
if( str.size() > 255 )
{
qWarning( "ShortSave will truncate QByteArray to 255 characters!" );
}
quint8 len;
len = qMin(str.size(), 255);
s << len;
s.writeRawData( str.data(), len );
}