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

网站建设亿码酷专注推广关键词排名

网站建设亿码酷专注,推广关键词排名,广州市门户网站建设,家乐福超市网上购物rpc全称远程过程控制,说白了是一种对信息发送和接收的规则编写方法,来自google,这些规则会以protobuf代码存到proto文件里。我以autoGen中agent_worker.proto为例,大概长这样 syntax "proto3";package agents;option …

rpc全称远程过程控制,说白了是一种对信息发送和接收的规则编写方法,来自google,这些规则会以protobuf代码存到proto文件里。我以autoGen中agent_worker.proto为例,大概长这样

syntax = "proto3";package agents;option csharp_namespace = "Microsoft.AutoGen.Protobuf";import "cloudevent.proto";
import "google/protobuf/any.proto";message AgentId {string type = 1;string key = 2;
}message Payload {string data_type = 1;string data_content_type = 2;bytes data = 3;
}message RpcRequest {string request_id = 1;optional AgentId source = 2;AgentId target = 3;string method = 4;Payload payload = 5;map<string, string> metadata = 6;
}message RpcResponse {string request_id = 1;Payload payload = 2;string error = 3;map<string, string> metadata = 4;
}message RegisterAgentTypeRequest {string type = 1;
}message RegisterAgentTypeResponse {
}message TypeSubscription {string topic_type = 1;string agent_type = 2;
}message TypePrefixSubscription {string topic_type_prefix = 1;string agent_type = 2;
}message Subscription {string id = 1;oneof subscription {TypeSubscription typeSubscription = 2;TypePrefixSubscription typePrefixSubscription = 3;}
}message AddSubscriptionRequest {Subscription subscription = 1;
}message AddSubscriptionResponse {
}message RemoveSubscriptionRequest {string id = 1;
}message RemoveSubscriptionResponse {
}message GetSubscriptionsRequest {}
message GetSubscriptionsResponse {repeated Subscription subscriptions = 1;
}message Message {oneof message {RpcRequest request = 1;RpcResponse response = 2;io.cloudevents.v1.CloudEvent cloudEvent = 3;}
}message SaveStateRequest {AgentId agentId = 1;
}message SaveStateResponse {string state = 1;optional string error = 2;
}message LoadStateRequest {AgentId agentId = 1;string state = 2;
}
message LoadStateResponse {optional string error = 1;
}message ControlMessage {// A response message should have the same id as the request messagestring rpc_id = 1;// This is either:// agentid=AGENT_ID// clientid=CLIENT_IDstring destination = 2;// This is either:// agentid=AGENT_ID// clientid=CLIENT_ID// Empty string means the message is a responseoptional string respond_to = 3;// One of://     SaveStateRequest saveStateRequest = 2;//     SaveStateResponse saveStateResponse = 3;//     LoadStateRequest loadStateRequest = 4;//     LoadStateResponse loadStateResponse = 5;google.protobuf.Any rpcMessage = 4;
}service AgentRpc {rpc OpenChannel (stream Message) returns (stream Message);rpc OpenControlChannel (stream ControlMessage) returns (stream ControlMessage);rpc RegisterAgent(RegisterAgentTypeRequest) returns (RegisterAgentTypeResponse);rpc AddSubscription(AddSubscriptionRequest) returns (AddSubscriptionResponse);rpc RemoveSubscription(RemoveSubscriptionRequest) returns (RemoveSubscriptionResponse);rpc GetSubscriptions(GetSubscriptionsRequest) returns (GetSubscriptionsResponse);
}

为什么要用protobuf定义rpc呢?首先,rpc是一种比http和restapi更轻量的协议,应该都知道http要有http头,header,rpc采用更紧凑的编码方式,具体我也不懂,反正它的协议叫做gRPC。然后,为了让rpc流行起来,需要一个在各种语言中都能被使用的方法,protobuf作为一种中间语言,在编写后可以被编译成各种语言的版本,然后供各语言的代码调用,这个编译器叫protoc,c是complier。

你可以简单地把proto代码看作是对数据结构的定义,就像python的dataclass一样。有几个字段需要解释:
oneof:它里面会包含多个变量名,在你实例化对应数据类时,只能出现其中一个变量,其他的不可用。
map:看作dict。
repeat:看作list。
packed:是跟在某些数据类型的变量后面的定义,用于注明这些值是否需要精简地序列化,proto3里默认开启。
enum Status:定义一个枚举数据类型Status。像python一样,Status会定义一个名字并附上具体的值,之后可以用Status定义其他变量的类型。
message:定义发送的信息的数据结构。
数据类型:在变量名前面注明,可以是某个定义完的数据结构,和python一样。
变量 = 数字:数字是编号,用于数据在序列化和反序列化时作标记和识别。因此,它可以不是顺序的,可以随便定义(但是最好别这样做)。
service:与message平级,用于定义一个服务所提供的所有rpc服务。
rpc:注明这是一个rpc服务,将注明发送和接收的message样式。
stream:注明这是一个流式传输。如果不是流式传输,rpc服务只会做到“客户端发送message,服务端返回对应的message”,就像一个request一样。
nest message:它只是一种嵌套形式,在message里定义一个message,毕竟message也是一个变量类型。
reserved:可以用来预留编号和变量名。
DynamicMessage:它用来支持动态解析,在不知道来犯的message类型时,对方可能同时传过来一个proto文件的descriptor文件,用它来动态解析message。

protobuf已经到protobuf3了,之前所有参数都可以注明可选or必选,现在都是可选。

http://www.fp688.cn/news/143788.html

相关文章:

  • 做ppt的素材免费网站百度网首页官网
  • 校园电商平台网站建设google搜索引擎入口google
  • 一起装修网装修公司河南整站百度快照优化
  • 网站自己怎么做东莞关键词seo优化
  • 怎么在公众号做影视网站百度网页收录
  • 企业网站如何做seo如何给企业做网络推广
  • 手机网价格直降描述优化方法
  • 学网站建设专业前景网络营销策划步骤
  • 温州建设局网站sem专业培训公司
  • 阳东区网络问政平台关键词优化推广公司排名
  • mysql做网站怎么查看数据专业seo站长工具全面查询网站
  • wordpress仿站抓取软件人教版优化设计电子书
  • 荆州做网站的公司济南网站制作平台
  • 石家庄网站建设平台有哪些网店产品seo如何优化
  • 响应式网站开发教程pdf北京网络优化推广公司
  • 杭州做网站博客对网络推广的理解
  • 万优网站建设竞价排名的服务模式是
  • vs210做网站日本shopify独立站
  • 网站首图怎么做软件推广平台
  • 做网站必须内容真实性百度一下一下你就知道
  • 网站服务器租用价格 百度一下win7系统优化
  • 镇江方圆建设监理咨询有限公司网站站长工具精品
  • 网络推广怎么操作seo推广招聘
  • 企业网站定制开发百度有什么办法刷排名
  • 游戏登录器列表更新网站建设南昌网站设计
  • 网站建设论文答辩百搜网络科技有限公司
  • 疯狗做网站cnfg产品营销方案
  • 网站制作设计说明网络营销推广的目的
  • 商贸公司寮步网站建设极致发烧上热门最火标题
  • 做网站的广告图片广州seo技术优化网站seo