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

数字营销公司seo优化自动点击软件

数字营销公司,seo优化自动点击软件,网站建设 淘宝描述,网站制作公司排名文章目录 RPC 协议gRPCJSON-RPC 数据序列化与反序列化lua-cjsonlua-protobuf RPC 协议 在分布式计算#xff0c;远程过程调用#xff08;英语#xff1a;Remote Procedure Call#xff0c;缩写为 RPC#xff09;是一个计算机通信协议。该协议允许运行于一台计算机的程序调… 文章目录 RPC 协议gRPCJSON-RPC 数据序列化与反序列化lua-cjsonlua-protobuf RPC 协议 在分布式计算远程过程调用英语Remote Procedure Call缩写为 RPC是一个计算机通信协议。该协议允许运行于一台计算机的程序调用另一个地址空间通常为一个开放网络的一台计算机的子程序而程序员就像调用本地程序一样无需额外地为这个交互作用编程无需关注细节。RPC 是一种服务器-客户端Client/Server模式经典实现是一个通过发送请求-接受回应进行信息交互的系统。 RPC 协议根据所使用的数据格式可以分为有模式schema和无模式schema-less。 有模式schema 通讯双方需要提前定义协议模板在数据传输过程中只传输值无需传输数据结构节省流量。典型的有模式 RPC 协议是基于 Protobuf 接口描述语言来实现的例如 gRPC。 优点是协议结构明确解析效率高缺点是不够灵活协议变更需要重新定义。 无模式(schema-less) 没有预定义数据结构支持动态语言。无需协议模板数据传输过程中需要带上数据结构。典型的无模式 RPC 协议是基于 JSON 来实现的 例如 JSON-RPC 。 优点是协议灵活、易于扩展缺点是解析效率较低。 通常我们会在数据序列化格式如 Protobuf、JSON的基础上定制符合自己要求的 RPC 协议灵活的在服务器和客户端之间通信。而不是采用通用的 RPC 框架对于不需要的功能增加了通信的开销。 gRPC https://doc.oschina.net/grpc JSON-RPC https://wiki.geekdream.com/Specification/json-rpc_2.0.html 数据序列化与反序列化 lua-cjson 采用的 json for lua 库https://github.com/cloudwu/lua-cjson lua CJSON 网站: https://www.kyne.com.au/~mark/software/lua-cjson.php 安装步骤 git clone https://github.com/cloudwu/lua-cjson.gitcd lua-cjson sudo vim Makefile 修改如下版本 5.4lua 文件前缀 /home/cauchy/.luaver/lua/5.4.6 由于我使用 luaver 来管理所以这里 lua 的路径可能不同。 make 执行完 Makefile成功后会生成 cjson.so我们只需要这个动态库。 mv cjson.so ../ cd .. sudo rm -rf lua-cjson 这一步可不执行只需要 cjson.so 在 require cjson 时能找到即可自己可以放置它的位置。 示例代码 协议格式 {fid: c2s_hello,msg: world }{fid: s2c_hello,succ: true, msg: hello .. ${msg} }fid 用于映射 RPC 协议处理的函数名fd 用于标识网络连接的文件描述符JS_data 标识序列化后的 JSON 数据data 是反序列化后的数据。 创建三个文件libnet.luaserver.luaclient.lua。 libnet.lua 模拟网络库简易实现网络数据的收发过程。提供三个接口发送消息给服务端发送消息给客户端连接服务器。 local M {}local server, clientfunction M.send_to_server(fd, JS_data)if not server then server require serverend server.dispatch(fd, JS_data) endfunction M.send_to_client(fd, JS_data)if not client then client require clientend client.dispatch(fd, JS_data) endlocal fd 0 function M.connect_server()fd fd 1return fd end return M server.lua 模拟服务器业务逻辑实现处理客户端的请求。 local cjson require cjson local libnet require libnetlocal M {} local RPC {}function RPC.c2s_hello(data)return {fid s2c_hello,succ true, msg hello .. data.msg} end function M.dispatch(fd, JS_data)local data cjson.decode(JS_data)local f assert(RPC[data.fid], Not exists Func: .. data.fid)local ok, r pcall(f, data)if ok then libnet.send_to_client(fd, cjson.encode(r))end return ok end return Mclient.lua 模拟客户端业务逻辑实现处理服务端的请求。 local cjson require cjson local libnet require libnetlocal M {} local RPC {}function RPC.s2c_hello(data)print(data.succ, data.msg) end function M.dispatch(fd, JS_data)local data cjson.decode(JS_data)local f assert(RPC[data.fid], Not exists Func: .. data.fid)local ok, r pcall(f, data)return ok end return M 新建 main.lua测试逻辑。 local cjson require cjson local libnet require libnetlocal function main()local fd libnet.connect_server()local data {fid c2s_hello,msg world}local JS_data cjson.encode(data)libnet.send_to_server(fd, JS_data) endmain()lua-protobuf lua-protobuf 库https://github.com/starwing/lua-protobuf luaver use 5.4.6luaver use-luarocks 3.9.2luarocks install lua-protobuf 使用 luarocks 来管理安装 lua 包 安装完后可以查看需要的 pb.so 和 protoc.lua 两个文件的路径 pb.soProtocol Buffers 的 Lua 语言动态库文件通过在 Lua 中 require(pb) 来加载该库。 protoc.luaProtocol Buffers 的 Lua 描述文件编译器将 .proto 文件编译生成对应的 Lua 代码生成的 Lua 代码依赖 pb.so 库来实现序列化和反序列化。 示例代码 local pb require pb local protoc require protoc-- 直接载入schema (这么写只是方便, 生产环境推荐使用 protoc.new() 接口) assert(protoc:load [[message Phone {optional string name 1;optional int64 phonenumber 2;}message Person {optional string name 1;optional int32 age 2;optional string address 3;repeated Phone contacts 4;} ]])-- lua 表数据 local data {name ilse,age 18,contacts {{ name alice, phonenumber 12312341234 },{ name bob, phonenumber 45645674567 }} }-- 将Lua表编码为二进制数据 local bytes assert(pb.encode(Person, data)) print(pb.tohex(bytes))-- 再解码回Lua表 local data2 assert(pb.decode(Person, bytes)) print(data2.name, data2.age, data2.contacts[1].name, data2.contacts[1].phonenumber, data2.contacts[2].name, data2.contacts[2].phonenumber)使用 protoc.new() 创建一个编译器实例加载 .proto 文件 addressbook.proto syntax proto3; package cauchy; message Person {string name 1; int32 age 2; enum PhoneType {MOBILE 0; HOME 1;WORK 2;}message PhoneNumber {string number 1;PhoneType type 2; }repeated PhoneNumber phones 3; }main.lua local protoc require protoc local pb require pblocal data {name cauchy,age 20,phones {{ number 1234567890, type 1 },{ number 0987654321 }} }local p protoc.new()local addressbook io.open(addressbook.proto):read(a) p:load(addressbook)local bytes assert(pb.encode(cauchy.Person, data)) local data2 assert(pb.decode(cauchy.Person, bytes)) print(data2.name, data2.age, data2.phones[1].number, data2.phones[1].type)for name, id, types in pb.fields(cauchy.Person) do print(name, id, types) end 由于我是通过 luaver 管理 luarocks 和 lua使用 luarocks 分发 lua 模块安装的 lua-protobuf。所以上述路径下没有 pb.so 和 protoc.lua直接找到安装路径下的需要 luaver 使用 lua 和 luarocks。 不过使用者也可以直接拉取到执行脚本的路径下。 上述操作是在 lua 代码中直接通过导入 protoc.lua 文件来在运行时加载 .proto 文件的无需提前编译但是这样转换性能可能比较慢。 下面我们来安装 protoc 编译器 sudo apt updatesudo apt install -y protobuf-compiler protoc 默认安装在 /usr/bin/ 下。 执行 protoc -o addressbook.pb addressbook.proto 生成 .pb 文件。 .proto 文件以 Protocol Buffers 语言编写的接口定义文件,用来定义数据结构、服务接口等。 .pb 文件从 .proto 接口定义文件生成的目标语言代码文件而没有指定目标语言生成通用的二进制文件包含了编码后的 Protocol Buffers 数据。 local pb require pbpb.loadfile(./addressbook.pb)local data {name cauchy,age 20,phones {{ number 1234567890, type 1 },{ number 0987654321}} }local bytes pb.encode(cauchy.Person, data) print(pb.tohex(bytes))local data2 pb.decode(cauchy.Person, bytes) print(data2.phones[2].number, data2.phones[2].type)for name, id, types in pb.fields(cauchy.Person) do print(name, id, types) end 更多具体的 API 操作参考官方 GitHubhttps://github.com/starwing/lua-protobuf
http://www.hkea.cn/news/14328045/

相关文章:

  • 济源网站建设价格网页设计与制作课件清华大学
  • 一般公司网站用什么域名套餐广州哪里能看海
  • 网站建设公司推广广告语惠州做网站广告
  • 蒙古文网站建设汇报江苏住房城乡建设网站
  • 在线做编程题的网站自己做网站自己买服务器
  • asp网站模板下载爱心助学网站建设
  • 做网站客户需要提供的资料网页版原神
  • 网站备案 域名不是自己的网站定制开发怎么做
  • 网站备案链接代码网络营销的基本方式有哪些
  • 英文网站接单做翻译比wordpress轻量的
  • 小说网站开发需求分析全自动行业管理系统
  • 阿里云服务器创建多个网站中国企业排名前十
  • 国外 网页框架搭建的网站wordpress大淘客
  • 织梦游戏网站源码做租房信息网站
  • 信仰类型的企业网站重庆工程建设招标投标交易信息网
  • 买源码做网站做淘宝优惠券推广网站
  • 安徽网站建设哪家好wordpress自定义钩子
  • 怎样用网站做app网站建设链接
  • 合肥网站建设步骤江北网站建设
  • 网站开发 分工vultr服务器做网站
  • 湖南自考网站建设与管理怎挖掘网站关键词
  • 中小企业网站建设济南兴田德润厉害吗国内电子商务网站有哪些
  • 网站开发职业资格证书网站开发的功能需求
  • 一个虚拟空间做两个网站以前的网站忘了怎么办啊
  • 程序外包网站淘宝推广费用多少钱一天
  • 网站建设是那个行业怎么做营销策划方案
  • 单位网站建设实施方案厦门物流网站建设
  • 宁波建设系统网站同安网站建设
  • 北京城建道桥建设网站微信积分商城
  • 南宁网站设计wordpress直接发送密码