高级序列化


【Advanced serialization】

子进程支持用于 IPC 的序列化机制,该机制基于 node:v8 模块的序列化 API,基于 HTML 结构化克隆算法。这通常更强大,并支持更多的内置 JavaScript 对象类型,例如 BigIntMapSetArrayBufferTypedArrayBufferErrorRegExp 等。

【Child processes support a serialization mechanism for IPC that is based on the serialization API of the node: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.】

然而,这种格式并不是 JSON 的完整超集,例如,设置在这些内置类型对象上的属性在序列化步骤中不会被传递。此外,性能可能与 JSON 不同,这取决于传入数据的结构。因此,使用此功能需要在调用 child_process.spawn()child_process.fork() 时,将 serialization 选项设置为 'advanced' 来选择启用。

【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().】