QList<GameItem*>* GlobalData::loadItemData(const char* fileName) { QList<GameItem*> *list = new QList<GameItem*>(); FILE *fp = openFile(fileName); if(!fp){ QDebug(QtWarningMsg) << "读取物品出错"; return list; } skipBytes(fp, readInt(fp)); int count = readInt(fp); for( int i = 0; i < count; i++){ GameItem *gameItem = new GameItem(); list->append(gameItem); gameItem->idx = readInt(fp); gameItem->name = readUTF(fp); gameItem->describe = readUTF(fp); gameItem->level = readInt(fp); gameItem->rank = readInt(fp); gameItem->buyPrice = readInt(fp); gameItem->salePrice = readInt(fp); gameItem->limitLevel = readInt(fp); gameItem->addHP = readInt(fp); gameItem->addAF = readInt(fp); gameItem->addDEF = readInt(fp); } closeFile(fp); QDebug(QtDebugMsg) << fileName << "加载"<<list->count()<<"个物品"; return list; }
static void checkException(std::istream* inputStream) { uint16_t retCode; READ_SHORT(inputStream, retCode); if (retCode != 0) { retCode = ntohs(retCode); std::auto_ptr<std::string> error(readUTF(inputStream)); throw VoldemortException(error->c_str()); } }
void ThreeGPPContentPlugin::readUserData(QFile* file, QContent *content) { qint32 box_len = 0; qint32 len; QString sig; const quint32 box_header_size = 8, fullbox_header_size = 4 + box_header_size, header_size = fullbox_header_size + 2; getHeaderBox(file, len, sig, true); len -= 8; while((len-=box_len) > 0) { getHeaderBox(file, box_len, sig,true); skip(file, 6); if (sig == "dscp") { content->setProperty( QContent::Description, readUTF( file->read(box_len - header_size))); } else if (sig == "cprt") { content->setProperty( QContent::Copyright, readUTF( file->read(box_len - header_size))); } else if (sig == "perf") { content->setProperty( QContent::Artist, readUTF( file->read(box_len - header_size))); } else if (sig == "auth") { content->setProperty( QContent::Author, readUTF( file->read(box_len - header_size))); } else if (sig == "gnre") { content->setProperty( QContent::Genre, readUTF( file->read(box_len - header_size))); } else if (sig == "albm") { content->setProperty( QContent::Album, readUTF( file->read(box_len - header_size - 1))); content->setProperty( QContent::Track, QString(file->read(1))); } else { skip(file,box_len-header_size); } } }
bool FlowFileRecord::DeSerialize(const uint8_t *buffer, const int bufferSize) { int ret; io::DataStream outStream(buffer, bufferSize); ret = read(this->event_time_, &outStream); if (ret != 8) { return false; } ret = read(this->entry_date_, &outStream); if (ret != 8) { return false; } ret = read(this->lineage_start_date_, &outStream); if (ret != 8) { return false; } ret = readUTF(this->uuidStr_, &outStream); if (ret <= 0) { return false; } ret = readUTF(this->uuid_connection_, &outStream); if (ret <= 0) { return false; } // read flow attributes uint32_t numAttributes = 0; ret = read(numAttributes, &outStream); if (ret != 4) { return false; } for (uint32_t i = 0; i < numAttributes; i++) { std::string key; ret = readUTF(key, &outStream, true); if (ret <= 0) { return false; } std::string value; ret = readUTF(value, &outStream, true); if (ret <= 0) { return false; } this->attributes_[key] = value; } ret = readUTF(this->content_full_fath_, &outStream); if (ret <= 0) { return false; } ret = read(this->size_, &outStream); if (ret != 8) { return false; } ret = read(this->offset_, &outStream); if (ret != 8) { return false; } if (nullptr == claim_) { claim_ = std::make_shared<ResourceClaim>(content_full_fath_, content_repo_, true); } return true; }
void* listenerThread (void* arg) { int running = 1; char jobId[32]; char message[1024]; unsigned char code = 0; unsigned char state = 0; unsigned char command = 0; if (debug) { printf ("**DEBUG: ListenerThread starting.\n"); } while (running == 1) { if (debug) { printf ("**DEBUG: Beginning loop.\n"); } if (readn (fd, &code, 1) < 0) { errorMessage = "Error while reading message code from socket stream"; return (void*)-1; } if (debug) { printf ("**DEBUG: Read code %x.\n", code); } if (code == LOG_MESSAGE) { if (readUTF (fd, jobId) < 0) { errorMessage = "Error while reading job id for Log Message notice"; return (void*)-1; } if (readUTF (fd, message) < 0) { errorMessage = "Error while reading message for Job Started notice"; return (void*)-1; } printf ("%s\n", message); } else if (code == LOG_ERROR) { if (readUTF (fd, jobId) < 0) { errorMessage = "Error while reading job id for Log Error notice"; return (void*)-1; } if (readUTF (fd, message) < 0) { errorMessage = "Error while reading error for Job Started notice"; return (void*)-1; } fprintf (stderr, "%s\n", message); } else if (code == JOB_STATE_CHANGE) { if (readUTF (fd, jobId) < 0) { errorMessage = "Error while reading job id for Job Complete notice"; return (void*)-1; } if (readn (fd, &state, 1) < 0) { errorMessage = "Error while reading state code for New Job State notice"; return (void*)-1; } printf ("***NOTICE: Job %s ", jobId); printJobState (state); if ((state == STATE_COMPLETED) || (state == STATE_STOPPED) || (state == STATE_FAILED)) { running = 0; } } else if (code == JOB_CHECKPOINTED) { if (readUTF (fd, jobId) < 0) { errorMessage = "Error while reading job id for Job Checkpointed notice"; return (void*)-1; } printf ("***NOTICE: Job %s has been checkpointed.\n", jobId); if (taskType == CHECKPOINT_JOB) { running = 0; } } else if (code == SHUTTING_DOWN) { printf ("***NOTICE: Server is shutting down.\n"); running = 0; } /* There's a bug here when multiple JCEPskeletons are attached to the same * job. If a command fails for any of them, it will cause all of them to * exit. */ else if (code == COMMAND_FAILED) { if (readn (fd, &command, 1) < 0) { errorMessage = "Error while reading command code for Command Failed notice"; return (void*)-1; } if (readUTF (fd, jobId) < 0) { errorMessage = "Error while reading job id for Command Failed notice"; return (void*)-1; } if (readUTF (fd, message) < 0) { errorMessage = "Error while reading job id for Command Failed notice"; return (void*)-1; } printf ("***NOTICE: The command for job %s failed: %s.\n", jobId, message); /* If the purpose of this process matches the command that failed, exit */ if (command == taskType) { running = 0; } } else if (code == 0) { /* Houston, we have a problem */ errorMessage = (char*)malloc (32); sprintf (errorMessage, "Failure reading message type: no message type read"); return (void*)-1; } else { errorMessage = (char*)malloc (32); sprintf (errorMessage, "Invalid message type: %x", code); return (void*)-1; } code = 0; } return (void*)0; }
/** * Send a Multimedia Message. * <p> * This API sends an MMS message. According to the JSR 205 specification, one * MMS includes a message header and a message body. There can be more than one * message part in an MMS message body. MIDP WMA layer. The customer of this API * does not have to care about the details of the MMS PDU protocol * (WAP-209-MMS-Encapsulation standard). The native protocol of the target * device should package the MMS into the MMS PDU and send it to the network. * The customer should also tell the MIDP WMA the maximum message length which * the target device can support. * <p> * Sending an MMS message to the network has a long life process. To avoid * blocking the JVM for a long time, this API should work in asynchronous mode. * It will transfer the parameter to the native software platform and return * quickly. The native software platform should take the responsibility for * handling the entire communication session and use an asynchronous message or * callback function to notify the MIDP WMA of the result. * * @param toAddr The recipient's MMS address. * @param fromAddr The sender's MMS address. * @param appID The application ID associated with the message. * @param replyToAppID The application ID to which replies can be sent. * @param headerLen The length of the message header. * @param header The message header. * @param bodyLen The length of the message body. * @param body The message body. * @param bytesSent The number of bytes that were sent. * @param pContext pointer where to save context of asynchronous operation. * * @return <code>WMA_OK</code> when successful or * <code>WMA_ERR</code> if an error occurred. */ WMA_STATUS jsr205_send_mms(char* toAddr, char* fromAddr, char* appID, char* replyToAppID, jint headerLen, char* header, jint bodyLen, char* body, /* OUT */jint* bytesSent, /* OUT */void **pContext) { /** The status from writing the message. */ WMA_STATUS status = WMA_NET_IOERROR; /** Context of asynchronous operation */ MMSMessageContext *context; /* The actual number of bytes written. */ *bytesSent = 0; if (*pContext == NULL) { context = (MMSMessageContext *)pcsl_mem_malloc(sizeof(*context)); if (context == NULL) { return -1; } memset(context, 0, sizeof(*context)); /* This implementation combines the header and body. */ context->msgLen = headerLen + bodyLen; context->msg = (char*)pcsl_mem_malloc(context->msgLen * sizeof(char)); memcpy(context->msg, header, headerLen); memcpy(context->msg + headerLen, body, bodyLen); *pContext = context; /* Prepare to walk through all addresses in "To", "Cc" and "Bcc" lists. */ initUTF(header, headerLen, context); } else { context = *pContext; /** Finish asynchronous operation */ status = jsr205_mms_write(context->talkToSelf, toAddr, fromAddr, appID, replyToAppID, context->msgLen, context->msg, bytesSent, &context->emulatorContext); } /* * Process address lists for "To", "Cc" and "Bcc" lists. Whenever this * device's phone number is located in any of those lists, indicate that * this phone is talking to itself when sending the message. */ while (status != WMA_NET_WOULDBLOCK && status != WMA_NET_INTERRUPTED ) { char* semicolon = NULL; char* phoneNumber = NULL; int phoneNumberLen = 0; /** If the current list of recipients is over obtain the next one. */ if (context->listIndex >= context->listLength) { if (context->list != NULL) { /* Free memory used by the address list we just processed. */ pcsl_mem_free(context->list); } /* Search for header field containing the list. */ while ((context->list = readUTF(context)) != NULL) { if ((strcmp(context->list, "To") == 0) || (strcmp(context->list, "Cc") == 0) || (strcmp(context->list, "Bcc") == 0)) { /* Free memory used by the name. */ pcsl_mem_free(context->list); /* Pick up the address list. */ context->list = readUTF(context); if (context->list != NULL) { context->listLength = strlen(context->list); context->listIndex = 0; } /* Proceed with send. */ break; } else { /* Free memory used by header name we just skipped. */ pcsl_mem_free(context->list); } } if (context->list == NULL) { /* No more addresses. */ break; } } /* Determine the length of the phone number. */ semicolon = strchr(context->list + context->listIndex, ';'); if (semicolon != NULL) { phoneNumberLen = semicolon - (context->list + context->listIndex); } else { phoneNumberLen = context->listLength - context->listIndex; } if (phoneNumberLen > 0) { /* * Extract the phone number from the list. The phone number * may have surrounding whitespace, which gets ignored by * the check for "talkToSelf." */ phoneNumber = (char*)pcsl_mem_malloc(phoneNumberLen + 1); strncpy(phoneNumber, context->list + context->listIndex, phoneNumberLen); *(phoneNumber + phoneNumberLen) = '\0'; /* terminator */ /* * If this phone number is this device's phone number, then * the message is being sent to the device itself and must * be handled differently. */ context->talkToSelf = (is_device_phone_number(phoneNumber) == WMA_OK); pcsl_mem_free(phoneNumber); /* * Sends the message, gets the number of bytes written or * failure status in return. */ status = jsr205_mms_write(context->talkToSelf, toAddr, fromAddr, appID, replyToAppID, context->msgLen, context->msg, bytesSent, &context->emulatorContext); } context->listIndex = context->listIndex + phoneNumberLen + 1; } if (status != WMA_NET_WOULDBLOCK) { /* Free all context structures if operation is over. */ if (status == WMA_NET_INTERRUPTED) { /* Free address list memory if operation is aborted. */ pcsl_mem_free(context->list); } pcsl_mem_free(context->msg); pcsl_mem_free(context); } if (status == WMA_NET_SUCCESS) { status = WMA_OK; } else if (status != WMA_NET_WOULDBLOCK) { status = WMA_ERR; } return status; }
void ObjectDataInput::readInternal(int typeId, std::string *object) { *object = *readUTF(); }