高级序列化
子进程支持 IPC 的序列化机制,该机制基于 v8
模块的序列化 API,基于 HTML 结构化克隆算法。
这通常功能更强大,支持更多内置的 JavaScript 对象类型,例如 BigInt
、Map
和 Set
、ArrayBuffer
和 TypedArray
、Buffer
、Error
、RegExp
等。
但是,这种格式不是 JSON 的完整超集,例如 在此类内置类型的对象上设置的属性不会通过序列化步骤传递。
此外,性能可能不等同于 JSON,具体取决于传递数据的结构。
因此,此功能需要在调用 child_process.spawn()
或 child_process.fork()
时通过将 serialization
选项设置为 'advanced'
来选择加入。
Child processes support a serialization mechanism for IPC that is based on the
serialization API of the v8
module, based on the
HTML structured clone algorithm. This is generally more powerful and
supports more built-in JavaScript object types, such as BigInt
, Map
and Set
, ArrayBuffer
and TypedArray
, Buffer
, Error
, RegExp
etc.
However, this format is not a full superset of JSON, and e.g. properties set on
objects of such built-in types will not be passed on through the serialization
step. Additionally, performance may not be equivalent to that of JSON, depending
on the structure of the passed data.
Therefore, this feature requires opting in by setting the
serialization
option to 'advanced'
when calling child_process.spawn()
or child_process.fork()
.