配置
本页介绍 Fory 配置参数和语言模式。
Fory 类
主要序列化接口:
class Fory:
def __init__(
self,
xlang: bool = False,
ref: bool = False,
strict: bool = True,
compatible: bool = False,
max_depth: int = 50
)
ThreadSafeFory 类
使用线程本地存储的线程安全序列化接口:
class ThreadSafeFory:
def __init__(
self,
xlang: bool = False,
ref: bool = False,
strict: bool = True,
compatible: bool = False,
max_depth: int = 50
)
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
xlang | bool | False | 启用跨语言序列化。当为 False 时,启用 Python 原生模式,支持所有 Python 对象。当为 True 时,启用跨语言模式,兼容 Java、Go、Rust 等。 |
ref | bool | False | 启用引用跟踪以支持共享/循环引用。如果数据没有共享引用,禁用此选项可获得更好性能。 |
strict | bool | True | 出于安全考虑需要类型注册。生产环境强烈推荐。仅在受信任的环境中禁用。 |
compatible | bool | False | 在跨语言模式中启用 schema 演化,允许在保持兼容性的同时添加/删除字段。 |
max_depth | int | 50 | 反序列化的最大深度,用于安全防护,防止栈溢出攻击。 |