bool WaveMetaDocument::addContainer(WaveContainer* c) { Q_ASSERT(container() == c->parentContainer()); ObjectMutation rootop(true); if ( !jsonObject().hasAttribute("containers")) { JSONObject documentsOp(true); documentsOp.setAttribute(c->name(), JSONObject(true)); rootop.setMutation("containers", documentsOp); } else { ObjectMutation documentsOp(true); documentsOp.setMutation(c->name(), InsertMutation(JSONObject(true))); rootop.setMutation("containers", documentsOp); } DocumentMutation docop(rootop); docop.setDocumentId(documentId()); docop.setRevision(revision()); // qDebug("OP=%s", qPrintable(docop.mutation().toJSON())); JSONObject result = container()->put(docop.mutation().toObject(), documentId()); return result.attribute("ok").toBool(); }
bool WaveMetaDocument::addDocument(WaveDocument* wdoc) { // Strip the "_" in front. QString docid = wdoc->documentId().mid(1); ObjectMutation rootop(true); if ( !jsonObject().hasAttribute("documents")) { JSONObject documentsOp(true); documentsOp.setAttribute(docid, JSONObject(true)); rootop.setMutation("documents", documentsOp); } else { ObjectMutation documentsOp(true); documentsOp.setMutation(docid, InsertMutation(JSONObject(true))); rootop.setMutation("documents", documentsOp); } DocumentMutation docop(rootop); docop.setDocumentId(documentId()); docop.setRevision(revision()); qDebug("OP=%s", qPrintable(docop.mutation().toJSON())); JSONObject result = container()->put(docop.mutation().toObject(), documentId()); return result.attribute("ok").toBool(); }
rapidjson::Value JSONSerializer::SerializeVec3(const Vec3& vec) { rapidjson::Value jsonObject(rapidjson::kObjectType); jsonObject.AddMember("x", vec.x, *mAllocator); jsonObject.AddMember("y", vec.y, *mAllocator); jsonObject.AddMember("z", vec.z, *mAllocator); return jsonObject; }
void parseFrame(const char* json, SpriteFrame& frame) { TempAllocator512 ta; JsonObject jsonObject(ta); JsonRFn::parse(json, jsonObject); frame.name = JsonRFn::parseStringId(jsonObject["name"]); frame.region = JsonRFn::parseVector4(jsonObject["region"]); frame.pivot = JsonRFn::parseVector2(jsonObject["pivot"]); }
MyMessage JSONParser::parse( std::string str ) { MyMessage message; JSONObject jsonObject(str); std::string flag = jsonObject.getString("flag"); if (atoi(flag.c_str()) > 0) message.setFlag(true); else message.setFlag(false); message.setMsg(jsonObject.getString("msg")); return message; }
void RequestHandler::handleHttpRequest(const QByteArray &json, QTcpSocket *httpSocket) { qDebug("[RequestHandler::handleHttpRequest]"); qDebug() << "[RequestHandler::handleHttpRequest] json to handle: " << json; QJsonObject jsonObj = jsonObject(json); if (jsonObj.isEmpty()) { qDebug("[RequestHandler::handleHttpRequest] ERROR: json obj is empty"); CliErrorReporter::printError(CliErrorReporter::NETWORK, CliErrorReporter::WARNING, "[RequestHandler::handleHttpRequest] json obj is empty"); // send error msg and kill socket // TODO error response httpSocket->close(); httpSocket->deleteLater(); return; } CommandExecuter::Command cmd = command(jsonObj); // TODO send correct data. For now stud data is used for prototyping and getting code done m_commandExecuter->execute(cmd, jsonObj.value("token").toString(), jsonObj.value("game").toString(), QVariantMap(), httpSocket); }
void compile(const char* path, CompileOptions& compileOptions) { Buffer buffer = compileOptions.read(path); TempAllocator4096 ta; JsonObject jsonObject(ta); JsonArray objectFrames(ta); Array<uint32_t> frames(getDefaultAllocator()); float totalTime = 0.0f; JsonRFn::parse(buffer, jsonObject); JsonRFn::parseArray(jsonObject["frames"], objectFrames); ArrayFn::resize(frames, ArrayFn::getCount(objectFrames)); for (uint32_t i = 0; i < ArrayFn::getCount(objectFrames); ++i) { frames[i] = (uint32_t)JsonRFn::parseFloat(objectFrames[i]); } totalTime = JsonRFn::parseFloat(jsonObject["totalTime"]); // Write SpriteAnimationResource spriteAnimationResource; spriteAnimationResource.version = RESOURCE_VERSION_SPRITE_ANIMATION; spriteAnimationResource.frameListCount = ArrayFn::getCount(frames); spriteAnimationResource.totalTime = totalTime; compileOptions.write(spriteAnimationResource.version); compileOptions.write(spriteAnimationResource.frameListCount); compileOptions.write(spriteAnimationResource.totalTime); for (uint32_t i = 0; i < ArrayFn::getCount(frames); ++i) { compileOptions.write(frames[i]); } }
void Output(const Mode mode, const char *file, const int line, const char *prefix, const char *delim, const char *name, const string &str) { if (initialized && str.length()) { string m = message(prefix,delim,name,str); // TODO - optional Regal source line numbers. #if 1 UNUSED_PARAMETER(file); UNUSED_PARAMETER(line); #else m = print_string(file,":",line," ",m); #endif #if REGAL_LOG_ONCE if (once) switch (mode) { case LOG_WARNING: { Thread::ScopedLock lock(uniqueMutex); if (uniqueWarnings.find(m)!=uniqueWarnings.end()) return; uniqueWarnings.insert(m); break; } case LOG_ERROR: { Thread::ScopedLock lock(uniqueMutex); if (uniqueErrors.find(m)!=uniqueErrors.end()) return; uniqueErrors.insert(m); break; } default: break; } #endif RegalContext *rCtx = NULL; #if !REGAL_SYS_WGL && !REGAL_NO_TLS if (Thread::currentContextKey && pthread_getspecific(Thread::currentContextKey)) rCtx = REGAL_GET_CONTEXT(); #else rCtx = REGAL_GET_CONTEXT(); #endif #if REGAL_LOG_CALLBACK if (callback && rCtx && rCtx->logCallback) rCtx->logCallback(GL_LOG_INFO_REGAL, (GLsizei) m.length(), m.c_str(), reinterpret_cast<void *>(rCtx->sysCtx)); #endif #if REGAL_SYS_WGL OutputDebugStringA(m.c_str()); #elif REGAL_SYS_ANDROID // ANDROID_LOG_INFO // ANDROID_LOG_WARN // ANDROID_LOG_ERROR __android_log_write(ANDROID_LOG_INFO, REGAL_LOG_TAG, m.c_str()); #endif #if REGAL_LOG_JSON && !REGAL_NO_JSON if (json && jsonOutput) { string m = jsonObject(prefix,name,str) + ",\n"; fwrite(m.c_str(),m.length(),1,jsonOutput); } #endif #if REGAL_LOG if (log && logOutput) { #if REGAL_SYS_ANDROID #else fprintf(logOutput, "%s", m.c_str()); fflush(logOutput); #endif } #endif append(m); } }