Skip to content

WasmGPU.python.bytes

Summary

WasmGPU.python.bytes returns a byte view of a Python interop handle region. Use this for raw serialization, hashing, and binary transport tasks.

Syntax

WasmGPU.python.bytes(handle: WasmNdarrayHandle): Uint8Array
const bytes = wgpu.python.bytes(handle);

Parameters

Name Type Required Description
handle WasmNdarrayHandle Yes Handle describing the Wasm ndarray payload.

Returns

Uint8Array - Byte slice covering handle.byteLength from handle.ptr.

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const handle = wgpu.python.sendNdarray(new Float32Array([1.5, 2.5]), { dtype: "f32", shape: [2], allocator: "heap" });
const bytes = wgpu.python.bytes(handle);
console.log(bytes.byteLength, bytes[0], bytes[1], bytes[2], bytes[3]);
wgpu.python.free(handle);

See Also