如何在proto中定义parentS < - > children关系
syntax = "proto3";
message Root {
repeated Category category = 2;
}
message Category {
string name = 2;
repeated Category parent = 3;
}
这里的关键是我希望能够召唤孩子们
MamyCategoryInstance
|
|--- FooCategoryInstance
...//
PapaCategoryInstance
|
|---- FooCategoryInstance
|---- BarCategoryInstance
谢谢
你不能。协议缓冲区是基于“树”的串行器,而不是基于“图形”的串行器。因此,对象只有一个语义父对象,这是隐式的 - 不是显式的。含义:
message Root {
repeated Category category = 2;
}
message Category {
string name = 2;
}
每个类别的父级只是:树中位于其上方的节点。如果尝试创建显式父关系,则序列化将因递归而失败。