当前位置: 首页 > wzjs >正文

乐思网络舆情监测系统北京seo计费

乐思网络舆情监测系统,北京seo计费,毕设做网站需要买域名么,青岛即墨网站建设源码链接:NetworkComputer_CustomProtocol_V3 周不才/cpp_linux study - 码云 - 开源中国 自定义协议(添加/去除报头,序列化/反序列化)Custom.hpp: //自定义协议:包含自定义格式的序列化和反序列化、添加…

源码链接:NetworkComputer_CustomProtocol_V3 · 周不才/cpp_linux study - 码云 - 开源中国

自定义协议(添加/去除报头,序列化/反序列化)Custom.hpp:

//自定义协议:包含自定义格式的序列化和反序列化、添加报头、去除报头操作
#pragma once
#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
#include <memory>//提供智能指针
#include "Log.hpp"//日志using namespace log_ns;//自定义协议约定:
//添加报头时为json子串加上有效载荷长度len和\r\n
//即 "len"\r\n{json}\r\nstatic const std::string sep="\r\n";//添加报头
std::string Encode(const std::string& jsonstr)
{//参数说明:jsonstr是不带报头json字符串//返回值:返回添加报头后的json字符串size_t len=jsonstr.size();std::string packagejsonstr=std::to_string(len)+sep+jsonstr+sep;//带报头的json字符串return packagejsonstr;
}//去除报头
std::string Decode(std::string& packagejsonstr)
{//参数说明:jsonstr是带报头的json字符串//返回值:返回去除报头后的json字符串size_t pos=packagejsonstr.find(sep);//定位\r\n的位置if(pos==std::string::npos)//定位失败{return std::string();//返回一个空串}std::string lenstr=packagejsonstr.substr(0,pos);//取出"len"int len=std::stoi(lenstr);//json字符串长度int total=lenstr.size()+len+sep.size()*2;//计算完整的报文长度,即"len"\r\n{json}\r\n长度if(packagejsonstr.size()<total)//说明当前接收到的数据没有一个完整的数据{return std::string();}//当前接收到的数据包含完整的数据std::string jsonstr=packagejsonstr.substr(pos+sep.size(),len);//开始提取有效数据(即json字符串)packagejsonstr.erase(0,total);//删除已经提取到的数据return jsonstr;
}   //请求类Request:服务端处理数据之前,数据的格式
class Request
{
private:int _x;int _y;char _operator;
public://初始化Request数据void SetValue(int x,int y,char op){_x=x;_y=y;_operator=op;}//获取数据int GetX(){return _x;}int GetY(){return _y;}char Getoperator(){return _operator;}
public://序列化操作bool Serialize(std::string* out){//参数说明//out是输出型参数,用于带出序列化为json字符串格式的数据//先将Request对象转换为Json::Value类型Json::Value root;root["x"]=_x;root["y"]=_y;root["operator"]=_operator;//再将Json::Value类型转换为json字符串类型*out=root.toStyledString();return true;}//反序列化操作bool Deserialize(const std::string& in){//参数说明//in是json字符串格式的数据//先将json字符串类型转换为Json::Value类型Json::Reader reader;//调用该对象的方法将数据转换为Json::Value类型Json::Value root;//反序列化后存储数据的Json::Valuereader.parse(in,root);//将数据转换为Json::Value类型//再将Json::Value类型转换为Request对象_x=root["x"].asInt();_y=root["y"].asInt();_operator=root["operator"].asInt();return true;}
};//应答类Response:服务端处理数据之后,数据的格式
class Response
{
private:int _result;//运算结果int _code;//运算结果码(0表示正常,1表示除0操作,2表示其他非法操作)std::string _describe;//运算结果描述
public://输出结果void Result(){std::cout<<"result: "<<_result<<", code: "<<_code<<", describe: "<<_describe<<std::endl;}//设置数据void SetResult(int result){_result=result;}void SetCode(int code){_code=code;}void SetDescribe(std::string describe){_describe=describe;}
public://序列化操作bool Serialize(std::string* out){//先将Response对象转换为Json::Value类型Json::Value root;root["result"]=_result;root["code"]=_code;root["describe"]=_describe;//再将Json::Value类型转换为json字符串类型*out=root.toStyledString();return true;}//反序列化操作bool Deserialize(const std::string& in){//先将json字符串类型转换为Json::Value类型Json::Value root;Json::Reader reader;reader.parse(in,root);//再将Json::Value类型转换为Response对象_result=root["result"].asInt();_code=root["code"].asInt();_describe=root["describe"].asString();return true;}
};//工厂模式:调用函数直接返回Request对象和Response对象
class Factory
{
public://构建Request对象static std::shared_ptr<Request> BuildRequest(){return std::make_shared<Request>();}//构建Response对象static std::shared_ptr<Response> BuildResponse(){return std::make_shared<Response>();}
};

文章转载自:

http://7UlmRWIB.gstff.cn
http://WRsIgxE2.gstff.cn
http://8g4TTNpO.gstff.cn
http://aVNgvjtJ.gstff.cn
http://rpjfMHnI.gstff.cn
http://YIAtIQ5Z.gstff.cn
http://aQRCaDyT.gstff.cn
http://jI4DpLHb.gstff.cn
http://cPtByHyU.gstff.cn
http://33Bsb7aP.gstff.cn
http://xoy8z0Vb.gstff.cn
http://8chLBiye.gstff.cn
http://cVQryNZC.gstff.cn
http://sMR3zDnO.gstff.cn
http://lwfzwZRv.gstff.cn
http://ZwQmPEIZ.gstff.cn
http://6nQb5PTT.gstff.cn
http://Dw6MGAgg.gstff.cn
http://bdggpybJ.gstff.cn
http://67aRH1D6.gstff.cn
http://y025piNO.gstff.cn
http://HlxlWa2k.gstff.cn
http://Kl4X5E0Y.gstff.cn
http://a8sfvKuX.gstff.cn
http://uz9q154C.gstff.cn
http://5EfC3gJA.gstff.cn
http://7MlR47ce.gstff.cn
http://z8JEwLzN.gstff.cn
http://KaMT5Km8.gstff.cn
http://o7xklKpv.gstff.cn
http://www.dtcms.com/wzjs/678558.html

相关文章:

  • 国内网站建设联系电话自己做家装设计网站
  • 哪家网站建设比较好厦门网站建设培训学校
  • 手机网站开发者工具wap手机网站建设
  • 做网站百度百科域名更换通知大牛鲁
  • 建行官网网站简单的网站设计案例
  • 湘潭大学迎新自助网站全球招商网
  • 哪家做网站好 成都龙岗seo优化
  • 天天seo站长工具新浪云上传wordpress
  • 专业的网站建设找聚爱开发网站的步骤
  • 企业建网站tiktok跨境电商怎么做
  • 那个网站可以找人做兼职兰溪城市建设规划网站
  • 保定网站公司那家好计算机专业网页毕业设计
  • 网站托管就业购物网站设计方案
  • 汉中微信网站建设服务网页设计网站建设的书籍
  • 黑龙省建设厅网站首页素锦wordpress主题修改
  • 成都航空公司官方网站谷歌浏览器网页
  • 海东商城网站建设windows优化大师会员
  • 服务器网站备案快速搭建网站 优帮云
  • 怎么给网站做spm网页制作东莞
  • 济南企业建站公司重庆工程公司有哪些
  • 网站免费建设怎样在网做旅游网站
  • 琼中网站建设wordpress调用子分类
  • 中细软网站建设跨境电商产品开发
  • 网站备案是 备案空间吗自己做网站别人怎么看见
  • dremrever怎么做网站怎么在wordpress免费注册博客网站
  • 吉林市做网站的公司网站上文章分享的代码怎么做的
  • 惠城网站建设有哪些企业网站建设的一般要素主要包括网站的
  • 怎样自学做网站国内开源网站
  • asp个人网站下载网站开发项目实训总结
  • 服务器搭建网站能ping t公民道德建设网站