bool Image::deserialize(const char* const SerializedImage, const unsigned int Size){ if(Size < 4 * 5 + Key::PubKeySize) return false; ID = NetworkToHost(*(int*)SerializedImage); up_count=NetworkToHost(*(int*)(SerializedImage+4)); view_limit=NetworkToHost(*(int*)(SerializedImage+8)); int image_name_size= NetworkToHost(*(int*)(SerializedImage+12)); if(Size < 4*5 + Key::PubKeySize + image_name_size) return false; char* tempImageName = new char[image_name_size]; memcpy(tempImageName,(SerializedImage+16),image_name_size); image_name = QString::fromStdString(std::string(tempImageName, image_name_size)); int imageStringSize = NetworkToHost(*(int *)(SerializedImage+16+image_name_size)); if(Size != 4 * 5 + Key::PubKeySize + image_name_size + imageStringSize){ delete [] tempImageName; return false; } char * tempImageString = new char[imageStringSize]; QByteArray bytearr(SerializedImage+16+image_name_size + 4, imageStringSize); QFile file(path = PeerProgram::TempFolderPath + QString::number(rand()) + "_image_" + QString::number(ID) + ".png"); file.open(QIODevice::WriteOnly); file.write(bytearr); file.close(); owner_key.setFromString(QString::fromStdString(std::string(SerializedImage+Size-Key::PubKeySize, Key::PubKeySize))); delete [] tempImageString; return true; }
/* * Handle the response to a QueuedGet command */ void DmxTriWidgetImpl::HandleQueuedGetResponse(uint8_t return_code, const uint8_t *data, unsigned int length) { if (length < 2) { OLA_FATAL << "Queued response too small, was " << length << " bytes"; delete m_pending_request; m_pending_request = NULL; ola::rdm::RDMCallback *callback = m_rdm_request_callback; m_rdm_request_callback = NULL; if (callback) { std::vector<string> packets; callback->Run(ola::rdm::RDM_INVALID_RESPONSE, NULL, packets); } return; } uint16_t pid; memcpy(reinterpret_cast<uint8_t*>(&pid), data, sizeof(pid)); pid = NetworkToHost(pid); data += 2; length -= 2; OLA_INFO << "Received queued message response with code 0x" << std::hex << static_cast<int>(return_code) << ", " << std::dec << length << " bytes, param " << std::hex << pid; if (!length) data = NULL; HandleGenericRDMResponse(return_code, pid, data, length); }