void controller::write_response_ok(const rapidjson::Document& data) { rapidjson::StringBuffer reply; rapidjson::Writer<rapidjson::StringBuffer> reply_writer(reply); data.Accept(reply_writer); _http_session->write_http_response(HTTP_CODE_OK, http_session::CONTENT_TYPE_JSON, reply.GetString(), reply.Size()); }
void Connection::send(rapidjson::Document &doc) { rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); send(buffer.GetString(), buffer.GetSize()); }
std::string jsonToString(const rapidjson::Document &document) { JsonStringWriter out; rapidjson::PrettyWriter<JsonStringWriter> writer(out); document.Accept(writer); // Yes, the string is copied here. stringstream does not allow moving the result out (boo!) return out.sstream.str(); }
std::string minius::rapidjsonToString(const rapidjson::Document& document) { rapidjson::StringBuffer stringBuffer; rapidjson::Writer<rapidjson::StringBuffer> writer(stringBuffer); document.Accept(writer); std::string message = stringBuffer.GetString(); return message; }
void FileSystem::WriteJSON( const char* filePath, rapidjson::Document& json ) { FILE* file; if ( fopen_s(&file, filePath, "w" ) != 0 ) return; rapidjson::FileStream fs(file); rapidjson::PrettyWriter<rapidjson::FileStream> writer(fs); json.Accept(writer); fclose(file); }
std::string toJson(rapidjson::Document& doc){ try { rapidjson::StringBuffer buffer; buffer.Clear(); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); return std::string(buffer.GetString()); }catch(std::exception& e){ DebugMessageWithTime("toJson exception:",e.what()); return ""; } }
void HrConvertUtil::FlushDataToFile(const std::string& strOutputFile, rapidjson::Document& doc) { rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); std::string strJsonContent = std::string(buffer.GetString()); strJsonContent = FormatJsonData(strJsonContent); std::string strRootPath = HrFileUtils::Instance()->GetFilePath(strOutputFile); std::string strFileName = HrFileUtils::Instance()->GetFileName(strOutputFile); std::string strSuffix = HrFileUtils::Instance()->GetFileSuffix(strOutputFile); filesystem::path filePath(strRootPath); //filePath = filePath / strFileName; //if (!filesystem::exists(filePath)) //{ // filesystem::create_directories(filePath); //} //auto outputFilePath = filePath / (strFileName + "." + strSuffix); std::string strRealOutputFilePath = strOutputFile;//outputFilePath.string(); HrFileUtils::Instance()->WriteDataToFile(strRealOutputFilePath, strJsonContent); auto fileTexturePath = filePath / "Texture\\"; if (!filesystem::exists(fileTexturePath)) { filesystem::create_directories(fileTexturePath); } //拷贝图片到Texture文件夹 for (size_t nMatIndex = 0; nMatIndex < m_modelDesc.vecMaterialDataInfo.size(); ++nMatIndex) { for (int nTexIndex = 0; nTexIndex < HrModelDataInfo::HrMaterialDataInfo::TS_NUMTEXTURESLOTS; ++nTexIndex) { if (filesystem::exists(m_modelDesc.vecMaterialDataInfo[nMatIndex].m_arrTexNames[nTexIndex])) { std::string strFileName = HrFileUtils::Instance()->GetFileNameWithSuffix(m_modelDesc.vecMaterialDataInfo[nMatIndex].m_arrTexNames[nTexIndex]); filesystem::path dstFilePath = fileTexturePath / strFileName; if (filesystem::exists(dstFilePath)) filesystem::remove(dstFilePath); filesystem::copy_file(m_modelDesc.vecMaterialDataInfo[nMatIndex].m_arrTexNames[nTexIndex], dstFilePath); } } } }
void MainWindow::writeConfigDocToFile(const rapidjson::Document &doc, const std::string &filename) { rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); std::ofstream output_file; output_file.open(filename); if (!output_file.is_open()) { throw std::runtime_error( (boost::format("Could not open file %s.") % filename).str() ); } else { output_file << buffer.GetString(); output_file.close(); } }
void saveShaderCache() { FILE* fp = fopen(_shaderCacheFilePath.c_str(), "wb"); if (fp == nullptr) { _INTR_LOG_ERROR("Failed to save shader cache..."); return; } char* writeBuffer = (char*)Memory::Tlsf::MainAllocator::allocate(65536u); { rapidjson::FileWriteStream os(fp, writeBuffer, 65536u); rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os); _shaderCache.Accept(writer); fclose(fp); } Memory::Tlsf::MainAllocator::free(writeBuffer); }
Field SchemaHelper::parseField(const rapidjson::Document &data, int index) { Field field = std::make_shared<SchemaField>(); field->index = index; field->name = getJSONString(data, "name"); field->type = getJSONString(data, "type"); field->geometry_type = getJSONString(data, "geometry_type"); field->nullable = getJSONBool(data, "nullable"); field->related_to = getJSONLong(data, "related_to", -1); field->max_length = getJSONInt(data, "max_length", -1); field->default_value = getJSONString(data, "default"); StringBuffer buffer; PrettyWriter<StringBuffer> writer(buffer); data.Accept(writer); field->json = buffer.GetString(); if(field->name == "amigo_id") { field->unique = true; } return field; }