這里關(guān)鍵的一點(diǎn)是要導(dǎo)入Google的的any.proto文件。如下的proto 文件:
import "google/protobuf/any.proto"
Service Hello{
rpc SayHello(MsgInfoBase)returns(google.protobuf.empty){};
}
message MsgInfoBase{
string id=1;
google.protobuf.any Data=2;//這樣就可以傳遞任意類型了。如Msg1,Msg2
}
message Msg1{
string Content=1;
bool result=2;
}
message Msg2{
string Name=1;
bool result=2;
}
客戶端上傳
MsgInfoBase msg = new MsgInfoBase();
Msg1 m1 = new Msg1();
msg.Data = Any.pack(m1);
服務(wù)端解析泛型類型
Msg1 m1=request.Data.Unpack<Msg1>();//這樣這個(gè)接口就可以傳遞泛型啦?。?!