当前位置: 首页>>代码示例>>C++>>正文


C++ JSONNode::write方法代码示例

本文整理汇总了C++中JSONNode::write方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::write方法的具体用法?C++ JSONNode::write怎么用?C++ JSONNode::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONNode的用法示例。


在下文中一共展示了JSONNode::write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: libjsonBenchmark

/*
 * @brief function for libjson benchmark
 *
 * @param jsonString test data as a string
 * @return none
 */
void libjsonBenchmark(std::string jsonString)
{
    timespec time1, time2; 

    std::cout << std::setw(25) << "libjson";

    //Parsing the string
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
    JSONNode n = libjson::parse(jsonString);
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);

    printTimeDiff(time1, time2);

    //Serialize to string
    std::string out;
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
    out = n.write();
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);

    printTimeDiff(time1, time2);
    std::cout << std::endl;
}
开发者ID:aleks-f,项目名称:JsonBenchmarkCpp,代码行数:28,代码来源:main.cpp

示例2: callMethod

std::string ModuleManager::callMethod(const std::string& sender, const std::string& reciver, const std::string& action, const std::string& jsonString, IrcConnection* connection) {
	if(reciver=="IRCCONNECTION") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "joinChan") {
			connection->joinChan(n["channel"].as_string());
		}
		else if(action == "partChan") {
			connection->partChan(n["channel"].as_string());
		}
		else if(action == "sendQuit") {
			connection->sendQuit(n["msg"].as_string());
		}
		else if(action == "sendMessage") {
			connection->sendMessage(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendNotice") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendAction") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "sendCTCP") {
			connection->sendNotice(n["target"].as_string(), n["message"].as_string());
		}
		else if(action == "changeNick") {
			connection->changeNick(n["nick"].as_string());
		}
		else if(action == "setUserMode") {
			connection->setUserMode(n["mode"].as_string());
		}
		else if(action == "setMode") {
			connection->setMode(n["nick"].as_string(), n["mode"].as_string());
		}
		else if(action == "getChannels") {
			JSONNode n(JSON_NODE);

			std::map<std::string, IrcChannel>& channelList = connection->getChannels();
			std::map<std::string, IrcChannel>::iterator iter;
			for(iter=channelList.begin(); iter!=channelList.end(); ++iter) {
				JSONNode n2(JSON_ARRAY);
				n2.set_name(iter->first);
				n2.push_back(convertIrcChannelToJSONString(iter->second));
				n.push_back(n2);
			}
			return n.write();
		}
		else if(action == "getServer") {
			return connection->getServer();
		}
		else if(action == "getPort") {
			return Base::StringUtils::toString(connection->getPort());
		}
		else if(action == "getNick") {
			return connection->getNick();
		}
		else if(action == "getID") {
			return connection->getID();
		}
	}
	else if(reciver=="IRC") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "disconect") {
			mIRC->disconect(n["id"].as_string());
		}
		else if(action == "disconectAll") {
			mIRC->disconectAll();
		}
	}
	else if(reciver=="MODULEMANAGER") {
		JSONNode n;
		if(!jsonString.empty()) {
			n = libjson::parse(jsonString);
		}

		if(action == "reloadModule") {
			return Base::StringUtils::toString(reloadModule(n["id"].as_string()));
		}
		else if(action == "loadModuleBinary" || action == "loadModuleScript") {
			std::map<std::string, std::string> tmpParams;

			JSONNode n2 = n["params"];
			JSONNode::iterator i = n2.begin();
			for(; i!=n2.end(); ++i) {
				tmpParams[(*i).name()] = (*i).as_string();
			}

			if(action == "loadModuleBinary") {
				return Base::StringUtils::toString(loadModuleBinary(n["id"].as_string(), n["file"].as_string(), tmpParams));
			}
			else {
				return Base::StringUtils::toString(loadModuleScript(n["id"].as_string(), n["file"].as_string(), tmpParams));
			}
//.........这里部分代码省略.........
开发者ID:S1M0NE,项目名称:IrcBot,代码行数:101,代码来源:modulemanager.cpp

示例3: main

/*!
 \brief figure out the meaning of life
 \param argc		number of args
 \param argv		arguments
 
 Parses arguments and environment variables and kicks off execution of our
 little git hook.
 */
int main(int argc, const char * argv[])
{
	char *git_repo_path;
	char *next_ref;
	vector<WTConnection *> conns;
	
	
	if(argc < 2 || argv[1] == NULL)
	{
#if defined(HAVE_GETPROGNAME)
		usage(getprogname());
#elif defined(HAVE_PROGINVOC)
		usage(program_invocation_short_name);
#else
		usage("real-git-rcmp");
#endif
		return -1;
	}
	
	
	// Why set the errno?
	// because, if we don't have a GIT_DIR, we use cwd.
	// if cwd (on up) doesn't have a git repo, then we won't have an errno
	//   to print for perror and it might be something silly, like
	//   "Not a typewriter".  let's not do that, mmk?
	errno = ENOENT;
	
	if(getenv("GIT_DIR") == NULL)
	{
		char *cwd = getcwd(NULL, 0);
		git_repo_path = find_git_repo_from_path(cwd);
		free(cwd);
	}
	else
		git_repo_path = strdup(getenv("GIT_DIR"));
	
	
	if(git_repo_path == NULL)
	{
		perror("can't find git path");
		return 1;
	}
	
	
	for(size_t urls = 1; urls < argc; urls++)
	{
		WTConnection *conn = new WTConnection(NULL);
		conn->connect(argv[urls]);
		conns.push_back(conn);
	}
	
	
	// handle refs passed via stdin
	// format is "old-sha1 SP new-sha1 SP refname LF"
	// so, fgets is a good tool for this
	next_ref = static_cast<char *>(malloc(512));
	while((next_ref = fgets(next_ref, 512, stdin)) != NULL)
	{
		const char *old_id, *new_id; char *ref; JSONNode *node;
		
		char *new_id_start;
		
		// Find the first space
		char *space = strchr(next_ref, (int)' ');
		if(space == NULL) continue;
		
		// Replace the space with NUL so the string is terminated
		space[0] = '\0';
		old_id = next_ref;
		
		// The new SHA1 starts after the space
		new_id_start = space + 1;
		space = strchr(new_id_start, (int)' ');
		if(space == NULL) continue;
		
		// Replace the space with NUL so the string is terminated
		space[0] = '\0';
		new_id = new_id_start;
		
		// The ref is whatever is left over after the new ID's space.
		ref = space + 1;
		
		node = git_hook_main(git_repo_path, old_id, new_id, ref);
		
		if(node == NULL) continue;
		
		for(size_t next_conn = 0; next_conn < conns.size(); next_conn++)
		{
			WTConnection *conn = conns.at(next_conn);
			char *result;
			string payload = "payload=" + string(URLEncode(node->write().c_str()));
			uint64_t len = payload.length();
//.........这里部分代码省略.........
开发者ID:awilfox,项目名称:real-git-rcmp,代码行数:101,代码来源:main.cpp

示例4: UpdateRepoTagOfTarball

ResponseCode UpdateRepoTagOfTarball(std::string pathTarball, std::string repo, std::string tag, std::string &idImage) {
  TAR *tar = NULL;
  int ret = 0;
  int th_found = 0;
  int exitcode = 0;
//  char tmp_filepath[] = P_tmpdir "/libtar-tmpfile-XXXXXX";
  //gen path to upload image
  char* tmp_imagepath = tempnam (FileUtils::GetPathDir(pathTarball).c_str(), "imageDirTmp_");
  std::string pathTmpDir = tmp_imagepath;
  free(tmp_imagepath);
  std::cout << "path tmp dir: " << pathTmpDir << std::endl;

  int tmp_fd = -1;

  ret = tar_open(&tar, (char*)pathTarball.c_str(), NULL, O_RDONLY, 0, 0);
  if (ret != 0) {
	fprintf(stdout, "Fail to open file: %s\n", pathTarball.c_str());
//	return FILE_ACTION_ERROR;
	exitcode = 2;
  }
	if (exitcode == 0) {
		if (tar_extract_all(tar, (char*)pathTmpDir.c_str()) != 0) {
            fprintf(stderr, "Fail to extract file: %s\n", pathTarball.c_str());
			exitcode = 2;
		}
	}

	if (exitcode == 0) {
		ret = tar_close(tar);
		if (ret != 0) {
			perror("Failed to close tar file.");
			exitcode = 2;
		}
		tar = NULL;
	}

  //Modify repository file
  if (exitcode == 0) {
	char buf[BUFSIZ];
	ssize_t n_buf = 0;
	FILE *tmpfile = NULL;

	std::ifstream in((pathTmpDir + "/" + REPOSITORIES_FILE).c_str(), std::ios::binary);
	std::string info((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());

	JSONNode n;
	try
	{
		n = libjson::parse(info);
	} catch(const std::invalid_argument& e) {
		std::cerr << "Invalid argument: " << e.what() << '\n';
//		return FILE_ACTION_ERROR;
		exitcode = 1;
	}
	if(exitcode == 0){
		JSONNode::const_iterator i = n.begin();
		//if (i != n.end() && i -> name() == TAG_SERVICE_STR && i -> type() != JSON_ARRAY && i -> type() != JSON_NODE)
		if (i != n.end() && i -> type() == JSON_NODE){
			JSONNode tag_id_node = i->as_node();
			i = tag_id_node.begin();
			if (i != n.end() && i -> type() != JSON_ARRAY && i -> type() != JSON_NODE){
				idImage = i->as_string();
			}else{
				std::cout << "Tarball format error.\n";
		//		return FILE_ACTION_ERROR;
				exitcode = 1;
			}
		}
	}else{
		std::cout << "Tarball format error.\n";
//			return FILE_ACTION_ERROR;
		exitcode = 1;
		}
	}

	if(exitcode == 0){
		JSONNode newRepoNode(JSON_NODE);
		newRepoNode.set_name(repo);
		newRepoNode.push_back(JSONNode(tag, idImage));

		JSONNode newNode;
		newNode.push_back(newRepoNode);
		std::string content = newNode.write();

		FILE * pFile;

		if (exitcode == 0) {
			pFile = fopen ((pathTmpDir + "/" + REPOSITORIES_FILE).c_str() , "w");
			if (pFile == NULL) {
			   printf("Error opening file %s\n", (pathTmpDir + "/" + REPOSITORIES_FILE).c_str());
		//	   return FILE_ACTION_ERROR;
			   exitcode = 1;
			}
		}

		if (exitcode == 0) {
			fwrite (content.c_str() , sizeof(char), content.size(), pFile);
			fclose (pFile);
			printf("content tmp file: %s\n", content.c_str());
		}
//.........这里部分代码省略.........
开发者ID:pyotr777,项目名称:kportal,代码行数:101,代码来源:TarUtil.cpp

示例5: AppendDBEvent

MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time)
{
	mir_cslock lck(m_AppendMessageLock);
	DBEVENTINFO dbei = { sizeof(dbei) };
	dbei.cbBlob = db_event_getBlobSize(hEvent);
	dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
	db_event_get(hEvent, &dbei);

	JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob);
	if (jMsg)
	{
		JSONNode &jEdits = jMsg["edits"];
		if (jEdits)
		{
			for (auto it = jEdits.begin(); it != jEdits.end(); ++it)
			{
				const JSONNode &jEdit = *it;

				if (jEdit["time"].as_int() == edit_time)
					return hEvent;
			}
			JSONNode jEdit;
			jEdit 
				<< JSONNode("time", (long)edit_time)
				<< JSONNode("text", szContent);

			jEdits << jEdit;
		}
	}
	else
	{
		jMsg = JSONNode();
		JSONNode jOriginalMsg; jOriginalMsg.set_name("original_message");
		JSONNode jEdits(JSON_ARRAY); jEdits.set_name("edits");
		JSONNode jEdit;

		jOriginalMsg
			<< JSONNode("time", (long)dbei.timestamp)
			<< JSONNode("text", (char*)dbei.pBlob);

		jMsg << jOriginalMsg;

		jEdit 
			<< JSONNode("time", (long)edit_time)
			<< JSONNode("text", szContent);

		jEdits << jEdit;	
		jMsg   << jEdits;


	}
	db_event_delete(hContact, hEvent);	
	return AddDbEvent(SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, hContact, dbei.timestamp, DBEF_UTF, jMsg.write().c_str(), szUid);
}
开发者ID:Seldom,项目名称:miranda-ng,代码行数:54,代码来源:skype_db.cpp


注:本文中的JSONNode::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。