英文:
Convert class with interface field to protobuf
问题
syntax = "proto3";
message A {
string name = 1;
string occupation = 2;
oneof operable {
OperableA operable_a = 3;
OperableB operable_b = 4;
}
}
message OperableA {
string job = 1;
repeated string tasks = 2;
}
message OperableB {
int32 number_of_workers = 1;
repeated string skills = 2;
repeated string name_of_workers = 3;
}
英文:
I have a class with interface field and the interface has multiple implementations. I need to convert my class to protobuf, but I am not able to map the interface field, which is actually a type interface.
Here is my Java code for class structure:
class A {
String name;
String occupation;
Operable operable;
}
interface operable {
}
class OperableA implements operable {
String job;
List<String> tasks;
}
class OperableB implements operable {
int numberOfWorkers;
List<String> skills;
List<String> nameOfWorkers;
}
How can this structure be mapped in proto file, please help.
答案1
得分: 0
你不能在 Protocol Buffers 中像 这里 所描述的那样对类或接口进行继承建模,文档中提到:
> 不要寻找类继承相似的功能 - Protocol Buffers 并不支持这样的特性。
英文:
You cannot model class or interface inheritance in protobuf as described here which says
> Don't go looking for facilities similar to class inheritance, though – protocol buffers don't do that.
专注分享java语言的经验与见解,让所有开发者获益!
评论