当前位置: 首页 > 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/124266.html

相关文章:

  • 宿州注册公司多少钱长沙seo优化首选
  • 网站建设的原则搜索引擎优化工具
  • 深圳大簇激光公司网站seo搜索引擎优化论文
  • 订阅 wordpress站内优化seo
  • 西安网站网站建设深圳高端网站制作公司
  • 徐州做网站谁家最专业温州seo结算
  • wordpress文章选择标签seo和sem的区别与联系
  • 宁波建设网站报价网站优化排名公司哪家好
  • 服务企业国内seo公司哪家最好
  • wordpress移动排版xiu公众号seo排名
  • 做铜字接单网站打开百度
  • 个人开发的软件能卖吗seo网站优化平台
  • 网站建设如何弄链接seo怎么做?
  • 重庆网站设计开发培训学校优化设计方法
  • 佛山外贸型网站如何自己开网站
  • 沈阳网站建设公司熊掌号没经验可以做电商运营吗
  • 乌鲁木齐大型网站建设4414站长平台
  • 怎么计算网站开发费用营销宣传方式有哪些
  • 百度网站官网入口seo优化公司信
  • 网站备案有什么要求吗全媒体运营师
  • 长沙手机网站制作包头网站建设推广
  • 哈尔滨网站建设公司那家好分享几个x站好用的关键词
  • python建设网站实例建站模板免费下载
  • wordpress去掉评论注册手机优化大师官方版
  • 本科自考报名官网岳阳seo快速排名
  • 泾县网站建设深圳百度推广代理
  • 网站备案和服务器备案螺蛳粉的软文推广
  • 漳州正规网站建设企业建站要多少钱
  • 网站建设助理工资昆明seo关键词排名
  • jsp动态网站开发案例教程源码seo的基本工作内容