Esempio n. 1
0
int main()
{
	etcd::Client<etcd::RapidReply> client("172.16.1.10", 2379);
	std::string a = GBKToUTF8("你好");
	
	etcd::RapidReply reply = client.Set("/message", a.c_str());
	etcd::RapidReply reply2 = client.Get("/message1");
	etcd::RapidReply::KvPairs result;
	reply2.GetAll(result);
	std::string b = UTF8ToGBK(result["/message1"].c_str());

	return 0;
}
Esempio n. 2
0
Score *Score::GetInstance()
{
	if (m_pInstance == ((void *)0))
	{
		m_pInstance = new Score();

		std::string smallBirdString="小小鸟队";
		std::string pigString = "掉队的小猪";
		GBKToUTF8(smallBirdString,"gbk","utf-8");
		GBKToUTF8(pigString,"gbk","utf-8");
		strcpy(teamScore[0].name, "LJX:            ");
		strcpy(teamScore[1].name, "XXX:           ");
		sprintf(teamScore[2].name, "%s:    ", smallBirdString.c_str());
		strcpy(teamScore[3].name, "000:           ");
		strcpy(teamScore[4].name, "[317]:         ");
		sprintf(teamScore[5].name, "%s: ", pigString.c_str());
		strcpy(teamScore[6].name, "fngng:        ");

		makeNameScore();
	}

	return m_pInstance;
}
Esempio n. 3
0
// 测试函数入口:
int main(int argc, char * argv[]) {

	//
	complexStrcutTest();

	// 初始化restful请求类的实例
	RESTFulRequestor<Person> request;

	/**********************************************************************************/
	// 中文乱码测试:
	string GetChineseURL = "http://172.16.10.14:1569/datasong/dataService/test/student/0EfwrIIfQUc9FuPbQNTeYx20161014113922976";
	string GetChineseResult = request.getGETResponse2Stream(GetChineseURL);
	cout << UTF8ToGBK(GetChineseResult) << endl;
	//string fileName = "C:\\Users\\wentao\\Desktop\\out.txt";
	//bool isGetSuccess = request.getGETResponseAsFile(GetChineseURL, fileName);
	
	// PUT方法调用测试:
	string PutURL = "http://172.16.10.14:1569/datasong/dataService/iscas/mission";
	string PutParamters = "{\"_actionid\" : \"1\", \"_id\" : \"\",  \"_name\" : \"任务1\",  \"_remark\" : \"我的第一个任务\",  \"_time\" : 2.119999999999999}";
	cout << PutParamters << endl;
	string PutResult = request.getPUTRequest2Stream(PutURL, GBKToUTF8(PutParamters));
	cout << UTF8ToGBK(PutResult) << endl;
	//string PutFileName = "C:\\Users\\wentao\\Desktop\\out.txt";
	//bool isPUTSuccess = request.getPUTRequestAsFile(GetChineseURL, PutParamters, PutFileName);

	// POST方法调用测试:
	string POSTURL = "http://172.16.10.14:1569/datasong/dataService/test/mission";
	string POSTParamters = "{\"search\":{\"field\":\"_actionid\",\"NAME\":\"term\",\"values\":[\"1\"]},\"start\":0,\"size\":10} ";
	string POSTResult = request.getPOSTRequest2Stream(PutURL, PutParamters);
	cout << UTF8ToGBK(POSTResult) << endl;


	/**********************************************************************************/
	// 测试:从自定义结构体转换为JSON
	string serializitionResult = request.serialize(p);
	cout << "转换后的JSON结果为:" << serializitionResult << endl;
	// 测试:从JSON转换到自定义结构体
	Person deserializitionResult;
	bool result = request.deserialize(deserializitionResult, serializitionResult);
	if (result) {
		cout << "反序列化成功!" << endl;
		cout << deserializitionResult.age << endl;
		cout << deserializitionResult.name << endl;
		cout << deserializitionResult.city << endl;
	}

	/**********************************************************************************/
	// 综合测试入口:
	if (argc<3) {	// 检查参数个数:
		cout << "at least input 2 paramters" << endl;
	}
	// 获取参数:
	int testOption = atoi(argv[1]);
	cout << "current option is: "<< testOption << endl;

	// 根据输入参数执行测试:
	switch (testOption)
	{
	// 测试0:访问网址,并且将网页返回内容显示在屏幕上
	case 0: {
		if (argc != 3) {
			cout << "call method: exe 0 URLAddress" << endl;
			break;
		}
		string testURL = argv[2];
		cout << "按照GET请求访问网址:" << testURL << endl;
		cout << "返回结果为:" << endl;
		request.getGETResponse2Screen(testURL);
		break;
	}
	// 测试1:使用GET方法访问URL,并将结果作为字符串返回
	case 1: {
		if (argc != 3) {
			cout << "call method: exe 1 URLAddress" << endl;
			break;
		}
		string testURL = argv[2];
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		string result = request.getGETResponse2Stream(testURL);
		cout << "返回结果为:" << UTF8ToGBK(result) << endl;
		break;
	}
	// 测试2:使用GET方法访问URL,并将结果写入指定的文件中
	case 2: {
		if (argc != 4) {
			cout << "call method: exe 2 URLAddress LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string restorFilePath = argv[3];
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getGETResponseAsFile(testURL, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" <<endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试3:使用POST方法访问URL,并将结果作为字符串返回
	case 3: {
		if (argc != 4) {
			cout << "call method: exe 3 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用POST方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getPOSTRequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试4:使用POST方法访问URL,并将结果写入到指定的文件中
	case 4: {
		if (argc != 5) {
			cout << "call method: exe 4 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getPOSTRequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试5:使用DELETE方法访问URL,并将结果作为字符串返回
	case 5: {
		if (argc != 4) {
			cout << "call method: exe 5 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getDELETERequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试6:使用DELETE方法访问URL,并将结果写入到指定的文件中
	case 6: {
		if (argc != 5) {
			cout << "call method: exe 6 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getDELETERequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试7:使用PUT方法访问URL,并将结果作为字符串返回
	case 7: {
		if (argc != 4) {
			cout << "call method: exe 7 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getPUTRequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试8:使用DELETE方法访问URL,并将结果写入到指定的文件中
	case 8: {
		if (argc != 5) {
			cout << "call method: exe 8 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用PUT方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getPUTRequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试9:form表单提交本地文件到指定的URL
	case 9: {
		if (argc != 5) {
			cout << "call method: exe 9 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单提交本地文件:" << localFilePath << endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadSimpleFormFile(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试10:form表单以multipart方式提交本地文件到指定的URL
	case 10: {
		if (argc != 5) {
			cout << "call method: exe 10 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单以multipart格式提交本地文件:" << localFilePath << endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadMultipartFormFile(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试11:form表单以multipart方式将本地文件转换为文件流,然后提交到指定的URL
	case 11: {
		if (argc != 5) {
			cout << "call method: exe 11 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单以multipart方式将本地文件:" << localFilePath <<" 转换为文件流"<< endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadMultipartFormFileStream(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试12:从指定的URL下载文件到本地路径:
	case 12: {
		if (argc != 5) {
			cout << "call method: exe 12 URLAddress requestParameter localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "从指定的URL:" << testURL << endl;
		cout << "按照参数:" << requestParameter << endl;
		cout << "下载文件到本地路径:" << localFilePath << endl;
		int result = request.SyncDownload(testURL, requestParameter, localFilePath);
		if (result == 0) {
			cout << "执行成功,请在本地路径查看下载文件" << endl;
		}
		break;
	}
	default:
		break;
	}


	// Finish test
	return 0;
}
Esempio n. 4
0
/** 
**在封装一层,直接传入一个string,转换后还回对应的编码给你 
*/  
const char* GBKToUTF(std::string &gbkStr)  
{  
	GBKToUTF8(gbkStr,"gbk","utf-8"); //后面两个参数就默认了,免得后面再传参麻烦  

	return gbkStr.c_str();  
}  
Esempio n. 5
0
bool DataManager::loadResTick(float dt)
{
	if (waitInitDataQueue.size()==0)
	{
		step2++;
		if (step2>5)
		{
			step2 = 0;
			return true;//加载结束
		}
		return false;
	}
	long startTime = TimeUtil::getInstance().getTimer();//@@temp
	int tag = waitInitDataQueue.front();

	step++;
	// 	if (step < 10)
	// 	{
	// 		return false;
	// 	}

	if (step<2)//2帧加一个
	{
		return false;
	}
	step = 0;
	switch (tag)
	{
	case DATA_TAG_INTERNATE:
		{
			InternationManager::getInstance().readData("locale/zh_CN.properties");
			initPlayerAttrStr();
			break;
		}
	case DATA_TAG_UI_COMMON_1:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_COMMON_1_PLIST);
			break;
		}
	case DATA_TAG_UI_COMMON_SUDOKU_1:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_COMMON_SUDOKU_1_PLIST);
			break;
		}
	case DATA_TAG_UI_ACHIEVE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_ACHIEVE_PLIST);
			break;
		}
	case DATA_TAG_UI_CHAT:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_CHAT_PLIST);
			break;
		}
	case DATA_TAG_UI_DANMEDICINE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_DANMEDICINE_PLIST);
			break;
		}
	case DATA_TAG_UI_GUILD:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_GUILD_PLIST);
			break;
		}
	case DATA_TAG_UI_HEADIMAGE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_HEADIMAGE_PLIST);
			CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("head.plist");
			break;
		}
	case DATA_TAG_UI_MENUBARBTN:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_MENUBARBTN_PLIST);
			break;
		}
	case DATA_TAG_UI_MOLD:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_MOLD_PLIST);
			break;
		}
	case DATA_TAG_UI_PET:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_PET_PLIST);
			break;
		}
	case DATA_TAG_UI_ROLE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_ROLE_PLIST);
			break;
		}
	case DATA_TAG_UI_SMALLMAP:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_SMALLMAP_PLIST);
			break;
		}
	case DATA_TAG_UI_SHOP:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_SHOP_PLIST);
			break;
		}
	case DATA_TAG_UI_SKILL:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_SKILL_PLIST);
			break;
		}
	case DATA_TAG_UI_SOCIETY:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_SOCIETY_PLIST);
			break;
		}
	case DATA_TAG_UI_VENATION:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_VENATION_PLIST);
			break;
		}
	case DATA_TAG_UI_NPC_TITLE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_NPC_TITLE_PLIST);
			break;
		}
	case DATA_TAG_UI_NPC_TITLE_1:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_NPC_TITLE_1_PLIST);
			break;
		}
	case DATA_TAG_UI_NPC_DIALOG:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_NPC_DIALOG_PLIST);
			CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(UI_NEW_NPC_DIALOG);
			break;
		}
	case DATA_TAG_UI_NPC_HEAD:
		{
			CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(UI_NPC_HEAD);
			break;
		}
	case DATA_TAG_UI_NPC_DIALOG_1:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_NPC_DIALOG_1_PLIST);
			break;
		}
	case DATA_TAG_UI_ROLE_TOP_TITLE:
		{
			PlistManager::getInstance().addUISpriteFrames(UI_ROLE_TOP_TITLE_PLIST);
			break;
		}
	case DATA_TAG_PLAYER:
		{
			PlayerController::getInstance().getRoleData()->setid(0);
			PlayerController::getInstance().getRoleData()->setTx(19);
			PlayerController::getInstance().getRoleData()->setTy(52);
			PlayerController::getInstance().getRoleData()->setCurrentHP(100);
			PlayerController::getInstance().getRoleData()->setTotalHP(150);
			PlayerController::getInstance().getRoleData()->setCurrentMP(100);
			PlayerController::getInstance().getRoleData()->setTotalMP(100);;
			PlayerController::getInstance().getRoleData()->setGender(1);
			PlayerController::getInstance().getRoleData()->setFaction(1);
			PlayerController::getInstance().getRoleData()->setLevel(1);
			PlayerController::getInstance().getRoleData()->setMoveSpeed(7);
			PlayerController::getInstance().getRoleData()->setKind(0);
			std::string name="纪宁";
			GBKToUTF8(name,"gb2312","utf-8");
			PlayerController::getInstance().getRoleData()->setName(name);
			break;
		}
	case DATA_TAG_NPC:
		{
			NpcData * npc1001=new NpcData();
			npc1001->entryid=132100000;
			npc1001->res_bodyId=132100000;
			npc1001->currentHP=50;
			npc1001->totalHP=100;
			npc1001->currentMP=100;
			npc1001->totalMP=100;
			npc1001->flag=NPC_TYPE_FUN;
			npc1001->kind=ENTITY_TYPE_NPC;
			npc1001->tx=33;
			npc1001->ty=48;
			npc1001->direction=4;
			std::string nameNpc001="李敬南";
			GBKToUTF8(nameNpc001,"gb2312","utf-8");
			npc1001->name=nameNpc001;

			NpcData * npc112000000=new NpcData();
			npc112000000->entryid=112000000;
			npc112000000->res_bodyId=112000000;
			npc112000000->currentHP=50;
			npc112000000->totalHP=100;
			npc112000000->currentMP=100;
			npc112000000->totalMP=100;
			npc112000000->flag=NPC_TYPE_FUN;
			npc112000000->kind=ENTITY_TYPE_NPC;
			npc112000000->tx=18;
			npc112000000->ty=70;
			npc112000000->direction=8;
			std::string nameNpc112000000="王雪";
			GBKToUTF8(nameNpc112000000,"gb2312","utf-8");
			npc112000000->name=nameNpc112000000;
			SceneController::getInstance().getSceneManager()->addToNpcQueue(npc112000000);
			SceneController::getInstance().getSceneManager()->addToNpcQueue(npc1001);
			break;
		}
	case DATA_TAG_TASK:
		{
			TaskController::getInstance().init();
			break;
		}
	case DATA_TAG_EFFECT:
		{
			EffectManager::getInstance().readData(EFFECT_PATH);
			break;
		}
	}
	long endTime = TimeUtil::getInstance().getTimer();//@@temp
	CCLOG("load data(data tag:%d) consume time: %d", tag, endTime-startTime);//@@temp
	GameGobal::getInstance().getLoadingLayer()->addCurreSize(1);
	waitInitDataQueue.pop();
	return false;
}