void SoD00V::ReadHeader(QDataStream &datastr){ QMutexLocker locker(&readmutex); char tmp[4]; for(int i=0;i<252;i++){ char c=0; datastr.readRawData(&c,1); Set_description(Description()+ QChar(c)); } datastr.readRawData(tmp,2); datastr.readRawData(tmp,1); Set_NADC( tmp[0]); datastr.readRawData(tmp,1); char nmon=tmp[0]*4; if(nmon>63){ nmon=63; Set_Warning(); error("Data header contains wrong data about monitor detectors count."); } for(int i=0; i<63; i++){ uint cnt=0; datastr.readRawData((char*)&cnt,4); double val=cnt; if(i<nmon) ApplyConstant("M#"+QString::number(i),val); } m_events_header=0; datastr.readRawData((char*)&m_events_header,4); }
//read form fp,and write to tcpSocket void sendStreamData(QTcpSocket* tcpSocket,QDataStream &in,long long streamLength){ char *buffer; buffer = new (std::nothrow) char[STREAMBLOCKSIZE]; if(!buffer){ std::cerr << "can not allocat memeory" << std::endl; return; } if(streamLength==0){ while(!in.atEnd()){ unsigned short len = in.readRawData(buffer,STREAMBLOCKSIZE); if(tcpSocket->bytesToWrite()>16384 && !tcpSocket->waitForBytesWritten()) return; tcpSocket->write((char*)&len,sizeof(unsigned short)); if(len!=0) tcpSocket->write(buffer,len); if(len!=STREAMBLOCKSIZE){ len=STREAMBLOCKSIZE; tcpSocket->write((char*)&len,sizeof(unsigned short)); //break; } } } else{ while(streamLength>0){ unsigned short len = in.readRawData(buffer,STREAMBLOCKSIZE); if(tcpSocket->bytesToWrite()>16384 && !tcpSocket->waitForBytesWritten()) return; tcpSocket->write(buffer,len); streamLength -= len; } } delete[] buffer; }
QString AbrStructParser::p_objc(QDataStream &buf){ // here we lost some data definitly // objnamelen is always 1 and objname is empty string quint32 objnamelen; buf >> objnamelen; char * objname = new char[objnamelen*2+1]; buf.readRawData(objname,objnamelen*2); objname[ objnamelen * 2 ] = '\0'; Q_ASSERT(objnamelen == 1); quint32 objtypelen; buf >> objtypelen; if (objtypelen == 0){ objtypelen = 4; } char * typeName = new char[objtypelen+1]; buf.readRawData(typeName,objtypelen); typeName [objtypelen] = '\0'; quint32 value; buf >> value; //return QString::fromLatin1( objname ) + ' ' + QString::fromLatin1(typeName) + ' ' + QString::number(value); return QString::fromLatin1(typeName) + ' ' + QString::number(value); }
inline bool KNMusicTagM4a::getBox(QDataStream &musicDataStream, KNMusicTagM4a::M4ABox &box, bool ignoreContent) { //Clear the box data. clearBox(box); //Set the box properties to independet box. box.independence=true; //Get the size of the box, reduce the 8 bytes size of itself and the name. musicDataStream>>box.size; box.size-=8; //Generate the name field. char nameField[5]={0}; //Get the name of the box. if(musicDataStream.readRawData(nameField, 4)==-1) { //If you cannot read the data, then it's failed to read the box. return false; } //Save the box name. box.name=nameField; //Get the content, or else we will simply get back. if(ignoreContent) { box.independence=false; //Skip the box size data. return musicDataStream.skipRawData(box.size); } //Allocate memory to store the box data. box.data=new char[box.size]; //Read the new data. return musicDataStream.readRawData(box.data, box.size); }
QVariant readBinaryArray(QDataStream& in, int& position) { quint32 arrayLength; quint32 encoding; quint32 compressedLength; in >> arrayLength; in >> encoding; in >> compressedLength; position += sizeof(quint32) * 3; QVector<T> values; if ((int)QSysInfo::ByteOrder == (int)in.byteOrder()) { values.resize(arrayLength); QByteArray arrayData; if (encoding == FBX_PROPERTY_COMPRESSED_FLAG) { // preface encoded data with uncompressed length QByteArray compressed(sizeof(quint32) + compressedLength, 0); *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T)); in.readRawData(compressed.data() + sizeof(quint32), compressedLength); position += compressedLength; arrayData = qUncompress(compressed); if (arrayData.isEmpty() || (unsigned int)arrayData.size() != (sizeof(T) * arrayLength)) { // answers empty byte array if corrupt throw QString("corrupt fbx file"); } } else { arrayData.resize(sizeof(T) * arrayLength); position += sizeof(T) * arrayLength; in.readRawData(arrayData.data(), arrayData.size()); } if (arrayData.size() > 0) { memcpy(&values[0], arrayData.constData(), arrayData.size()); } } else { values.reserve(arrayLength); if (encoding == FBX_PROPERTY_COMPRESSED_FLAG) { // preface encoded data with uncompressed length QByteArray compressed(sizeof(quint32) + compressedLength, 0); *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T)); in.readRawData(compressed.data() + sizeof(quint32), compressedLength); position += compressedLength; QByteArray uncompressed = qUncompress(compressed); if (uncompressed.isEmpty()) { // answers empty byte array if corrupt throw QString("corrupt fbx file"); } QDataStream uncompressedIn(uncompressed); uncompressedIn.setByteOrder(QDataStream::LittleEndian); uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch for (quint32 i = 0; i < arrayLength; i++) { T value; uncompressedIn >> value; values.append(value); } } else { for (quint32 i = 0; i < arrayLength; i++) {
QString readUtf8(QDataStream& stream){ int size; stream.readRawData((char*)&size,sizeof(int)); if (size==0) return ""; char* utf8 = new char[size]; stream.readRawData(utf8,size); QString value = QString::fromUtf8(utf8,size); delete [] utf8; return value; }
bool FeatureConnector::readRing(QDataStream& stream, std::vector<Coordinate2d> &ring ) { quint32 numberOfCoords; if (stream.readRawData((char *)&numberOfCoords, 4) <= 0) return ERROR1(ERR_COULD_NOT_OPEN_READING_1,"data file"); vector<XYZ> pnts(numberOfCoords); stream.readRawData((char *)&pnts[0],numberOfCoords*3*8); ring.resize(numberOfCoords); for(quint32 i=0; i < numberOfCoords; ++i) { ring[i] = Coordinate2d(pnts[i].x, pnts[i].y); } return true; }
void TempConnection::ready() { QDataStream in ( m_socket ); in.setVersion ( QDataStream::Qt_4_5 ); if ( m_hdr == NULL ) { if ( m_socket->bytesAvailable() < ( int ) sizeof ( p_header ) ) { return; } m_hdr = new p_header; in.readRawData ( ( char* ) m_hdr, sizeof ( p_header ) ); //check the packet if ( strcmp ( ( const char* ) m_hdr->ident.data, "CERB" ) != 0 ) { // bad packet, do something here return; } //check the version if ( !is_proto_current ( m_hdr->ver ) ) { // the version is not the same, do something here } } if ( m_socket->bytesAvailable() < m_hdr->length ) { return; } if ( m_hdr->command == NET_INITIATE_CONNECTION ) { uchar client_type; in >> client_type; emit newClient ( this, static_cast<CLIENT_ID> ( client_type ) ); } else {
template<class T> QVariant readArray(QDataStream& in) { quint32 arrayLength; quint32 encoding; quint32 compressedLength; in >> arrayLength; in >> encoding; in >> compressedLength; QVector<T> values; const int DEFLATE_ENCODING = 1; if (encoding == DEFLATE_ENCODING) { // preface encoded data with uncompressed length QByteArray compressed(sizeof(quint32) + compressedLength, 0); *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T)); in.readRawData(compressed.data() + sizeof(quint32), compressedLength); QByteArray uncompressed = qUncompress(compressed); QDataStream uncompressedIn(uncompressed); uncompressedIn.setByteOrder(QDataStream::LittleEndian); uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch for (int i = 0; i < arrayLength; i++) { T value; uncompressedIn >> value; values.append(value); } } else {
template<class T> QVariant readBinaryArray(QDataStream& in, int& position) { quint32 arrayLength; quint32 encoding; quint32 compressedLength; in >> arrayLength; in >> encoding; in >> compressedLength; position += sizeof(quint32) * 3; QVector<T> values; const unsigned int DEFLATE_ENCODING = 1; if (encoding == DEFLATE_ENCODING) { // preface encoded data with uncompressed length QByteArray compressed(sizeof(quint32) + compressedLength, 0); *((quint32*)compressed.data()) = qToBigEndian<quint32>(arrayLength * sizeof(T)); in.readRawData(compressed.data() + sizeof(quint32), compressedLength); position += compressedLength; QByteArray uncompressed = qUncompress(compressed); if (uncompressed.isEmpty()) { // answers empty byte array if corrupt throw QString("corrupt fbx file"); } QDataStream uncompressedIn(uncompressed); uncompressedIn.setByteOrder(QDataStream::LittleEndian); uncompressedIn.setVersion(QDataStream::Qt_4_5); // for single/double precision switch for (quint32 i = 0; i < arrayLength; i++) { T value; uncompressedIn >> value; values.append(value); } } else {
QString readString(QDataStream &stream) { QString res = ""; while(true || !stream.atEnd()) { char data[2]; stream.readRawData(data, 2); if (data[0] == 0x00) break; if(data[0] != 0x00) res += QChar::fromLatin1(data[0]); /* * короче не знает он что такое этот фром аски, пробовал инклюды разные и доставлял либы, не помогло * sea-kg: беда... метод в ку5 морально устарел... может попробовать res += QChar::fromLatin1(data[0]) ??? * или res += QChar(QLatin1Char(data[0]).unicode()); * http://qt-project.org/doc/qt-5.0/qtcore/qchar.html * Static Public Method * QChar fromAscii(char c) (deprecated) * Converts the ASCII character c to it's equivalent QChar. This is mainly useful for non-internationalized software. * An alternative is to use QLatin1Char. */ } return res; }
void Connection::readChat(QDataStream& s) { int a,b; s>>a; qDebug()<<"Hei "<<a; char* buf = new char[2*a+1]; s.readRawData(buf,2*a); buf[2*a]=0; QString chatName=QString::fromRawData((QChar*)buf,a); s>>b; buf = new char[2*b+1]; s.readRawData(buf,2*b); buf[2*b]=0; QString chatMsg=QString::fromRawData((QChar*)buf,b); engine.chatList.append(ChatMessage(QDateTime::currentDateTime(),chatName,chatMsg)); }
QString AbrStructParser::p_untf(QDataStream &buf){ char * type = new char[5]; buf.readRawData(type, 4); type[4] = '\0'; double value; buf >> value; return QString::fromLatin1(type) + ' ' + QString::number(value); }
void chmEditer::on_pushButton_clicked() { // chmHeader hd; QString fileName = QFileDialog::getOpenFileName(this, tr("Открыть chm"), ".", tr("Chm Files (*.chm)")); // fileName = "D:\\ferz\\chm1\\TestPrj.chm"; QFile f; f.setFileName(fileName); if (f.open(QIODevice::ReadOnly)) { QDataStream stream; stream.setDevice(&f); stream.setByteOrder(QDataStream::LittleEndian); char *tmp1; tmp1 = new char[4]; stream.readRawData(tmp1,4); hd.header = tmp1; delete tmp1; stream>> hd.version; stream>> hd.lenght; stream.skipRawData(4); stream>>hd.timestamp; stream>>hd.languageID; tmp1 = new char[10]; stream.readRawData(tmp1,10); hd.GUID1 = tmp1; delete tmp1; tmp1 = new char[10]; stream.readRawData(tmp1,10); hd.GUID2 = tmp1; delete tmp1; qDebug()<<hd.GUID1; ui->textEdit->append("<b>Заголовок</b>: "+hd.header); ui->textEdit->append("<b>Версия</b>: "+QString("%1").arg(hd.version)); ui->textEdit->append("<b>полный размер заголовка</b> : "+QString("%1").arg(hd.lenght)); ui->textEdit->append("<b>Язык</b> : "+QString("%1").arg(hd.languageID,0, 16)); }
static bool abr_reach_8BIM_section(QDataStream & abr, const QString name) { char tag[4]; char tagname[5]; qint32 section_size = 0; int r; // find 8BIMname section while (!abr.atEnd()) { r = abr.readRawData(tag, 4); if (r != 4) { warnKrita << "Error: Cannot read 8BIM tag "; return false; } if (strncmp(tag, "8BIM", 4)) { warnKrita << "Error: Start tag not 8BIM but " << (int)tag[0] << (int)tag[1] << (int)tag[2] << (int)tag[3] << " at position " << abr.device()->pos(); return false; } r = abr.readRawData(tagname, 4); if (r != 4) { warnKrita << "Error: Cannot read 8BIM tag name"; return false; } tagname[4] = '\0'; QString s1 = QString::fromLatin1(tagname, 4); if (!s1.compare(name)) { return true; } // long abr >> section_size; abr.device()->seek(abr.device()->pos() + section_size); } return true; }
void Summoners::msg_RoleInfo(QDataStream &oStream) { qint32 len; char name[128] = {'\0'}; //假设名字最长128字符 oStream >> len; oStream.readRawData(name, len); oStream >> player.level >> player.exp >> player.hp >> player.dc; player.name = name; DisplayPlayerInfo(); }
QString AbrStructParser::p_enum(QDataStream &buf){ quint32 size1, size2; buf >> size1; if (size1 == 0){ size1 = 4; } char * name1 = new char[size1+1]; buf.readRawData(name1,size1); name1[size1] = '\0'; buf >> size2 ; if (size2 == 0){ size2 = 4; } char * name2 = new char[size2+1]; buf.readRawData(name2,size2); name2[size2] = '\0'; return QString::fromLatin1(name1) + ' ' + QString::fromLatin1(name2); }
void KMessageSocket::processNewData () { if (isRecursive) return; isRecursive = true; QDataStream str (mSocket); while (mSocket->bytesAvailable() > 0) { if (mAwaitingHeader) { // Header = magic number + packet length = 5 bytes if (mSocket->bytesAvailable() < 5) { isRecursive = false; return; } // Read the magic number first. If something unexpected is found, // start over again, ignoring the data that was read up to then. quint8 v; str >> v; if (v != 'M') { qCWarning(GAMES_PRIVATE_KGAME) << ": Received unexpected data, magic number wrong!"; continue; } str >> mNextBlockLength; mAwaitingHeader = false; } else { // Data not completely read => wait for more if (mSocket->bytesAvailable() < (qint64) mNextBlockLength) { isRecursive = false; return; } QByteArray msg (mNextBlockLength, 0); str.readRawData (msg.data(), mNextBlockLength); // send the received message emit received (msg); // Waiting for the header of the next message mAwaitingHeader = true; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QVariantMap variantMap; QString string = "testString"; variantMap["test"] = string; QVariantMap nestedMap; QString nestedString = "nestedString"; nestedMap["nested"] = nestedString; variantMap["nestedTest"] = nestedMap; const int length = 256; unsigned char* buffer = new unsigned char[length]; for (int i = 0; i < length; i++) { buffer[i] = i; } QFile file("file.dat"); file.open(QIODevice::WriteOnly); QDataStream out(&file); out << variantMap; out.writeRawData(reinterpret_cast<const char *>(buffer), length); file.close(); file.open(QIODevice::ReadOnly); QDataStream in (&file); QVariantMap variantMapIn; in >> variantMapIn; in.readRawData(reinterpret_cast<char *>(buffer), length); qDebug() << variantMapIn["test"].toString(); qDebug() << variantMapIn["nestedTest"].toMap()["nested"].toString(); qDebug() << "buffer 23:" << static_cast<int>(buffer[23]); this->dumpObjectTree(); this->dumpObjectInfo(); delete[] buffer; }
PwHeaderV3::ErrorCode PwHeaderV3::read(QDataStream& stream) { clear(); // check file signatures (although probably checked before) quint32 sign1, sign2, fileVersion; stream >> sign1 >> sign2 >> flags >> fileVersion; if (sign1 != SIGNATURE_1) return SIGNATURE_1_MISMATCH; if (sign2 != SIGNATURE_2) return SIGNATURE_2_MISMATCH; if ((fileVersion & 0xFFFFFF00) != (DB_VERSION & 0xFFFFFF00)) return UNSUPPORTED_FILE_VERSION; if ((flags & FLAG_RIJNDAEL) || !(flags & FLAG_TWOFISH)) { cypherAlgorithm = ALGORITHM_AES; } else if ((flags & FLAG_TWOFISH) || !(flags & FLAG_RIJNDAEL)) { cypherAlgorithm = ALGORITHM_TWOFISH; } else return UNSUPPORTED_CYPHER; LOG("Signatures match"); masterSeed.fill(0, MASTER_SEED_SIZE); stream.readRawData(masterSeed.data(), MASTER_SEED_SIZE); initialVector.fill(0, INITIAL_VECTOR_SIZE); stream.readRawData(initialVector.data(), INITIAL_VECTOR_SIZE); stream >> groupCount >> entryCount; contentHash.fill(0, CONTENT_HASH_SIZE); stream.readRawData(contentHash.data(), CONTENT_HASH_SIZE); transformSeed.fill(0, TRANSFORM_SEED_SIZE); stream.readRawData(transformSeed.data(), TRANSFORM_SEED_SIZE); stream >> transformRounds; return SUCCESS; }
bool FileFormatTimestampTypeSizeRawMessage::readHeaderFromStream(QDataStream& stream) { char name[13]; name[12] = '\0'; stream.readRawData(name, sizeof(name) - 1); qint32 version; stream >> version; if (QString(name) == "SSL_LOG_FILE" && version == this->version()) { return true; } return false; }
/** Load a QByteArray from a stream with only one leading byte instead of 4. */ void ShortLoad (QDataStream &s, QByteArray &str) { str.detach(); quint8 len; s >> len; // read size of string if ( len == 0 || s.atEnd() ) { // end of file reached str.resize( 0 ); return; } str.resize( len ); s.readRawData( str.data(), len ); return; }
void cTelnet::_loadReplay() { if( ! replayStream.atEnd() ) { int offset; int amount; replayStream >> offset; replayStream >> amount; char * pB = &loadBuffer[0]; loadedBytes = replayStream.readRawData ( pB, amount ); qDebug()<<"loaded:"<<loadedBytes<<"/"<<amount<<" bytes"<<" waiting for "<<offset<<" milliseconds"; loadBuffer[loadedBytes+1] = '\0'; QTimer::singleShot( offset/mudlet::self()->mReplaySpeed, this, SLOT(readPipe())); mudlet::self()->mReplayTime = mudlet::self()->mReplayTime.addMSecs(offset); }
TransactionChange::TransactionChange(QDataStream &in) : IMessage(in) { qint16 dateLength; QString date; in >> m_stockId >> m_amount >> m_price >> dateLength; QByteArray buffer(dateLength, Qt::Uninitialized); in.readRawData(buffer.data(), dateLength); date = QString(buffer); m_date = QDateTime::fromString(date, Qt::ISODate); }
void Summoners::msg_FightStart(QDataStream &oStream) { qint32 len; char name[128] = { '\0' }; //假设名字最长128字符 oStream >> len; oStream.readRawData(name, len); oStream >> monster.level >> monster.exp >> monster.hp >> monster.dc; monster.name = name; DisplayMonsterInfo(); ui.btn_startFight->setEnabled(false); ui.btn_attack->setEnabled(true); ui.btn_defense->setEnabled(true); ui.btn_recovery->setEnabled(true); }
static bool parseHostAndPort(QDataStream &stream, quint8 &type, QByteArray &host, quint16 &port) { // get host name quint8 hostLength; stream >> type; stream >> hostLength; if (stream.status() != QDataStream::Ok) return false; host.resize(hostLength); if (stream.readRawData(host.data(), hostLength) != hostLength) { qWarning("Invalid host length"); return false; } // get port stream >> port; return stream.status() == QDataStream::Ok; }
template<typename T> void loadBulk(const RawConverter& converter, QDataStream& stream, StreamConnector *streamconnector, const BoundingBox& box, const IRasterCoverage& raster){ if ( streamconnector->isFileBased()){ //const UPGrid& grid = raster->grid(); quint32 blockCount; stream >> blockCount; for(int i = 0; i < blockCount; ++i){ quint32 blockIndex; quint64 blockByteSize; stream >> blockIndex; stream >> blockByteSize; int pixelCount = blockByteSize / 8; std::vector<double> data(pixelCount); stream.readRawData((char *)&data[0],blockByteSize ); raster->gridRef()->setBlockData(i, data, true); } streamconnector->flush(true); } else {
void SoD00Z::ReadHeader(QDataStream &datastr){ QMutexLocker locker(&readmutex); char *buf=new char[512]; datastr.readRawData(buf,512); int formatid=((int)(buf[10])+256*((int)buf[11])); if(formatid!=2){ error("Wrond datafile format descriptor"); Set_Error(); } recordwidth=(((int)buf[8])+256*((int)buf[9])); blocklength=(((int)buf[14])+256*((int)buf[15])); recsperblock=blocklength/recordwidth; blocktag=blocklength%recordwidth; numblocks=(((int)buf[18])+256*((int)buf[19])); lastblocklength=(((int)buf[20])+256*((int)buf[21])); count=recsperblock*numblocks-(recsperblock-lastblocklength); Set_NADC((char)(recordwidth-1)); char cntcnt=buf[134]; for(int i=0;i<cntcnt;i++){ uint v=((uint)buf[136+i*4])+ ((uint)buf[136+i*4+1])*256+ ((uint)buf[136+i*4+2])*65536+ ((uint)buf[136+i*4+3])*256*65536; double val=v; ApplyConstant("M#"+QString::number(i),val); } int textlen=buf[232]; QString text=""; for(int i=0; (i< (textlen+1)/2) && (i<10); i++){ int data= ((int)buf[234+i*2])+ ((int)buf[234+i*2])*256; int basa=RADIX50.length(); text+=RADIX50[(data%(basa*basa*basa))/(basa*basa)]; text+=RADIX50[(data%(basa*basa))/basa]; text+=RADIX50[data%basa]; } Set_description(Description()+ text); cnt=0; blockcnt=0; delete [] buf; }
int FilterParserThread::getlineInStream(QDataStream &stream, std::string &name, char delim) { char c; int total_read = 0; int read; do { read = stream.readRawData(&c, 1); total_read += read; if (read > 0) { if (c != delim) { name += c; } else { // Delim found return total_read; } } } while(read > 0); return total_read; }
size_t SHMStreamer::operator ()(QDataStream& stream, CASSEvent& evt) { size_t nBytesRead(0); /** read frame header and calculate the frame data size from the contained * info. Set the eventid according to the id in the info Then read the frame * from the stream into the frame buffer. */ hllDataTypes::FrameHeader frameHead; stream >> frameHead; nBytesRead += sizeof(hllDataTypes::FrameHeader); evt.id() = frameHead.external_id; const size_t framesize(_width * frameHead.the_height); const size_t framesizeBytes(framesize * sizeof(hllDataTypes::pixel)); _hllFrameBuffer.resize(framesize); stream.readRawData(reinterpret_cast<char*>(&_hllFrameBuffer.front()), framesizeBytes); nBytesRead += framesizeBytes; /** get the detector associated with the frame info id from the event */ CASSEvent::devices_t &devices(evt.devices()); CASSEvent::devices_t::iterator devIt(devices.find(CASSEvent::PixelDetectors)); if(devIt == devices.end()) throw runtime_error("SHMStreamer: There is no pixeldetector device within the CASSEvent"); Device &dev(dynamic_cast<Device&>(*(devIt->second))); Detector &det(dev.dets()[frameHead.id]); det.id() = evt.id(); /** set the information of the frame to the detector */ det.columns() = _width/2; det.rows() = frameHead.the_height*2; det.frame().resize(_hllFrameBuffer.size()); /** convert the hll type frame to the cass type frame */ const size_t quadrantColumns = frameHead.the_height; const size_t quadrantRows = quadrantColumns; /** @todo: read out somehow? */ const size_t HLLColumns = _width; hllDataTypes::HLL2CASS(_hllFrameBuffer,det.frame(),quadrantColumns,quadrantRows,HLLColumns); return nBytesRead; }