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

自我介绍html网页模板seo培训

自我介绍html网页模板,seo培训,网站的图片大小规定,wordpress设置客户端缓存时间源码链接: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://www.dtcms.com/wzjs/231844.html

相关文章:

  • 制作一个企业网站多少钱网络营销的发展历程
  • 做分销网站多少钱手机游戏性能优化软件
  • 站酷网站建设推广普通话手抄报
  • 增城高端定制网站建设江阴百度推广公司
  • 网络营销有必要学吗杭州seo网
  • 做网站一班需要多少钱全球最牛的搜索引擎
  • 网站建设学什么软件网络营销策略优化
  • 简单搜索网页代码seo优化排名工具
  • 廉江网站建设公司模板建站的网站
  • 学校网站建设培训方案专业网站优化
  • 请问有没有做网站软文网站推荐
  • 微信小程序怎么推广运营我赢seo
  • 石景山网站制作长春关键词优化公司
  • 网站里的活动专题栏怎么做微信群推广
  • 万润 企业网站建设重庆百度推广排名
  • 做网站需要交接什么长春网站关键词推广
  • 建设不动产网站百度ai智能写作工具
  • 品牌网站解决方案免费网页在线客服系统
  • wordpress 腾讯云cos重庆seo网络推广关键词
  • 门户网站开发建设成本明细模板免费下载网站
  • 郴州竞价网站建设方案重庆百度快照优化
  • 东宁做木耳招工人网站西安百度公司
  • 石家庄网站制作招聘seo百科
  • 九牧全球市场地位seo企业建站系统
  • wordpress 做大型网站吗智能优化网站
  • 怎么给自己的网站做优化八零云自助建站免费建站平台
  • 做网站用虚拟机还是服务器深圳网络推广哪家
  • 公司免费网站注册百度推广
  • 申请域名后怎么做网站宣传推广方式有哪些
  • 日本做头像网站淘宝seo