Protocol buffers ProtoBuf支持多态性吗?
我有一个可以返回结果或null的服务,因此我将其定义为:Protocol buffers ProtoBuf支持多态性吗?,protocol-buffers,Protocol Buffers,我有一个可以返回结果或null的服务,因此我将其定义为: syntax = "proto3"; package package; import "google/protobuf/empty.proto"; service A { rpc getById (ASearchRequest) returns (AResponse) { } rpc getById (ASearchRequest) returns (google.protobuf.Empty) {
syntax = "proto3";
package package;
import "google/protobuf/empty.proto";
service A {
rpc getById (ASearchRequest) returns (AResponse) {
}
rpc getById (ASearchRequest) returns (google.protobuf.Empty) {
}
}
message AResponse {
string _id = 1;
string key = 2;
string name = 3;
}
message ASearchRequest {
required string id = 1;
}
但是编译器不会执行它,因此如何处理ProtoBuf中的可空响应类型?一个可能的解决方案可能是定义一个包含AResponse类型的单个可选成员的消息AnOptionalResponse。然后,返回optionalResponse,它可以是空消息,也可以是包含可选AResponse协议成员的消息 或者只是让AResponse中的所有字段都是可选的