Apache thrift,结构包含自身
我正在研究数据序列化的节俭。但文档说
循环结构 - 结构只能包含在其之前声明的结构。结构体也不能包含自身
我们的要求之一是
- 结构体 A
- 子项目列表
- 项目(项目是结构 A )
- 子项目列表
所以阅读要求我不能在任何级别上拥有 Struct 本身?我可以像上面那样将它放在循环模型中吗? Struct 不是 Struct 的直接成员,但它有一些其他成员并且包含 struct。
他们的文档描述性不太好。
Thrift 中可能吗? protobuf支持吗?
I am looking into thrift for serialization of data. But Document says
cyclic structs - Structs can only contain structs that have been declared before it. A struct also cannot contain itself
One of our requirement is
- Struct A
- List of Child items
- Items(Items are Struct A )
- List of Child items
So reading requirement i can't have Struct within itself at any level? can i have it in cyclic model as i have it above. Struct is not member of Struct directly but it has some other member and it contains struct.
Their document is not so well descriptive.
Is it possible in Thrift? Does protobuf supports it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 此讨论,这在 Thrift 中是不可能的。但是,有一种解决方法,可以使用整数对主列表进行索引。本质上,这是穷人指针的一种形式。
subitems 本质上是指向 AllAs.items 的指针列表。
在 Protocol Buffers 中,它很简单:
According to this discussion, it's not possible in Thrift. However, there is a workaround of using integers to index into a master list. Essentially, this is a form of poor man's pointers.
subitems is essentially a list of pointers into AllAs.items
In Protocol Buffers, it's trivial:
是的,从 Thrift 0.9.2 开始支持此场景。
对于任何早期版本的 thrift,以下内容(故意)会导致编译器错误消息:
但仍然有一些警告。开发人员有责任不产生无限循环或钻石参考,例如
Yes, starting with Thrift 0.9.2 this scenario is supported.
With any earlier version of thrift the following (intentionally) lead to an compiler error message:
There are still a few caveats though. The deveoper is responsible for not producing endless loops or diamond references, like