TL;DR:如果你已经有 .proto 或 .fbs Schema,并且希望支持共享/循环引用,那么使用 Fory 编译器时你可以保留这些 Schema,只需添加一小组 Fory 选项,再通过 foryc 生成 Fory 支持语言中的原生习惯模型,随后即可序列化对象图,无需手工通过 *_id 重建关联,也无需把整份 Schema 重写为 Fory Schema。
- GitHub: https://github.com/apache/fory
- 编译器文档: https://fory.apache.org/docs/compiler
- 安装:
pip install fory-compiler
Protobuf 与 FlatBuffers Schema 的缺口
很多生产模型本质上是对象图,而不是纯树结构:
- 父指针(
child.parent) - 共享节点(两 条边指向同一个对象)
- 循环(A -> B -> A)
在原生 protobuf 或 FlatBuffers Schema 设计中,这类关系通常只能通过手工 ID 链接(parent_id、child_ids)间接表示,并在解码后由应用代码重建对象关系。
Apache Fory 增加了 Schema 级引用跟踪能力,可以通过 Fory 选项在 protobuf/FlatBuffers 源文件中直接声明这类对象图语义。
保留 .proto 与 .fbs,补充对象图语义
你不需要先把所有内容重写为 .fdl。
- 对 protobuf 输入,使用
(fory).ref、(fory).weak_ref等选项。 - 对 FlatBuffers 输入,使用
fory_ref:true、fory_weak_ref:true等属性。 - 使用
foryc编译。 - 生成 Fory 模型并使用 Fory 编码格式。
重要说明:这个路径复用了 Schema 的语法与结构,但序列化输出是 Fory 二进制协议,不与 protobuf/FlatBuffers 编码格式兼容。
