Skip to content

Node.js Interoperability

Vihan edited this page Nov 18, 2018 · 3 revisions

VSL is designed to have a consistent ABI for most types. For ICP the OS may provide a mechanism but you can still construct objects which can be passed through Buffers. This is the equivalent of the vsl/native.h for Node.js.

import * as VSL from 'vsl/interop';

Data Types

let vslString = VSL.String.from("Hello, World!"); // Wraps in VSL string
vslString.toBuffer();
vslString.toString();
vslString.toArrayBuffer();
let vslNumber = VSL.Number.from(123, {
    width: 64, // default 32 on 32-bit systems and 64 on 64-bit systems
    signed: true, // default `true`
}); // Converts to a Int dependent on system settings
vslNumber.toBuffer();
vslNumber.toNumber();
vslNumber.toArrayBuffer();
let vslBool = VSL.Boolean.from(true);
vslBool.toBuffer();
vslBool.toNumber();
vslBool.toArrayBuffer();

Usage in VSL

The easiest way to unwrap these objects is then by a bit case:

let stdinData: ByteSequence = ...;
let unwrapped = String[]::stdinData;