Node.JS Buffers
Node.JS’s custom Buffer HostObjects.
extensions.NodeJsArrayBufferViewHostObjectHandler
extensions.NodeJsArrayBufferViewHostObjectHandler()
Support for deserializing ArrayBuffer views from NodeJS’s custom serialization.
NodeJS uses its own method of serializing ArrayBuffer views instead of the default V8 serialization. It encodes them in HostObject tag data (HostObject tags are the V8 serialization format’s way to allow an application to insert their own custom data into the serialized data).
Examples
Serialize a Buffer from Node.JS something like:
$ node --version
v22.4.0
$ node -e 'console.log(
require("v8").serialize(Uint8Array.from([1, 2, 3]))
.toString("base64"))'
/w9cAQMBAgM=
>>> from v8serialize import loads, TagReader
>>> from base64 import b64decode
>>> decode_steps = [TagReader(
=NodeJsArrayBufferViewHostObjectHandler()
... host_object_deserializer
... )]>>> loads(b64decode('/w9cAQMBAgM='), decode_steps=decode_steps)
b'\x01\x02\x03')) JSUint8Array(JSArrayBuffer(
Methods
Name | Description |
---|---|
deserialize_host_object | Read a HostObject from the stream as a Node.JS ArrayBuffer/TypedArray. |
serialize_host_object | Serialize JSDataView and JSTypedArray using Node.js’s custom HostObject format. |
deserialize_host_object
extensions.NodeJsArrayBufferViewHostObjectHandler.deserialize_host_object(
stream: ReadableTagStream, )
Read a HostObject from the stream as a Node.JS ArrayBuffer/TypedArray.
Returns
Name | Type | Description |
---|---|---|
JSDataView | JSTypedArray | The buffer wrapped in a view. |
Raises
Name | Type | Description |
---|---|---|
NodeJsArrayBufferViewHostObjectHandlerDecodeError | When the stream’s HostObject data is not a valid Node.JS Buffer. |
serialize_host_object
extensions.NodeJsArrayBufferViewHostObjectHandler.serialize_host_object(
stream: WritableTagStream,| JSTypedArray,
value: JSDataView )
Serialize JSDataView and JSTypedArray using Node.js’s custom HostObject format.
See Also
extensions.serialize_js_array_buffer_views_as_nodejs_host_object
extensions.serialize_js_array_buffer_views_as_nodejs_host_object(object,
value: /,
ctx: EncodeContext,next: EncodeNextFn,
)
Serialize JSDataView and JSTypedArray using node.js’s custom HostObject format.
Notes
This is an Object Mapper (SerializeObjectFn
) that can be used to encode JSDataView and JSTypedArray in the same custom HostObject format that Node.JS writes using the Node.JS v8.serialize()
function.
Because Node.JS is capable of reading the normal encoding of JSArrayBuffer
, JSDataView
and JSTypedArray
, this doesn’t need to be used to send data to Node.JS (unlike on the deserializing side, where NodeJsArrayBufferViewHostObjectHandler
must be used to read Node.JS’s custom encoding).
extensions.ViewFormat
extensions.ViewFormat(self,
int,
nodejs_code:
view_format: ArrayBufferViewStructFormat, )
extensions.NodeBufferFormat
extensions.NodeBufferFormat(self,
int | ArrayBufferViewTag | NodeBufferFormat,
value: )
extensions.NodeJsArrayBufferViewHostObjectHandlerDecodeError
extensions.NodeJsArrayBufferViewHostObjectHandlerDecodeError(self,
str,
message: *args: object,
int,
position:
data: ReadableBinary, )
Raised when decoding a HostObject as a Node.JS Buffer fails.