我正在研究数据序列化的节俭。但文档说
循环结构 - 结构只能包含在其之前声明的结构。结构体也不能包含自身
我们的要求之一是
- 结构A
- 子项目列表
- 项目(项目是结构 A )
- 子项目列表
所以阅读要求我在任何级别都不能拥有 Struct ?我可以像上面那样将它放在循环模型中吗? Struct不是Struct直接的成员,但它有一些其他成员并且包含struct。
他们的文档描述性不太好。
Thrift 中可能吗? protobuf支持吗?
最佳答案
根据this discussion ,这在 Thrift 中是不可能的。但是,有一种解决方法,可以使用整数对主列表进行索引。本质上,这是穷人指点的一种形式。
struct A
{
1: list<i32> subitems;
}
struct AllAs
{
1: list<A> items;
}
subitems 本质上是指向 AllAs.items 的指针列表
在 Protocol Buffers 中,这很简单:
message A {
repeated A subitems = 1;
}
关于protocol-buffers - Apache thrift,结构包含自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011701/