我有一个用 GO 编写的 grpc 客户端和一个用 Java 编写的 grpc 服务器(两者都使用相同的原型文件(语法 2)。
我的 grpc 方法接收一条可能包含扩展名的消息。我能够在客户端构建包含所需扩展的消息并将其发送到服务器。但是当我尝试阅读服务器上的消息时,我的扩展名作为未知字段可用。(换句话说, Java 中的entity.hasExtension(extension)返回 false)。
所以我的问题是 grpc 是否允许在作为方法参数提供的消息中使用扩展。如果没有,有没有办法将未知字段转换为特定类型的字段?
我的原型文件:
syntax = "proto2";
// proto file used as source for go client and java server as well
package my_services;
import "basic_types.proto";
// import "extension_types.proto";
// do not delete: options for generating java code
option java_multiple_files = true;
option java_package = "myservice.grpc";
option java_outer_classname = "MyServiceWrapper";
option objc_class_prefix = "Foo";
// Interface exposed by the server.
service DataService {
// Obtains all objects satisfying the request message
rpc MyMethod(DataRequest) returns (DataResponse) {}
}
message DataRequest {
optional IdDefinition id = 1;
repeated basic_types.Entity templates = 2;
}
message DataResponse {
repeated IdDefinition id = 1;
optional basic_types.DataResult result = 2;
}
message IdDefinition {
optional int32 myid = 1;
}
basic_types.Entity是包含扩展的基本消息:
message Entity {
extensions 1 to max;
}
并且可以像这样扩展:
extend basic_types.Entity {
optional Foo foo = 1000;
optional Bar bar = 1001;
}
任何帮助或提示将不胜感激。