阿里巴巴国际站,wordpress加载很慢,网站建设收益分析,一个网站有哪几种漏洞rpc全称远程过程控制#xff0c;说白了是一种对信息发送和接收的规则编写方法#xff0c;来自google#xff0c;这些规则会以protobuf代码存到proto文件里。我以autoGen中agent_worker.proto为例#xff0c;大概长这样
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;mapstring, string metadata 6;
}message RpcResponse {string request_id 1;Payload payload 2;string error 3;mapstring, 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:// agentidAGENT_ID// clientidCLIENT_IDstring destination 2;// This is either:// agentidAGENT_ID// clientidCLIENT_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头headerrpc采用更紧凑的编码方式具体我也不懂反正它的协议叫做gRPC。然后为了让rpc流行起来需要一个在各种语言中都能被使用的方法protobuf作为一种中间语言在编写后可以被编译成各种语言的版本然后供各语言的代码调用这个编译器叫protocc是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必选现在都是可选。