Source code
Revision control
Copy as Markdown
Other Tools
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
// Trust me, you don't want to mess with it!
import { UniFFITypeError } from "moz-src:///toolkit/components/uniffi-js/js/UniFFI.sys.mjs";
// Objects intended to be used in the unit tests
export var UnitTestObjs = {};
/**
* Handler for a single UniFFI CallbackInterface
*
* This class stores objects that implement a callback interface in a handle
* map, allowing them to be referenced by the Rust code using an integer
* handle.
*
* While the callback object is stored in the map, it allows the Rust code to
* call methods on the object using the callback object handle, a method id,
* and an ArrayBuffer packed with the method arguments.
*
* When the Rust code drops its reference, it sends a call with the methodId=0,
* which causes callback object to be removed from the map.
*/
class UniFFICallbackHandler {
#name;
#interfaceId;
#handleCounter;
#handleMap;
#methodHandlers;
#allowNewCallbacks
/**
* Create a UniFFICallbackHandler
* @param {string} name - Human-friendly name for this callback interface
* @param {int} interfaceId - Interface ID for this CallbackInterface.
* @param {UniFFICallbackMethodHandler[]} methodHandlers -- UniFFICallbackHandler for each method, in the same order as the UDL file
*/
constructor(name, interfaceId, methodHandlers) {
this.#name = name;
this.#interfaceId = interfaceId;
this.#handleCounter = 0;
this.#handleMap = new Map();
this.#methodHandlers = methodHandlers;
this.#allowNewCallbacks = true;
UniFFIScaffolding.registerCallbackHandler(this.#interfaceId, this);
Services.obs.addObserver(this, "xpcom-shutdown");
}
/**
* Store a callback object in the handle map and return the handle
*
* @param {obj} callbackObj - Object that implements the callback interface
* @returns {int} - Handle for this callback object, this is what gets passed back to Rust.
*/
storeCallbackObj(callbackObj) {
if (!this.#allowNewCallbacks) {
throw new UniFFIError(`No new callbacks allowed for ${this.#name}`);
}
// Increment first. This way handles start at `1` and we can use `0` to represent a NULL
// handle.
this.#handleCounter += 1;
const handle = this.#handleCounter;
this.#handleMap.set(handle, new UniFFICallbackHandleMapEntry(callbackObj, Components.stack.caller.formattedStack.trim()));
return handle;
}
/**
* Get a previously stored callback object
*
* @param {int} handle - Callback object handle, returned from `storeCallbackObj()`
* @returns {obj} - Callback object
*/
getCallbackObj(handle) {
const callbackObj = this.#handleMap.get(handle).callbackObj;
if (callbackObj === undefined) {
throw new UniFFIError(`${this.#name}: invalid callback handle id: ${handle}`);
}
return callbackObj;
}
/**
* Get a UniFFICallbackMethodHandler
*
* @param {int} methodId - index of the method
* @returns {UniFFICallbackMethodHandler}
*/
getMethodHandler(methodId) {
const methodHandler = this.#methodHandlers[methodId];
if (methodHandler === undefined) {
throw new UniFFIError(`${this.#name}: invalid method id: ${methodId}`)
}
return methodHandler;
}
/**
* Set if new callbacks are allowed for this handler
*
* This is called with false during shutdown to ensure the callback maps don't
* prevent JS objects from being GCed.
*/
setAllowNewCallbacks(allow) {
this.#allowNewCallbacks = allow
}
/**
* Check if there are any registered callbacks in the handle map
*
* This is used in the unit tests
*/
hasRegisteredCallbacks() {
return this.#handleMap.size > 0;
}
/**
* Check that no callbacks are currently registered
*
* If there are callbacks registered a UniFFIError will be thrown. This is
* called during shutdown to generate an alert if there are leaked callback
* interfaces.
*/
assertNoRegisteredCallbacks() {
if (this.#handleMap.size > 0) {
const entry = this.#handleMap.values().next().value;
throw new UniFFIError(`UniFFI interface ${this.#name} has ${this.#handleMap.size} registered callbacks at xpcom-shutdown. This likely indicates a UniFFI callback leak.\nStack trace for the first leaked callback:\n${entry.stackTrace}.`);
}
}
/**
* Invoke a method on a stored callback object
* @param {int} handle - Object handle
* @param {int} methodId - Method index (0-based)
* @param {UniFFIScaffoldingValue[]} args - Arguments to pass to the method
*/
call(handle, methodId, ...args) {
try {
const callbackObj = this.getCallbackObj(handle);
const methodHandler = this.getMethodHandler(methodId);
methodHandler.call(callbackObj, args);
} catch (e) {
console.error(`internal error invoking callback: ${e}`)
}
}
/**
* Invoke a method on a stored callback object
* @param {int} handle - Object handle
* @param {int} methodId - Method index (0-based)
* @param {UniFFIScaffoldingValue[]} args - Arguments to pass to the method
*/
async callAsync(handle, methodId, ...args) {
const callbackObj = this.getCallbackObj(handle);
const methodHandler = this.getMethodHandler(methodId);
try {
const returnValue = await methodHandler.call(callbackObj, args);
return methodHandler.lowerReturn(returnValue);
} catch(e) {
return methodHandler.lowerError(e)
}
}
/**
* Destroy a stored callback object
* @param {int} handle - Object handle
*/
destroy(handle) {
this.#handleMap.delete(handle);
}
/**
* xpcom-shutdown observer method
*
* This handles:
* - Deregistering ourselves as the UniFFI callback handler
* - Checks for any leftover stored callbacks which indicate memory leaks
*/
observe(aSubject, aTopic, aData) {
if (aTopic == "xpcom-shutdown") {
try {
this.setAllowNewCallbacks(false);
this.assertNoRegisteredCallbacks();
UniFFIScaffolding.deregisterCallbackHandler(this.#interfaceId);
} catch (ex) {
console.error(`UniFFI Callback interface error during xpcom-shutdown: ${ex}`);
Cc["@mozilla.org/xpcom/debug;1"]
.getService(Ci.nsIDebug2)
.abort(ex.filename, ex.lineNumber);
}
}
}
}
/**
* Handles calling a single method for a callback interface
*/
class UniFFICallbackMethodHandler {
#name;
#argsConverters;
#returnConverter;
#errorConverter;
/**
* Create a UniFFICallbackMethodHandler
* @param {string} name -- Name of the method to call on the callback object
* @param {FfiConverter[]} argsConverters - FfiConverter for each argument type
*/
constructor(name, argsConverters, returnConverter, errorConverter) {
this.#name = name;
this.#argsConverters = argsConverters;
this.#returnConverter = returnConverter;
this.#errorConverter = errorConverter;
}
call(callbackObj, args) {
const convertedArgs = this.#argsConverters.map((converter, i) => converter.lift(args[i]));
return callbackObj[this.#name](...convertedArgs);
}
lowerReturn(returnValue) {
return {
code: "success",
data: this.#returnConverter(returnValue),
};
}
lowerError(error) {
return {
code: "error",
data: this.#errorConverter(error),
};
}
toString() {
return `CallbackMethodHandler(${this.#name})`
}
}
/**
* UniFFICallbackHandler.handleMap entry
*
* @property callbackObj - Callback object, this must implement the callback interface.
* @property {string} stackTrace - Stack trace from when the callback object was registered. This is used to proved extra context when debugging leaked callback objects.
*/
class UniFFICallbackHandleMapEntry {
constructor(callbackObj, stackTrace) {
this.callbackObj = callbackObj;
this.stackTrace = stackTrace
}
}
let lazy = {};
ChromeUtils.defineLazyGetter(lazy, "decoder", () => new TextDecoder());
ChromeUtils.defineLazyGetter(lazy, "encoder", () => new TextEncoder());
// Write/Read data to/from an ArrayBuffer
class ArrayBufferDataStream {
constructor(arrayBuffer) {
this.dataView = new DataView(arrayBuffer);
this.pos = 0;
}
readUint8() {
let rv = this.dataView.getUint8(this.pos);
this.pos += 1;
return rv;
}
writeUint8(value) {
this.dataView.setUint8(this.pos, value);
this.pos += 1;
}
readUint16() {
let rv = this.dataView.getUint16(this.pos);
this.pos += 2;
return rv;
}
writeUint16(value) {
this.dataView.setUint16(this.pos, value);
this.pos += 2;
}
readUint32() {
let rv = this.dataView.getUint32(this.pos);
this.pos += 4;
return rv;
}
writeUint32(value) {
this.dataView.setUint32(this.pos, value);
this.pos += 4;
}
readUint64() {
let rv = this.dataView.getBigUint64(this.pos);
this.pos += 8;
return Number(rv);
}
writeUint64(value) {
this.dataView.setBigUint64(this.pos, BigInt(value));
this.pos += 8;
}
readInt8() {
let rv = this.dataView.getInt8(this.pos);
this.pos += 1;
return rv;
}
writeInt8(value) {
this.dataView.setInt8(this.pos, value);
this.pos += 1;
}
readInt16() {
let rv = this.dataView.getInt16(this.pos);
this.pos += 2;
return rv;
}
writeInt16(value) {
this.dataView.setInt16(this.pos, value);
this.pos += 2;
}
readInt32() {
let rv = this.dataView.getInt32(this.pos);
this.pos += 4;
return rv;
}
writeInt32(value) {
this.dataView.setInt32(this.pos, value);
this.pos += 4;
}
readInt64() {
let rv = this.dataView.getBigInt64(this.pos);
this.pos += 8;
return Number(rv);
}
writeInt64(value) {
this.dataView.setBigInt64(this.pos, BigInt(value));
this.pos += 8;
}
readFloat32() {
let rv = this.dataView.getFloat32(this.pos);
this.pos += 4;
return rv;
}
writeFloat32(value) {
this.dataView.setFloat32(this.pos, value);
this.pos += 4;
}
readFloat64() {
let rv = this.dataView.getFloat64(this.pos);
this.pos += 8;
return rv;
}
writeFloat64(value) {
this.dataView.setFloat64(this.pos, value);
this.pos += 8;
}
writeString(value) {
// Note: in order to efficiently write this data, we first write the
// string data, reserving 4 bytes for the size.
const dest = new Uint8Array(this.dataView.buffer, this.pos + 4);
const encodeResult = lazy.encoder.encodeInto(value, dest);
if (encodeResult.read != value.length) {
throw new UniFFIError(
"writeString: out of space when writing to ArrayBuffer. Did the computeSize() method returned the wrong result?"
);
}
const size = encodeResult.written;
// Next, go back and write the size before the string data
this.dataView.setUint32(this.pos, size);
// Finally, advance our position past both the size and string data
this.pos += size + 4;
}
readString() {
const size = this.readUint32();
const source = new Uint8Array(this.dataView.buffer, this.pos, size)
const value = lazy.decoder.decode(source);
this.pos += size;
return value;
}
readBytes() {
const size = this.readInt32();
const bytes = new Uint8Array(this.dataView.buffer, this.pos, size);
this.pos += size;
return bytes
}
writeBytes(value) {
this.writeUint32(value.length);
value.forEach((elt) => {
this.writeUint8(elt);
})
}
// Reads a pointer from the data stream
// UniFFI Pointers are **always** 8 bytes long. That is enforced
// by the C++ and Rust Scaffolding code.
readPointer(pointerId) {
const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos);
this.pos += 8;
return res;
}
// Writes a pointer into the data stream
// UniFFI Pointers are **always** 8 bytes long. That is enforced
// by the C++ and Rust Scaffolding code.
writePointer(pointerId, value) {
UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos);
this.pos += 8;
}
}
function handleRustResult(result, liftCallback, liftErrCallback) {
switch (result.code) {
case "success":
return liftCallback(result.data);
case "error":
throw liftErrCallback(result.data);
case "internal-error":
if (result.data) {
throw new UniFFIInternalError(FfiConverterString.lift(result.data));
} else {
throw new UniFFIInternalError("Unknown error");
}
default:
throw new UniFFIError(`Unexpected status code: ${result.code}`);
}
}
class UniFFIError {
constructor(message) {
this.message = message;
}
toString() {
return `UniFFIError: ${this.message}`
}
}
class UniFFIInternalError extends UniFFIError {}
// Base class for FFI converters
class FfiConverter {
// throw `UniFFITypeError` if a value to be converted has an invalid type
static checkType(value) {
if (value === undefined ) {
throw new UniFFITypeError(`undefined`);
}
if (value === null ) {
throw new UniFFITypeError(`null`);
}
}
}
// Base class for FFI converters that lift/lower by reading/writing to an ArrayBuffer
class FfiConverterArrayBuffer extends FfiConverter {
static lift(buf) {
return this.read(new ArrayBufferDataStream(buf));
}
static lower(value) {
const buf = new ArrayBuffer(this.computeSize(value));
const dataStream = new ArrayBufferDataStream(buf);
this.write(dataStream, value);
return buf;
}
/**
* Computes the size of the value.
*
* @param {*} _value
* @return {number}
*/
static computeSize(_value) {
throw new UniFFIInternalError("computeSize() should be declared in the derived class");
}
/**
* Reads the type from a data stream.
*
* @param {ArrayBufferDataStream} _dataStream
* @returns {any}
*/
static read(_dataStream) {
throw new UniFFIInternalError("read() should be declared in the derived class");
}
/**
* Writes the type to a data stream.
*
* @param {ArrayBufferDataStream} _dataStream
* @param {any} _value
*/
static write(_dataStream, _value) {
throw new UniFFIInternalError("write() should be declared in the derived class");
}
}
// Symbols that are used to ensure that Object constructors
// can only be used with a proper UniFFI pointer
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
const constructUniffiObject = Symbol("constructUniffiObject");
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
/**
* asyncRoundtripF32
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripF32(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterFloat32.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
113, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_f32
FfiConverterFloat32.lower(v),
)
return handleRustResult(
result,
FfiConverterFloat32.lift.bind(FfiConverterFloat32),
null,
)
}
/**
* asyncRoundtripF64
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripF64(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterFloat64.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
114, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_f64
FfiConverterFloat64.lower(v),
)
return handleRustResult(
result,
FfiConverterFloat64.lift.bind(FfiConverterFloat64),
null,
)
}
/**
* asyncRoundtripI16
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripI16(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterInt16.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
115, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_i16
FfiConverterInt16.lower(v),
)
return handleRustResult(
result,
FfiConverterInt16.lift.bind(FfiConverterInt16),
null,
)
}
/**
* asyncRoundtripI32
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripI32(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterInt32.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
116, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_i32
FfiConverterInt32.lower(v),
)
return handleRustResult(
result,
FfiConverterInt32.lift.bind(FfiConverterInt32),
null,
)
}
/**
* asyncRoundtripI64
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripI64(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterInt64.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
117, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_i64
FfiConverterInt64.lower(v),
)
return handleRustResult(
result,
FfiConverterInt64.lift.bind(FfiConverterInt64),
null,
)
}
/**
* asyncRoundtripI8
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripI8(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterInt8.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
118, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_i8
FfiConverterInt8.lower(v),
)
return handleRustResult(
result,
FfiConverterInt8.lift.bind(FfiConverterInt8),
null,
)
}
/**
* asyncRoundtripMap
* @param {object} v
* @returns {Promise<object>}}
*/
export async function asyncRoundtripMap(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterMapStringString.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
119, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_map
FfiConverterMapStringString.lower(v),
)
return handleRustResult(
result,
FfiConverterMapStringString.lift.bind(FfiConverterMapStringString),
null,
)
}
/**
* asyncRoundtripObj
* @param {AsyncInterface} v
* @returns {Promise<AsyncInterface>}}
*/
export async function asyncRoundtripObj(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterTypeAsyncInterface.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
120, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_obj
FfiConverterTypeAsyncInterface.lower(v),
)
return handleRustResult(
result,
FfiConverterTypeAsyncInterface.lift.bind(FfiConverterTypeAsyncInterface),
null,
)
}
/**
* asyncRoundtripString
* @param {string} v
* @returns {Promise<string>}}
*/
export async function asyncRoundtripString(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterString.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
121, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_string
FfiConverterString.lower(v),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
/**
* asyncRoundtripU16
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripU16(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterUInt16.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
122, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_u16
FfiConverterUInt16.lower(v),
)
return handleRustResult(
result,
FfiConverterUInt16.lift.bind(FfiConverterUInt16),
null,
)
}
/**
* asyncRoundtripU32
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripU32(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterUInt32.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
123, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_u32
FfiConverterUInt32.lower(v),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* asyncRoundtripU64
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripU64(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterUInt64.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
124, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_u64
FfiConverterUInt64.lower(v),
)
return handleRustResult(
result,
FfiConverterUInt64.lift.bind(FfiConverterUInt64),
null,
)
}
/**
* asyncRoundtripU8
* @param {number} v
* @returns {Promise<number>}}
*/
export async function asyncRoundtripU8(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterUInt8.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
125, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_u8
FfiConverterUInt8.lower(v),
)
return handleRustResult(
result,
FfiConverterUInt8.lift.bind(FfiConverterUInt8),
null,
)
}
/**
* asyncRoundtripVec
* @param {Array.<number>} v
* @returns {Promise<Array.<number>>}}
*/
export async function asyncRoundtripVec(
v) {
if (v instanceof UniffiSkipJsTypeCheck) {
v = v.value;
} else {
FfiConverterSequenceUInt32.checkType(v);
}
const result = await UniFFIScaffolding.callAsync(
126, // uniffi_uniffi_bindings_tests_fn_func_async_roundtrip_vec
FfiConverterSequenceUInt32.lower(v),
)
return handleRustResult(
result,
FfiConverterSequenceUInt32.lift.bind(FfiConverterSequenceUInt32),
null,
)
}
/**
* asyncThrowError
*/
export async function asyncThrowError() {
const result = await UniFFIScaffolding.callAsync(
127, // uniffi_uniffi_bindings_tests_fn_func_async_throw_error
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* cloneInterface
* @param {TestInterface} int
* @returns {TestInterface}
*/
export function cloneInterface(
int) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeTestInterface.checkType(int);
}
const result = UniFFIScaffolding.callSync(
128, // uniffi_uniffi_bindings_tests_fn_func_clone_interface
FfiConverterTypeTestInterface.lower(int),
)
return handleRustResult(
result,
FfiConverterTypeTestInterface.lift.bind(FfiConverterTypeTestInterface),
null,
)
}
/**
* createAsyncTestTraitInterface
* @param {number} value
* @returns {Promise<AsyncTestTraitInterface>}}
*/
export async function createAsyncTestTraitInterface(
value) {
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
129, // uniffi_uniffi_bindings_tests_fn_func_create_async_test_trait_interface
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
FfiConverterTypeAsyncTestTraitInterface.lift.bind(FfiConverterTypeAsyncTestTraitInterface),
null,
)
}
/**
* Create an implementation of the interface in Rust
* @param {number} value
* @returns {TestTraitInterface}
*/
export function createTestTraitInterface(
value) {
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = UniFFIScaffolding.callSync(
130, // uniffi_uniffi_bindings_tests_fn_func_create_test_trait_interface
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
FfiConverterTypeTestTraitInterface.lift.bind(FfiConverterTypeTestTraitInterface),
null,
)
}
/**
* funcWithDefault
* @param {string} arg
* @returns {string}
*/
export function funcWithDefault(
arg = "DEFAULT") {
if (arg instanceof UniffiSkipJsTypeCheck) {
arg = arg.value;
} else {
FfiConverterString.checkType(arg);
}
const result = UniFFIScaffolding.callSync(
131, // uniffi_uniffi_bindings_tests_fn_func_func_with_default
FfiConverterString.lower(arg),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
/**
* funcWithError
* @param {number} input
*/
export function funcWithError(
input) {
if (input instanceof UniffiSkipJsTypeCheck) {
input = input.value;
} else {
FfiConverterUInt32.checkType(input);
}
const result = UniFFIScaffolding.callSync(
132, // uniffi_uniffi_bindings_tests_fn_func_func_with_error
FfiConverterUInt32.lower(input),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* funcWithFlatError
* @param {number} input
*/
export function funcWithFlatError(
input) {
if (input instanceof UniffiSkipJsTypeCheck) {
input = input.value;
} else {
FfiConverterUInt32.checkType(input);
}
const result = UniFFIScaffolding.callSync(
133, // uniffi_uniffi_bindings_tests_fn_func_func_with_flat_error
FfiConverterUInt32.lower(input),
)
return handleRustResult(
result,
(result) => undefined,
FfiConverterTypeTestFlatError.lift.bind(FfiConverterTypeTestFlatError),
)
}
/**
* Test a multi-word argument. `the_argument` should be normalized to the naming style of the
* foreign language.
* @param {string} theArgument
* @returns {string}
*/
export function funcWithMultiWordArg(
theArgument) {
if (theArgument instanceof UniffiSkipJsTypeCheck) {
theArgument = theArgument.value;
} else {
FfiConverterString.checkType(theArgument);
}
const result = UniFFIScaffolding.callSync(
134, // uniffi_uniffi_bindings_tests_fn_func_func_with_multi_word_arg
FfiConverterString.lower(theArgument),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
/**
* getCustomTypesDemo
* @returns {Promise<CustomTypesDemo>}}
*/
export async function getCustomTypesDemo() {
const result = await UniFFIScaffolding.callAsyncWrapper(
135, // uniffi_uniffi_bindings_tests_fn_func_get_custom_types_demo
)
return handleRustResult(
result,
FfiConverterTypeCustomTypesDemo.lift.bind(FfiConverterTypeCustomTypesDemo),
null,
)
}
/**
* invokeAsyncTestTraitInterfaceGetValue
* @param {AsyncTestTraitInterface} int
* @returns {Promise<number>}}
*/
export async function invokeAsyncTestTraitInterfaceGetValue(
int) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeAsyncTestTraitInterface.checkType(int);
}
const result = await UniFFIScaffolding.callAsync(
136, // uniffi_uniffi_bindings_tests_fn_func_invoke_async_test_trait_interface_get_value
FfiConverterTypeAsyncTestTraitInterface.lower(int),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* invokeAsyncTestTraitInterfaceNoop
* @param {AsyncTestTraitInterface} int
*/
export async function invokeAsyncTestTraitInterfaceNoop(
int) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeAsyncTestTraitInterface.checkType(int);
}
const result = await UniFFIScaffolding.callAsync(
137, // uniffi_uniffi_bindings_tests_fn_func_invoke_async_test_trait_interface_noop
FfiConverterTypeAsyncTestTraitInterface.lower(int),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeAsyncTestTraitInterfaceSetValue
* @param {AsyncTestTraitInterface} int
* @param {number} value
*/
export async function invokeAsyncTestTraitInterfaceSetValue(
int,
value) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeAsyncTestTraitInterface.checkType(int);
}
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = await UniFFIScaffolding.callAsync(
138, // uniffi_uniffi_bindings_tests_fn_func_invoke_async_test_trait_interface_set_value
FfiConverterTypeAsyncTestTraitInterface.lower(int),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeAsyncTestTraitInterfaceThrowIfEqual
* @param {AsyncTestTraitInterface} int
* @param {CallbackInterfaceNumbers} numbers
* @returns {Promise<CallbackInterfaceNumbers>}}
*/
export async function invokeAsyncTestTraitInterfaceThrowIfEqual(
int,
numbers) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeAsyncTestTraitInterface.checkType(int);
}
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = await UniFFIScaffolding.callAsync(
139, // uniffi_uniffi_bindings_tests_fn_func_invoke_async_test_trait_interface_throw_if_equal
FfiConverterTypeAsyncTestTraitInterface.lower(int),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* invokeTestAsyncCallbackInterfaceGetValue
* @param {TestAsyncCallbackInterface} cbi
* @returns {Promise<number>}}
*/
export async function invokeTestAsyncCallbackInterfaceGetValue(
cbi) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestAsyncCallbackInterface.checkType(cbi);
}
const result = await UniFFIScaffolding.callAsync(
140, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_async_callback_interface_get_value
FfiConverterTypeTestAsyncCallbackInterface.lower(cbi),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* invokeTestAsyncCallbackInterfaceNoop
* @param {TestAsyncCallbackInterface} cbi
*/
export async function invokeTestAsyncCallbackInterfaceNoop(
cbi) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestAsyncCallbackInterface.checkType(cbi);
}
const result = await UniFFIScaffolding.callAsync(
141, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_async_callback_interface_noop
FfiConverterTypeTestAsyncCallbackInterface.lower(cbi),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestAsyncCallbackInterfaceSetValue
* @param {TestAsyncCallbackInterface} cbi
* @param {number} value
*/
export async function invokeTestAsyncCallbackInterfaceSetValue(
cbi,
value) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestAsyncCallbackInterface.checkType(cbi);
}
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = await UniFFIScaffolding.callAsync(
142, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_async_callback_interface_set_value
FfiConverterTypeTestAsyncCallbackInterface.lower(cbi),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestAsyncCallbackInterfaceThrowIfEqual
* @param {TestAsyncCallbackInterface} cbi
* @param {CallbackInterfaceNumbers} numbers
* @returns {Promise<CallbackInterfaceNumbers>}}
*/
export async function invokeTestAsyncCallbackInterfaceThrowIfEqual(
cbi,
numbers) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestAsyncCallbackInterface.checkType(cbi);
}
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = await UniFFIScaffolding.callAsync(
143, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_async_callback_interface_throw_if_equal
FfiConverterTypeTestAsyncCallbackInterface.lower(cbi),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* invokeTestCallbackInterfaceGetValue
* @param {TestCallbackInterface} cbi
* @returns {Promise<number>}}
*/
export async function invokeTestCallbackInterfaceGetValue(
cbi) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestCallbackInterface.checkType(cbi);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
144, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_callback_interface_get_value
FfiConverterTypeTestCallbackInterface.lower(cbi),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* invokeTestCallbackInterfaceNoop
* @param {TestCallbackInterface} cbi
*/
export async function invokeTestCallbackInterfaceNoop(
cbi) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestCallbackInterface.checkType(cbi);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
145, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_callback_interface_noop
FfiConverterTypeTestCallbackInterface.lower(cbi),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestCallbackInterfaceSetValue
* @param {TestCallbackInterface} cbi
* @param {number} value
*/
export async function invokeTestCallbackInterfaceSetValue(
cbi,
value) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestCallbackInterface.checkType(cbi);
}
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
146, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_callback_interface_set_value
FfiConverterTypeTestCallbackInterface.lower(cbi),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestCallbackInterfaceThrowIfEqual
* @param {TestCallbackInterface} cbi
* @param {CallbackInterfaceNumbers} numbers
* @returns {Promise<CallbackInterfaceNumbers>}}
*/
export async function invokeTestCallbackInterfaceThrowIfEqual(
cbi,
numbers) {
if (cbi instanceof UniffiSkipJsTypeCheck) {
cbi = cbi.value;
} else {
FfiConverterTypeTestCallbackInterface.checkType(cbi);
}
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
147, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_callback_interface_throw_if_equal
FfiConverterTypeTestCallbackInterface.lower(cbi),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* invokeTestTraitInterfaceGetValue
* @param {TestTraitInterface} int
* @returns {number}
*/
export function invokeTestTraitInterfaceGetValue(
int) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeTestTraitInterface.checkType(int);
}
const result = UniFFIScaffolding.callSync(
148, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_trait_interface_get_value
FfiConverterTypeTestTraitInterface.lower(int),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* invokeTestTraitInterfaceNoop
* @param {TestTraitInterface} int
*/
export function invokeTestTraitInterfaceNoop(
int) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeTestTraitInterface.checkType(int);
}
const result = UniFFIScaffolding.callSync(
149, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_trait_interface_noop
FfiConverterTypeTestTraitInterface.lower(int),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestTraitInterfaceSetValue
* @param {TestTraitInterface} int
* @param {number} value
*/
export function invokeTestTraitInterfaceSetValue(
int,
value) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeTestTraitInterface.checkType(int);
}
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = UniFFIScaffolding.callSync(
150, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_trait_interface_set_value
FfiConverterTypeTestTraitInterface.lower(int),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* invokeTestTraitInterfaceThrowIfEqual
* @param {TestTraitInterface} int
* @param {CallbackInterfaceNumbers} numbers
* @returns {CallbackInterfaceNumbers}
*/
export function invokeTestTraitInterfaceThrowIfEqual(
int,
numbers) {
if (int instanceof UniffiSkipJsTypeCheck) {
int = int.value;
} else {
FfiConverterTypeTestTraitInterface.checkType(int);
}
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = UniFFIScaffolding.callSync(
151, // uniffi_uniffi_bindings_tests_fn_func_invoke_test_trait_interface_throw_if_equal
FfiConverterTypeTestTraitInterface.lower(int),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
/**
* roundtripBool
* @param {boolean} a
* @returns {boolean}
*/
export function roundtripBool(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterBoolean.checkType(a);
}
const result = UniFFIScaffolding.callSync(
152, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_bool
FfiConverterBoolean.lower(a),
)
return handleRustResult(
result,
FfiConverterBoolean.lift.bind(FfiConverterBoolean),
null,
)
}
/**
* roundtripComplexCompound
* @param {?Array.<object>} a
* @returns {?Array.<object>}
*/
export function roundtripComplexCompound(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterOptionalSequenceMapStringUInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
153, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_complex_compound
FfiConverterOptionalSequenceMapStringUInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterOptionalSequenceMapStringUInt32.lift.bind(FfiConverterOptionalSequenceMapStringUInt32),
null,
)
}
/**
* roundtripComplexEnum
* @param {ComplexEnum} en
* @returns {ComplexEnum}
*/
export function roundtripComplexEnum(
en) {
if (en instanceof UniffiSkipJsTypeCheck) {
en = en.value;
} else {
FfiConverterTypeComplexEnum.checkType(en);
}
const result = UniFFIScaffolding.callSync(
154, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_complex_enum
FfiConverterTypeComplexEnum.lower(en),
)
return handleRustResult(
result,
FfiConverterTypeComplexEnum.lift.bind(FfiConverterTypeComplexEnum),
null,
)
}
/**
* roundtripComplexRec
* @param {ComplexRec} rec
* @returns {ComplexRec}
*/
export function roundtripComplexRec(
rec) {
if (rec instanceof UniffiSkipJsTypeCheck) {
rec = rec.value;
} else {
FfiConverterTypeComplexRec.checkType(rec);
}
const result = UniFFIScaffolding.callSync(
155, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_complex_rec
FfiConverterTypeComplexRec.lower(rec),
)
return handleRustResult(
result,
FfiConverterTypeComplexRec.lift.bind(FfiConverterTypeComplexRec),
null,
)
}
/**
* roundtripCustomType
* @param {Handle} handle
* @returns {Handle}
*/
export function roundtripCustomType(
handle) {
if (handle instanceof UniffiSkipJsTypeCheck) {
handle = handle.value;
} else {
FfiConverterTypeHandle.checkType(handle);
}
const result = UniFFIScaffolding.callSync(
156, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_custom_type
FfiConverterTypeHandle.lower(handle),
)
return handleRustResult(
result,
FfiConverterTypeHandle.lift.bind(FfiConverterTypeHandle),
null,
)
}
/**
* roundtripEnumNoData
* @param {EnumNoData} en
* @returns {EnumNoData}
*/
export function roundtripEnumNoData(
en) {
if (en instanceof UniffiSkipJsTypeCheck) {
en = en.value;
} else {
FfiConverterTypeEnumNoData.checkType(en);
}
const result = UniFFIScaffolding.callSync(
157, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_enum_no_data
FfiConverterTypeEnumNoData.lower(en),
)
return handleRustResult(
result,
FfiConverterTypeEnumNoData.lift.bind(FfiConverterTypeEnumNoData),
null,
)
}
/**
* roundtripEnumWithData
* @param {EnumWithData} en
* @returns {EnumWithData}
*/
export function roundtripEnumWithData(
en) {
if (en instanceof UniffiSkipJsTypeCheck) {
en = en.value;
} else {
FfiConverterTypeEnumWithData.checkType(en);
}
const result = UniFFIScaffolding.callSync(
158, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_enum_with_data
FfiConverterTypeEnumWithData.lower(en),
)
return handleRustResult(
result,
FfiConverterTypeEnumWithData.lift.bind(FfiConverterTypeEnumWithData),
null,
)
}
/**
* roundtripF32
* @param {number} a
* @returns {number}
*/
export function roundtripF32(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterFloat32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
159, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_f32
FfiConverterFloat32.lower(a),
)
return handleRustResult(
result,
FfiConverterFloat32.lift.bind(FfiConverterFloat32),
null,
)
}
/**
* roundtripF64
* @param {number} a
* @returns {number}
*/
export function roundtripF64(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterFloat64.checkType(a);
}
const result = UniFFIScaffolding.callSync(
160, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_f64
FfiConverterFloat64.lower(a),
)
return handleRustResult(
result,
FfiConverterFloat64.lift.bind(FfiConverterFloat64),
null,
)
}
/**
* roundtripHashMap
* @param {object} a
* @returns {object}
*/
export function roundtripHashMap(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterMapStringUInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
161, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_hash_map
FfiConverterMapStringUInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterMapStringUInt32.lift.bind(FfiConverterMapStringUInt32),
null,
)
}
/**
* roundtripI16
* @param {number} a
* @returns {number}
*/
export function roundtripI16(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterInt16.checkType(a);
}
const result = UniFFIScaffolding.callSync(
162, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_i16
FfiConverterInt16.lower(a),
)
return handleRustResult(
result,
FfiConverterInt16.lift.bind(FfiConverterInt16),
null,
)
}
/**
* roundtripI32
* @param {number} a
* @returns {number}
*/
export function roundtripI32(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
163, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_i32
FfiConverterInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterInt32.lift.bind(FfiConverterInt32),
null,
)
}
/**
* roundtripI64
* @param {number} a
* @returns {number}
*/
export function roundtripI64(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterInt64.checkType(a);
}
const result = UniFFIScaffolding.callSync(
164, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_i64
FfiConverterInt64.lower(a),
)
return handleRustResult(
result,
FfiConverterInt64.lift.bind(FfiConverterInt64),
null,
)
}
/**
* roundtripI8
* @param {number} a
* @returns {number}
*/
export function roundtripI8(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterInt8.checkType(a);
}
const result = UniFFIScaffolding.callSync(
165, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_i8
FfiConverterInt8.lower(a),
)
return handleRustResult(
result,
FfiConverterInt8.lift.bind(FfiConverterInt8),
null,
)
}
/**
* roundtripOption
* @param {?number} a
* @returns {?number}
*/
export function roundtripOption(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterOptionalUInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
166, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_option
FfiConverterOptionalUInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterOptionalUInt32.lift.bind(FfiConverterOptionalUInt32),
null,
)
}
/**
* roundtripSimpleRec
* @param {SimpleRec} rec
* @returns {Promise<SimpleRec>}}
*/
export async function roundtripSimpleRec(
rec) {
if (rec instanceof UniffiSkipJsTypeCheck) {
rec = rec.value;
} else {
FfiConverterTypeSimpleRec.checkType(rec);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
167, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_simple_rec
FfiConverterTypeSimpleRec.lower(rec),
)
return handleRustResult(
result,
FfiConverterTypeSimpleRec.lift.bind(FfiConverterTypeSimpleRec),
null,
)
}
/**
* roundtripString
* @param {string} a
* @returns {string}
*/
export function roundtripString(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterString.checkType(a);
}
const result = UniFFIScaffolding.callSync(
168, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_string
FfiConverterString.lower(a),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
/**
* roundtripTimeIntervalMs
* @param {TimeIntervalMs} time
* @returns {Promise<TimeIntervalMs>}}
*/
export async function roundtripTimeIntervalMs(
time) {
if (time instanceof UniffiSkipJsTypeCheck) {
time = time.value;
} else {
FfiConverterTypeTimeIntervalMs.checkType(time);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
169, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_time_interval_ms
FfiConverterTypeTimeIntervalMs.lower(time),
)
return handleRustResult(
result,
FfiConverterTypeTimeIntervalMs.lift.bind(FfiConverterTypeTimeIntervalMs),
null,
)
}
/**
* roundtripTimeIntervalSecDbl
* @param {TimeIntervalSecDbl} time
* @returns {Promise<TimeIntervalSecDbl>}}
*/
export async function roundtripTimeIntervalSecDbl(
time) {
if (time instanceof UniffiSkipJsTypeCheck) {
time = time.value;
} else {
FfiConverterTypeTimeIntervalSecDbl.checkType(time);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
170, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_time_interval_sec_dbl
FfiConverterTypeTimeIntervalSecDbl.lower(time),
)
return handleRustResult(
result,
FfiConverterTypeTimeIntervalSecDbl.lift.bind(FfiConverterTypeTimeIntervalSecDbl),
null,
)
}
/**
* roundtripTimeIntervalSecFlt
* @param {TimeIntervalSecFlt} time
* @returns {Promise<TimeIntervalSecFlt>}}
*/
export async function roundtripTimeIntervalSecFlt(
time) {
if (time instanceof UniffiSkipJsTypeCheck) {
time = time.value;
} else {
FfiConverterTypeTimeIntervalSecFlt.checkType(time);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
171, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_time_interval_sec_flt
FfiConverterTypeTimeIntervalSecFlt.lower(time),
)
return handleRustResult(
result,
FfiConverterTypeTimeIntervalSecFlt.lift.bind(FfiConverterTypeTimeIntervalSecFlt),
null,
)
}
/**
* roundtripU16
* @param {number} a
* @returns {number}
*/
export function roundtripU16(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterUInt16.checkType(a);
}
const result = UniFFIScaffolding.callSync(
172, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_u16
FfiConverterUInt16.lower(a),
)
return handleRustResult(
result,
FfiConverterUInt16.lift.bind(FfiConverterUInt16),
null,
)
}
/**
* roundtripU32
* @param {number} a
* @returns {number}
*/
export function roundtripU32(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterUInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
173, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_u32
FfiConverterUInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* roundtripU64
* @param {number} a
* @returns {number}
*/
export function roundtripU64(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterUInt64.checkType(a);
}
const result = UniFFIScaffolding.callSync(
174, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_u64
FfiConverterUInt64.lower(a),
)
return handleRustResult(
result,
FfiConverterUInt64.lift.bind(FfiConverterUInt64),
null,
)
}
/**
* roundtripU8
* @param {number} a
* @returns {number}
*/
export function roundtripU8(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterUInt8.checkType(a);
}
const result = UniFFIScaffolding.callSync(
175, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_u8
FfiConverterUInt8.lower(a),
)
return handleRustResult(
result,
FfiConverterUInt8.lift.bind(FfiConverterUInt8),
null,
)
}
/**
* roundtripUrl
* @param {Url} url
* @returns {Promise<Url>}}
*/
export async function roundtripUrl(
url) {
if (url instanceof UniffiSkipJsTypeCheck) {
url = url.value;
} else {
FfiConverterTypeUrl.checkType(url);
}
const result = await UniFFIScaffolding.callAsyncWrapper(
176, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_url
FfiConverterTypeUrl.lower(url),
)
return handleRustResult(
result,
FfiConverterTypeUrl.lift.bind(FfiConverterTypeUrl),
null,
)
}
/**
* roundtripVec
* @param {Array.<number>} a
* @returns {Array.<number>}
*/
export function roundtripVec(
a) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterSequenceUInt32.checkType(a);
}
const result = UniFFIScaffolding.callSync(
177, // uniffi_uniffi_bindings_tests_fn_func_roundtrip_vec
FfiConverterSequenceUInt32.lower(a),
)
return handleRustResult(
result,
FfiConverterSequenceUInt32.lift.bind(FfiConverterSequenceUInt32),
null,
)
}
/**
* Complex test: input a bunch of different values and add them together
* @param {number} a
* @param {number} b
* @param {number} c
* @param {number} d
* @param {number} e
* @param {number} f
* @param {number} g
* @param {number} h
* @param {number} i
* @param {number} j
* @param {boolean} negate
* @returns {number}
*/
export function sumWithManyTypes(
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
negate) {
if (a instanceof UniffiSkipJsTypeCheck) {
a = a.value;
} else {
FfiConverterUInt8.checkType(a);
}
if (b instanceof UniffiSkipJsTypeCheck) {
b = b.value;
} else {
FfiConverterInt8.checkType(b);
}
if (c instanceof UniffiSkipJsTypeCheck) {
c = c.value;
} else {
FfiConverterUInt16.checkType(c);
}
if (d instanceof UniffiSkipJsTypeCheck) {
d = d.value;
} else {
FfiConverterInt16.checkType(d);
}
if (e instanceof UniffiSkipJsTypeCheck) {
e = e.value;
} else {
FfiConverterUInt32.checkType(e);
}
if (f instanceof UniffiSkipJsTypeCheck) {
f = f.value;
} else {
FfiConverterInt32.checkType(f);
}
if (g instanceof UniffiSkipJsTypeCheck) {
g = g.value;
} else {
FfiConverterUInt64.checkType(g);
}
if (h instanceof UniffiSkipJsTypeCheck) {
h = h.value;
} else {
FfiConverterInt64.checkType(h);
}
if (i instanceof UniffiSkipJsTypeCheck) {
i = i.value;
} else {
FfiConverterFloat32.checkType(i);
}
if (j instanceof UniffiSkipJsTypeCheck) {
j = j.value;
} else {
FfiConverterFloat64.checkType(j);
}
if (negate instanceof UniffiSkipJsTypeCheck) {
negate = negate.value;
} else {
FfiConverterBoolean.checkType(negate);
}
const result = UniFFIScaffolding.callSync(
178, // uniffi_uniffi_bindings_tests_fn_func_sum_with_many_types
FfiConverterUInt8.lower(a),
FfiConverterInt8.lower(b),
FfiConverterUInt16.lower(c),
FfiConverterInt16.lower(d),
FfiConverterUInt32.lower(e),
FfiConverterInt32.lower(f),
FfiConverterUInt64.lower(g),
FfiConverterInt64.lower(h),
FfiConverterFloat32.lower(i),
FfiConverterFloat64.lower(j),
FfiConverterBoolean.lower(negate),
)
return handleRustResult(
result,
FfiConverterFloat64.lift.bind(FfiConverterFloat64),
null,
)
}
/**
* swapTestInterfaces
* @param {TwoTestInterfaces} interfaces
* @returns {TwoTestInterfaces}
*/
export function swapTestInterfaces(
interfaces) {
if (interfaces instanceof UniffiSkipJsTypeCheck) {
interfaces = interfaces.value;
} else {
FfiConverterTypeTwoTestInterfaces.checkType(interfaces);
}
const result = UniFFIScaffolding.callSync(
179, // uniffi_uniffi_bindings_tests_fn_func_swap_test_interfaces
FfiConverterTypeTwoTestInterfaces.lower(interfaces),
)
return handleRustResult(
result,
FfiConverterTypeTwoTestInterfaces.lift.bind(FfiConverterTypeTwoTestInterfaces),
null,
)
}
/**
* testFunc
*/
export function testFunc() {
const result = UniFFIScaffolding.callSync(
180, // uniffi_uniffi_bindings_tests_fn_func_test_func
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt32 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < 0 || value > 4294967295) {
throw new UniFFITypeError(`${value} exceeds the U32 bounds`);
}
}
static computeSize(_value) {
return 4;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint32(value)
}
static read(dataStream) {
return dataStream.readUint32()
}
}
/**
* CallbackInterfaceNumbers
*/
export class CallbackInterfaceNumbers {
constructor(
{
a,
b
} = {
a: undefined,
b: undefined
}
) {
try {
FfiConverterUInt32.checkType(a)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("a");
}
throw e;
}
try {
FfiConverterUInt32.checkType(b)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("b");
}
throw e;
}
/**
* a
*/
this.a = a;
/**
* b
*/
this.b = b;
}
equals(other) {
return (
this.a == other.a
&& this.b == other.b
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeCallbackInterfaceNumbers extends FfiConverterArrayBuffer {
static read(dataStream) {
return new CallbackInterfaceNumbers({
a: FfiConverterUInt32.read(dataStream),
b: FfiConverterUInt32.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterUInt32.write(dataStream, value.a);
FfiConverterUInt32.write(dataStream, value.b);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterUInt32.computeSize(value.a);
totalSize += FfiConverterUInt32.computeSize(value.b);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof CallbackInterfaceNumbers)) {
throw new UniFFITypeError(`Expected 'CallbackInterfaceNumbers', found '${typeof value}'`);
}
try {
FfiConverterUInt32.checkType(value.a);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".a");
}
throw e;
}
try {
FfiConverterUInt32.checkType(value.b);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".b");
}
throw e;
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt8 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < 0 || value > 256) {
throw new UniFFITypeError(`${value} exceeds the U8 bounds`);
}
}
static computeSize(_value) {
return 1;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint8(value)
}
static read(dataStream) {
return dataStream.readUint8()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt8 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < -128 || value > 127) {
throw new UniFFITypeError(`${value} exceeds the I8 bounds`);
}
}
static computeSize(_value) {
return 1;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt8(value)
}
static read(dataStream) {
return dataStream.readInt8()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt16 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < 0 || value > 65535) {
throw new UniFFITypeError(`${value} exceeds the U16 bounds`);
}
}
static computeSize(_value) {
return 2;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint16(value)
}
static read(dataStream) {
return dataStream.readUint16()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt16 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < -32768 || value > 32767) {
throw new UniFFITypeError(`${value} exceeds the I16 bounds`);
}
}
static computeSize(_value) {
return 2;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt16(value)
}
static read(dataStream) {
return dataStream.readInt16()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt32 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isInteger(value)) {
throw new UniFFITypeError(`${value} is not an integer`);
}
if (value < -2147483648 || value > 2147483647) {
throw new UniFFITypeError(`${value} exceeds the I32 bounds`);
}
}
static computeSize(_value) {
return 4;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt32(value)
}
static read(dataStream) {
return dataStream.readInt32()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterUInt64 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isSafeInteger(value)) {
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
}
if (value < 0) {
throw new UniFFITypeError(`${value} exceeds the U64 bounds`);
}
}
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeUint64(value)
}
static read(dataStream) {
return dataStream.readUint64()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterInt64 extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (!Number.isSafeInteger(value)) {
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
}
}
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeInt64(value)
}
static read(dataStream) {
return dataStream.readInt64()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterFloat32 extends FfiConverter {
static computeSize(_value) {
return 4;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeFloat32(value)
}
static read(dataStream) {
return dataStream.readFloat32()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterFloat64 extends FfiConverter {
static computeSize(_value) {
return 8;
}
static lift(value) {
return value;
}
static lower(value) {
return value;
}
static write(dataStream, value) {
dataStream.writeFloat64(value)
}
static read(dataStream) {
return dataStream.readFloat64()
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterString extends FfiConverter {
static checkType(value) {
super.checkType(value);
if (typeof value !== "string") {
throw new UniFFITypeError(`${value} is not a string`);
}
}
static lift(buf) {
const utf8Arr = new Uint8Array(buf);
return lazy.decoder.decode(utf8Arr);
}
static lower(value) {
return lazy.encoder.encode(value).buffer;
}
static write(dataStream, value) {
dataStream.writeString(value);
}
static read(dataStream) {
return dataStream.readString();
}
static computeSize(value) {
return 4 + lazy.encoder.encode(value).length
}
}
/**
* SimpleRec
*/
export class SimpleRec {
constructor(
{
a
} = {
a: undefined
}
) {
try {
FfiConverterUInt8.checkType(a)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("a");
}
throw e;
}
/**
* a
*/
this.a = a;
}
equals(other) {
return (
this.a == other.a
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSimpleRec extends FfiConverterArrayBuffer {
static read(dataStream) {
return new SimpleRec({
a: FfiConverterUInt8.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterUInt8.write(dataStream, value.a);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterUInt8.computeSize(value.a);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof SimpleRec)) {
throw new UniFFITypeError(`Expected 'SimpleRec', found '${typeof value}'`);
}
try {
FfiConverterUInt8.checkType(value.a);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".a");
}
throw e;
}
}
}
/**
* ComplexRec
*/
export class ComplexRec {
constructor(
{
fieldU8,
fieldI8,
fieldU16,
fieldI16,
fieldU32,
fieldI32,
fieldU64,
fieldI64,
fieldF32,
fieldF64,
fieldString= "DefaultString",
fieldRec
} = {
fieldU8: undefined,
fieldI8: undefined,
fieldU16: undefined,
fieldI16: undefined,
fieldU32: undefined,
fieldI32: undefined,
fieldU64: undefined,
fieldI64: undefined,
fieldF32: undefined,
fieldF64: undefined,
fieldString: undefined,
fieldRec: undefined
}
) {
try {
FfiConverterUInt8.checkType(fieldU8)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldU8");
}
throw e;
}
try {
FfiConverterInt8.checkType(fieldI8)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldI8");
}
throw e;
}
try {
FfiConverterUInt16.checkType(fieldU16)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldU16");
}
throw e;
}
try {
FfiConverterInt16.checkType(fieldI16)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldI16");
}
throw e;
}
try {
FfiConverterUInt32.checkType(fieldU32)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldU32");
}
throw e;
}
try {
FfiConverterInt32.checkType(fieldI32)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldI32");
}
throw e;
}
try {
FfiConverterUInt64.checkType(fieldU64)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldU64");
}
throw e;
}
try {
FfiConverterInt64.checkType(fieldI64)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldI64");
}
throw e;
}
try {
FfiConverterFloat32.checkType(fieldF32)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldF32");
}
throw e;
}
try {
FfiConverterFloat64.checkType(fieldF64)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldF64");
}
throw e;
}
try {
FfiConverterString.checkType(fieldString)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldString");
}
throw e;
}
try {
FfiConverterTypeSimpleRec.checkType(fieldRec)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("fieldRec");
}
throw e;
}
/**
* fieldU8
*/
this.fieldU8 = fieldU8;
/**
* fieldI8
*/
this.fieldI8 = fieldI8;
/**
* fieldU16
*/
this.fieldU16 = fieldU16;
/**
* fieldI16
*/
this.fieldI16 = fieldI16;
/**
* fieldU32
*/
this.fieldU32 = fieldU32;
/**
* fieldI32
*/
this.fieldI32 = fieldI32;
/**
* fieldU64
*/
this.fieldU64 = fieldU64;
/**
* fieldI64
*/
this.fieldI64 = fieldI64;
/**
* fieldF32
*/
this.fieldF32 = fieldF32;
/**
* fieldF64
*/
this.fieldF64 = fieldF64;
/**
* fieldString
*/
this.fieldString = fieldString;
/**
* fieldRec
*/
this.fieldRec = fieldRec;
}
equals(other) {
return (
this.fieldU8 == other.fieldU8
&& this.fieldI8 == other.fieldI8
&& this.fieldU16 == other.fieldU16
&& this.fieldI16 == other.fieldI16
&& this.fieldU32 == other.fieldU32
&& this.fieldI32 == other.fieldI32
&& this.fieldU64 == other.fieldU64
&& this.fieldI64 == other.fieldI64
&& this.fieldF32 == other.fieldF32
&& this.fieldF64 == other.fieldF64
&& this.fieldString == other.fieldString
&& this.fieldRec.equals(other.fieldRec)
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeComplexRec extends FfiConverterArrayBuffer {
static read(dataStream) {
return new ComplexRec({
fieldU8: FfiConverterUInt8.read(dataStream),
fieldI8: FfiConverterInt8.read(dataStream),
fieldU16: FfiConverterUInt16.read(dataStream),
fieldI16: FfiConverterInt16.read(dataStream),
fieldU32: FfiConverterUInt32.read(dataStream),
fieldI32: FfiConverterInt32.read(dataStream),
fieldU64: FfiConverterUInt64.read(dataStream),
fieldI64: FfiConverterInt64.read(dataStream),
fieldF32: FfiConverterFloat32.read(dataStream),
fieldF64: FfiConverterFloat64.read(dataStream),
fieldString: FfiConverterString.read(dataStream),
fieldRec: FfiConverterTypeSimpleRec.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterUInt8.write(dataStream, value.fieldU8);
FfiConverterInt8.write(dataStream, value.fieldI8);
FfiConverterUInt16.write(dataStream, value.fieldU16);
FfiConverterInt16.write(dataStream, value.fieldI16);
FfiConverterUInt32.write(dataStream, value.fieldU32);
FfiConverterInt32.write(dataStream, value.fieldI32);
FfiConverterUInt64.write(dataStream, value.fieldU64);
FfiConverterInt64.write(dataStream, value.fieldI64);
FfiConverterFloat32.write(dataStream, value.fieldF32);
FfiConverterFloat64.write(dataStream, value.fieldF64);
FfiConverterString.write(dataStream, value.fieldString);
FfiConverterTypeSimpleRec.write(dataStream, value.fieldRec);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterUInt8.computeSize(value.fieldU8);
totalSize += FfiConverterInt8.computeSize(value.fieldI8);
totalSize += FfiConverterUInt16.computeSize(value.fieldU16);
totalSize += FfiConverterInt16.computeSize(value.fieldI16);
totalSize += FfiConverterUInt32.computeSize(value.fieldU32);
totalSize += FfiConverterInt32.computeSize(value.fieldI32);
totalSize += FfiConverterUInt64.computeSize(value.fieldU64);
totalSize += FfiConverterInt64.computeSize(value.fieldI64);
totalSize += FfiConverterFloat32.computeSize(value.fieldF32);
totalSize += FfiConverterFloat64.computeSize(value.fieldF64);
totalSize += FfiConverterString.computeSize(value.fieldString);
totalSize += FfiConverterTypeSimpleRec.computeSize(value.fieldRec);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof ComplexRec)) {
throw new UniFFITypeError(`Expected 'ComplexRec', found '${typeof value}'`);
}
try {
FfiConverterUInt8.checkType(value.fieldU8);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldU8");
}
throw e;
}
try {
FfiConverterInt8.checkType(value.fieldI8);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldI8");
}
throw e;
}
try {
FfiConverterUInt16.checkType(value.fieldU16);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldU16");
}
throw e;
}
try {
FfiConverterInt16.checkType(value.fieldI16);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldI16");
}
throw e;
}
try {
FfiConverterUInt32.checkType(value.fieldU32);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldU32");
}
throw e;
}
try {
FfiConverterInt32.checkType(value.fieldI32);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldI32");
}
throw e;
}
try {
FfiConverterUInt64.checkType(value.fieldU64);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldU64");
}
throw e;
}
try {
FfiConverterInt64.checkType(value.fieldI64);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldI64");
}
throw e;
}
try {
FfiConverterFloat32.checkType(value.fieldF32);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldF32");
}
throw e;
}
try {
FfiConverterFloat64.checkType(value.fieldF64);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldF64");
}
throw e;
}
try {
FfiConverterString.checkType(value.fieldString);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldString");
}
throw e;
}
try {
FfiConverterTypeSimpleRec.checkType(value.fieldRec);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".fieldRec");
}
throw e;
}
}
}
export class FfiConverterTypeUrl extends FfiConverter {
static lift(value) {
const builtinVal = FfiConverterString.lift(value);
return new URL(builtinVal);
}
static lower(value) {
const builtinVal = value.toString();
return FfiConverterString.lower(builtinVal);
}
static write(dataStream, value) {
const builtinVal = value.toString();
FfiConverterString.write(dataStream, builtinVal);
}
static read(dataStream) {
const builtinVal = FfiConverterString.read(dataStream);
return new URL(builtinVal);
}
static computeSize(value) {
const builtinVal = value.toString();
return FfiConverterString.computeSize(builtinVal);
}
static checkType(value) {
if (value === null || value === undefined) {
throw new TypeError("value is null or undefined");
}
if (value?.constructor?.name !== "URL") {
throw new TypeError(`${value} is not a URL`);
}
}
}
export class FfiConverterTypeHandle extends FfiConverter {
static lift(value) {
return FfiConverterUInt64.lift(value);
}
static lower(value) {
return FfiConverterUInt64.lower(value);
}
static write(dataStream, value) {
FfiConverterUInt64.write(dataStream, value);
}
static read(dataStream) {
const builtinVal = FfiConverterUInt64.read(dataStream);
return builtinVal;
}
static computeSize(value) {
return FfiConverterUInt64.computeSize(value);
}
static checkType(value) {
if (value === null || value === undefined) {
throw new TypeError("value is null or undefined");
}
}
}
export class FfiConverterTypeTimeIntervalMs extends FfiConverter {
static lift(value) {
const builtinVal = FfiConverterInt64.lift(value);
return new Date(builtinVal);
}
static lower(value) {
const builtinVal = value.getTime();
return FfiConverterInt64.lower(builtinVal);
}
static write(dataStream, value) {
const builtinVal = value.getTime();
FfiConverterInt64.write(dataStream, builtinVal);
}
static read(dataStream) {
const builtinVal = FfiConverterInt64.read(dataStream);
return new Date(builtinVal);
}
static computeSize(value) {
const builtinVal = value.getTime();
return FfiConverterInt64.computeSize(builtinVal);
}
static checkType(value) {
if (value === null || value === undefined) {
throw new TypeError("value is null or undefined");
}
if (value?.constructor?.name !== "Date") {
throw new TypeError(`${value} is not a Date`);
}
}
}
export class FfiConverterTypeTimeIntervalSecDbl extends FfiConverter {
static lift(value) {
const builtinVal = FfiConverterFloat64.lift(value);
return new Date(builtinVal * 1000);
}
static lower(value) {
const builtinVal = value.getTime() / 1000;
return FfiConverterFloat64.lower(builtinVal);
}
static write(dataStream, value) {
const builtinVal = value.getTime() / 1000;
FfiConverterFloat64.write(dataStream, builtinVal);
}
static read(dataStream) {
const builtinVal = FfiConverterFloat64.read(dataStream);
return new Date(builtinVal * 1000);
}
static computeSize(value) {
const builtinVal = value.getTime() / 1000;
return FfiConverterFloat64.computeSize(builtinVal);
}
static checkType(value) {
if (value === null || value === undefined) {
throw new TypeError("value is null or undefined");
}
if (value?.constructor?.name !== "Date") {
throw new TypeError(`${value} is not a Date`);
}
}
}
export class FfiConverterTypeTimeIntervalSecFlt extends FfiConverter {
static lift(value) {
return FfiConverterFloat32.lift(value);
}
static lower(value) {
return FfiConverterFloat32.lower(value);
}
static write(dataStream, value) {
FfiConverterFloat32.write(dataStream, value);
}
static read(dataStream) {
const builtinVal = FfiConverterFloat32.read(dataStream);
return builtinVal;
}
static computeSize(value) {
return FfiConverterFloat32.computeSize(value);
}
static checkType(value) {
if (value === null || value === undefined) {
throw new TypeError("value is null or undefined");
}
}
}
/**
* CustomTypesDemo
*/
export class CustomTypesDemo {
constructor(
{
url,
handle,
timeIntervalMs,
timeIntervalSecDbl,
timeIntervalSecFlt
} = {
url: undefined,
handle: undefined,
timeIntervalMs: undefined,
timeIntervalSecDbl: undefined,
timeIntervalSecFlt: undefined
}
) {
try {
FfiConverterTypeUrl.checkType(url)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("url");
}
throw e;
}
try {
FfiConverterTypeHandle.checkType(handle)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("handle");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalMs.checkType(timeIntervalMs)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("timeIntervalMs");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalSecDbl.checkType(timeIntervalSecDbl)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("timeIntervalSecDbl");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalSecFlt.checkType(timeIntervalSecFlt)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("timeIntervalSecFlt");
}
throw e;
}
/**
* url
*/
this.url = url;
/**
* handle
*/
this.handle = handle;
/**
* timeIntervalMs
*/
this.timeIntervalMs = timeIntervalMs;
/**
* timeIntervalSecDbl
*/
this.timeIntervalSecDbl = timeIntervalSecDbl;
/**
* timeIntervalSecFlt
*/
this.timeIntervalSecFlt = timeIntervalSecFlt;
}
equals(other) {
return (
this.url == other.url
&& this.handle == other.handle
&& this.timeIntervalMs == other.timeIntervalMs
&& this.timeIntervalSecDbl == other.timeIntervalSecDbl
&& this.timeIntervalSecFlt == other.timeIntervalSecFlt
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeCustomTypesDemo extends FfiConverterArrayBuffer {
static read(dataStream) {
return new CustomTypesDemo({
url: FfiConverterTypeUrl.read(dataStream),
handle: FfiConverterTypeHandle.read(dataStream),
timeIntervalMs: FfiConverterTypeTimeIntervalMs.read(dataStream),
timeIntervalSecDbl: FfiConverterTypeTimeIntervalSecDbl.read(dataStream),
timeIntervalSecFlt: FfiConverterTypeTimeIntervalSecFlt.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterTypeUrl.write(dataStream, value.url);
FfiConverterTypeHandle.write(dataStream, value.handle);
FfiConverterTypeTimeIntervalMs.write(dataStream, value.timeIntervalMs);
FfiConverterTypeTimeIntervalSecDbl.write(dataStream, value.timeIntervalSecDbl);
FfiConverterTypeTimeIntervalSecFlt.write(dataStream, value.timeIntervalSecFlt);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterTypeUrl.computeSize(value.url);
totalSize += FfiConverterTypeHandle.computeSize(value.handle);
totalSize += FfiConverterTypeTimeIntervalMs.computeSize(value.timeIntervalMs);
totalSize += FfiConverterTypeTimeIntervalSecDbl.computeSize(value.timeIntervalSecDbl);
totalSize += FfiConverterTypeTimeIntervalSecFlt.computeSize(value.timeIntervalSecFlt);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof CustomTypesDemo)) {
throw new UniFFITypeError(`Expected 'CustomTypesDemo', found '${typeof value}'`);
}
try {
FfiConverterTypeUrl.checkType(value.url);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".url");
}
throw e;
}
try {
FfiConverterTypeHandle.checkType(value.handle);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".handle");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalMs.checkType(value.timeIntervalMs);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".timeIntervalMs");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalSecDbl.checkType(value.timeIntervalSecDbl);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".timeIntervalSecDbl");
}
throw e;
}
try {
FfiConverterTypeTimeIntervalSecFlt.checkType(value.timeIntervalSecFlt);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".timeIntervalSecFlt");
}
throw e;
}
}
}
/**
* RecWithDefault
*/
export class RecWithDefault {
constructor(
{
a= 42
} = {
a: undefined
}
) {
try {
FfiConverterUInt8.checkType(a)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("a");
}
throw e;
}
/**
* a
*/
this.a = a;
}
equals(other) {
return (
this.a == other.a
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRecWithDefault extends FfiConverterArrayBuffer {
static read(dataStream) {
return new RecWithDefault({
a: FfiConverterUInt8.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterUInt8.write(dataStream, value.a);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterUInt8.computeSize(value.a);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof RecWithDefault)) {
throw new UniFFITypeError(`Expected 'RecWithDefault', found '${typeof value}'`);
}
try {
FfiConverterUInt8.checkType(value.a);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".a");
}
throw e;
}
}
}
/**
* TestInterface
*/
export class TestInterface {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
/**
* init
* @param {number} value
* @returns {TestInterface}
*/
static init(
value) {
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = UniFFIScaffolding.callSync(
181, // uniffi_uniffi_bindings_tests_fn_constructor_testinterface_new
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
FfiConverterTypeTestInterface.lift.bind(FfiConverterTypeTestInterface),
null,
)
}
/**
* getValue
* @returns {number}
*/
getValue() {
const result = UniFFIScaffolding.callSync(
182, // uniffi_uniffi_bindings_tests_fn_method_testinterface_get_value
FfiConverterTypeTestInterface.lowerReceiver(this),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* Get the current reference count for this object
*
* The count does not include the extra reference needed to call this method.
* @returns {number}
*/
refCount() {
const result = UniFFIScaffolding.callSync(
183, // uniffi_uniffi_bindings_tests_fn_method_testinterface_ref_count
FfiConverterTypeTestInterface.lowerReceiver(this),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestInterface extends FfiConverter {
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new TestInterface(opts);
}
static lower(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'TestInterface' instance");
}
return ptr;
}
static lowerReceiver(value) {
// This works exactly the same as lower for non-trait interfaces
return this.lower(value);
}
static read(dataStream) {
return this.lift(dataStream.readPointer(15));
}
static write(dataStream, value) {
dataStream.writePointer(15, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
/**
* TwoTestInterfaces
*/
export class TwoTestInterfaces {
constructor(
{
first,
second
} = {
first: undefined,
second: undefined
}
) {
try {
FfiConverterTypeTestInterface.checkType(first)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("first");
}
throw e;
}
try {
FfiConverterTypeTestInterface.checkType(second)
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("second");
}
throw e;
}
/**
* first
*/
this.first = first;
/**
* second
*/
this.second = second;
}
equals(other) {
return (
this.first == other.first
&& this.second == other.second
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTwoTestInterfaces extends FfiConverterArrayBuffer {
static read(dataStream) {
return new TwoTestInterfaces({
first: FfiConverterTypeTestInterface.read(dataStream),
second: FfiConverterTypeTestInterface.read(dataStream),
});
}
static write(dataStream, value) {
FfiConverterTypeTestInterface.write(dataStream, value.first);
FfiConverterTypeTestInterface.write(dataStream, value.second);
}
static computeSize(value) {
let totalSize = 0;
totalSize += FfiConverterTypeTestInterface.computeSize(value.first);
totalSize += FfiConverterTypeTestInterface.computeSize(value.second);
return totalSize
}
static checkType(value) {
super.checkType(value);
if (!(value instanceof TwoTestInterfaces)) {
throw new UniFFITypeError(`Expected 'TwoTestInterfaces', found '${typeof value}'`);
}
try {
FfiConverterTypeTestInterface.checkType(value.first);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".first");
}
throw e;
}
try {
FfiConverterTypeTestInterface.checkType(value.second);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(".second");
}
throw e;
}
}
}
/**
* EnumNoData
*/
export const EnumNoData = {
/**
* A
*/
A: 0,
/**
* B
*/
B: 1,
/**
* C
*/
C: 2,
};
Object.freeze(EnumNoData);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeEnumNoData extends FfiConverterArrayBuffer {
static #validValues = Object.values(EnumNoData)
static read(dataStream) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
switch (dataStream.readInt32()) {
case 1:
return EnumNoData.A
case 2:
return EnumNoData.B
case 3:
return EnumNoData.C
default:
throw new UniFFITypeError("Unknown EnumNoData variant");
}
}
static write(dataStream, value) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
if (value === EnumNoData.A) {
dataStream.writeInt32(1);
return;
}
if (value === EnumNoData.B) {
dataStream.writeInt32(2);
return;
}
if (value === EnumNoData.C) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown EnumNoData variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
// Check that the value is a valid enum variant
if (!this.#validValues.includes(value)) {
throw new UniFFITypeError(`${value} is not a valid value for EnumNoData`);
}
}
}
/**
* EnumWithData
*/
export class EnumWithData {}
/**
* A
*/
EnumWithData.A = class extends EnumWithData{
constructor({value = undefined } = {}) {
super();
try {
FfiConverterUInt8.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
this.value = value;
}
}
/**
* B
*/
EnumWithData.B = class extends EnumWithData{
constructor({value = undefined } = {}) {
super();
try {
FfiConverterString.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
this.value = value;
}
}
/**
* C
*/
EnumWithData.C = class extends EnumWithData{
constructor() {
super();
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeEnumWithData extends FfiConverterArrayBuffer {
static read(dataStream) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
switch (dataStream.readInt32()) {
case 1:
return new EnumWithData.A({
value: FfiConverterUInt8.read(dataStream)
});
case 2:
return new EnumWithData.B({
value: FfiConverterString.read(dataStream)
});
case 3:
return new EnumWithData.C();
default:
throw new UniFFITypeError("Unknown EnumWithData variant");
}
}
static write(dataStream, value) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
if (value instanceof EnumWithData.A) {
dataStream.writeInt32(1);
FfiConverterUInt8.write(dataStream, value.value);
return;
}
if (value instanceof EnumWithData.B) {
dataStream.writeInt32(2);
FfiConverterString.write(dataStream, value.value);
return;
}
if (value instanceof EnumWithData.C) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown EnumWithData variant");
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof EnumWithData.A) {
totalSize += FfiConverterUInt8.computeSize(value.value);
return totalSize;
}
if (value instanceof EnumWithData.B) {
totalSize += FfiConverterString.computeSize(value.value);
return totalSize;
}
if (value instanceof EnumWithData.C) {
return totalSize;
}
throw new UniFFITypeError("Unknown EnumWithData variant");
}
static checkType(value) {
if (!(value instanceof EnumWithData)) {
throw new UniFFITypeError(`${value} is not a subclass instance of EnumWithData`);
}
}
}
/**
* ComplexEnum
*/
export class ComplexEnum {}
/**
* A
*/
ComplexEnum.A = class extends ComplexEnum{
constructor({value = undefined } = {}) {
super();
try {
FfiConverterTypeEnumNoData.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
this.value = value;
}
}
/**
* B
*/
ComplexEnum.B = class extends ComplexEnum{
constructor({value = undefined } = {}) {
super();
try {
FfiConverterTypeEnumWithData.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
this.value = value;
}
}
/**
* C
*/
ComplexEnum.C = class extends ComplexEnum{
constructor({value = undefined } = {}) {
super();
try {
FfiConverterTypeSimpleRec.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("value");
}
throw e;
}
this.value = value;
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeComplexEnum extends FfiConverterArrayBuffer {
static read(dataStream) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
switch (dataStream.readInt32()) {
case 1:
return new ComplexEnum.A({
value: FfiConverterTypeEnumNoData.read(dataStream)
});
case 2:
return new ComplexEnum.B({
value: FfiConverterTypeEnumWithData.read(dataStream)
});
case 3:
return new ComplexEnum.C({
value: FfiConverterTypeSimpleRec.read(dataStream)
});
default:
throw new UniFFITypeError("Unknown ComplexEnum variant");
}
}
static write(dataStream, value) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
if (value instanceof ComplexEnum.A) {
dataStream.writeInt32(1);
FfiConverterTypeEnumNoData.write(dataStream, value.value);
return;
}
if (value instanceof ComplexEnum.B) {
dataStream.writeInt32(2);
FfiConverterTypeEnumWithData.write(dataStream, value.value);
return;
}
if (value instanceof ComplexEnum.C) {
dataStream.writeInt32(3);
FfiConverterTypeSimpleRec.write(dataStream, value.value);
return;
}
throw new UniFFITypeError("Unknown ComplexEnum variant");
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof ComplexEnum.A) {
totalSize += FfiConverterTypeEnumNoData.computeSize(value.value);
return totalSize;
}
if (value instanceof ComplexEnum.B) {
totalSize += FfiConverterTypeEnumWithData.computeSize(value.value);
return totalSize;
}
if (value instanceof ComplexEnum.C) {
totalSize += FfiConverterTypeSimpleRec.computeSize(value.value);
return totalSize;
}
throw new UniFFITypeError("Unknown ComplexEnum variant");
}
static checkType(value) {
if (!(value instanceof ComplexEnum)) {
throw new UniFFITypeError(`${value} is not a subclass instance of ComplexEnum`);
}
}
}
/**
* ExplicitValuedEnum
*/
export const ExplicitValuedEnum = {
/**
* FIRST
*/
FIRST: 1,
/**
* SECOND
*/
SECOND: 2,
/**
* FOURTH
*/
FOURTH: 4,
/**
* TENTH
*/
TENTH: 10,
/**
* ELEVENTH
*/
ELEVENTH: 11,
/**
* THIRTEENTH
*/
THIRTEENTH: 13,
};
Object.freeze(ExplicitValuedEnum);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeExplicitValuedEnum extends FfiConverterArrayBuffer {
static #validValues = Object.values(ExplicitValuedEnum)
static read(dataStream) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
switch (dataStream.readInt32()) {
case 1:
return ExplicitValuedEnum.FIRST
case 2:
return ExplicitValuedEnum.SECOND
case 3:
return ExplicitValuedEnum.FOURTH
case 4:
return ExplicitValuedEnum.TENTH
case 5:
return ExplicitValuedEnum.ELEVENTH
case 6:
return ExplicitValuedEnum.THIRTEENTH
default:
throw new UniFFITypeError("Unknown ExplicitValuedEnum variant");
}
}
static write(dataStream, value) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
if (value === ExplicitValuedEnum.FIRST) {
dataStream.writeInt32(1);
return;
}
if (value === ExplicitValuedEnum.SECOND) {
dataStream.writeInt32(2);
return;
}
if (value === ExplicitValuedEnum.FOURTH) {
dataStream.writeInt32(3);
return;
}
if (value === ExplicitValuedEnum.TENTH) {
dataStream.writeInt32(4);
return;
}
if (value === ExplicitValuedEnum.ELEVENTH) {
dataStream.writeInt32(5);
return;
}
if (value === ExplicitValuedEnum.THIRTEENTH) {
dataStream.writeInt32(6);
return;
}
throw new UniFFITypeError("Unknown ExplicitValuedEnum variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
// Check that the value is a valid enum variant
if (!this.#validValues.includes(value)) {
throw new UniFFITypeError(`${value} is not a valid value for ExplicitValuedEnum`);
}
}
}
/**
* GappedEnum
*/
export const GappedEnum = {
/**
* ONE
*/
ONE: 10,
/**
* TWO
*/
TWO: 11,
/**
* THREE
*/
THREE: 14,
};
Object.freeze(GappedEnum);
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeGappedEnum extends FfiConverterArrayBuffer {
static #validValues = Object.values(GappedEnum)
static read(dataStream) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
switch (dataStream.readInt32()) {
case 1:
return GappedEnum.ONE
case 2:
return GappedEnum.TWO
case 3:
return GappedEnum.THREE
default:
throw new UniFFITypeError("Unknown GappedEnum variant");
}
}
static write(dataStream, value) {
// Use sequential indices (1-based) for the wire format to match the Rust scaffolding
if (value === GappedEnum.ONE) {
dataStream.writeInt32(1);
return;
}
if (value === GappedEnum.TWO) {
dataStream.writeInt32(2);
return;
}
if (value === GappedEnum.THREE) {
dataStream.writeInt32(3);
return;
}
throw new UniFFITypeError("Unknown GappedEnum variant");
}
static computeSize(value) {
return 4;
}
static checkType(value) {
// Check that the value is a valid enum variant
if (!this.#validValues.includes(value)) {
throw new UniFFITypeError(`${value} is not a valid value for GappedEnum`);
}
}
}
/**
* Error enum
*/
export class TestError extends Error {}
/**
* Failure1
*/
export class Failure1 extends TestError {
constructor(
...params
) {
super(...params);
}
toString() {
return `Failure1: ${super.toString()}`
}
}
/**
* Failure2
*/
export class Failure2 extends TestError {
constructor(
data,
...params
) {
const message = `data: ${ data }`;
super(message, ...params);
this.data = data;
}
toString() {
return `Failure2: ${super.toString()}`
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestError extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return new Failure1(
);
case 2:
return new Failure2(
FfiConverterString.read(dataStream)
);
default:
throw new UniFFITypeError("Unknown TestError variant");
}
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof Failure1) {
return totalSize;
}
if (value instanceof Failure2) {
totalSize += FfiConverterString.computeSize(value.data);
return totalSize;
}
throw new UniFFITypeError("Unknown TestError variant");
}
static write(dataStream, value) {
if (value instanceof Failure1) {
dataStream.writeInt32(1);
return;
}
if (value instanceof Failure2) {
dataStream.writeInt32(2);
FfiConverterString.write(dataStream, value.data);
return;
}
throw new UniFFITypeError("Unknown TestError variant");
}
static errorClass = TestError;
}
/**
* Flat error enum
*
* The associated data for this won't be across the FFI. Flat errors are mostly just a historical
* artifact, but there are some use-cases for them -- for example variants that wrap errors from
* other crates.
*/
export class TestFlatError extends Error {}
/**
* Here's an example of a variant that only works with a flat error, `io::Error` is not
* UniFFI compatible and can't be passed across the FFI.
*/
export class IoError extends TestFlatError {
constructor(message, ...params) {
super(...params);
this.message = message;
}
toString() {
return `IoError: ${super.toString()}`
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestFlatError extends FfiConverterArrayBuffer {
static read(dataStream) {
switch (dataStream.readInt32()) {
case 1:
return new IoError(FfiConverterString.read(dataStream));
default:
throw new UniFFITypeError("Unknown TestFlatError variant");
}
}
static computeSize(value) {
// Size of the Int indicating the variant
let totalSize = 4;
if (value instanceof IoError) {
return totalSize;
}
throw new UniFFITypeError("Unknown TestFlatError variant");
}
static write(dataStream, value) {
if (value instanceof IoError) {
dataStream.writeInt32(1);
return;
}
throw new UniFFITypeError("Unknown TestFlatError variant");
}
static errorClass = TestFlatError;
}
/**
* AsyncInterface
*/
export class AsyncInterface {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
/**
* init
* @param {string} name
* @returns {AsyncInterface}
*/
static init(
name) {
if (name instanceof UniffiSkipJsTypeCheck) {
name = name.value;
} else {
FfiConverterString.checkType(name);
}
const result = UniFFIScaffolding.callSync(
184, // uniffi_uniffi_bindings_tests_fn_constructor_asyncinterface_new
FfiConverterString.lower(name),
)
return handleRustResult(
result,
FfiConverterTypeAsyncInterface.lift.bind(FfiConverterTypeAsyncInterface),
null,
)
}
/**
* name
* @returns {Promise<string>}}
*/
async name() {
const result = await UniFFIScaffolding.callAsync(
185, // uniffi_uniffi_bindings_tests_fn_method_asyncinterface_name
FfiConverterTypeAsyncInterface.lowerReceiver(this),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeAsyncInterface extends FfiConverter {
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new AsyncInterface(opts);
}
static lower(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'AsyncInterface' instance");
}
return ptr;
}
static lowerReceiver(value) {
// This works exactly the same as lower for non-trait interfaces
return this.lower(value);
}
static read(dataStream) {
return this.lift(dataStream.readPointer(16));
}
static write(dataStream, value) {
dataStream.writePointer(16, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
/**
* Async version of `TestTraitInterface`
*/
export class AsyncTestTraitInterface {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
/**
* No-op function, this tests if that we can make calls at all
*/
async noop() {
const result = await UniFFIScaffolding.callAsync(
186, // uniffi_uniffi_bindings_tests_fn_method_asynctesttraitinterface_noop
FfiConverterTypeAsyncTestTraitInterface.lowerReceiver(this),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* Get the internal value
* @returns {Promise<number>}}
*/
async getValue() {
const result = await UniFFIScaffolding.callAsync(
187, // uniffi_uniffi_bindings_tests_fn_method_asynctesttraitinterface_get_value
FfiConverterTypeAsyncTestTraitInterface.lowerReceiver(this),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* Set the internal value
* @param {number} value
*/
async setValue(
value) {
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = await UniFFIScaffolding.callAsync(
188, // uniffi_uniffi_bindings_tests_fn_method_asynctesttraitinterface_set_value
FfiConverterTypeAsyncTestTraitInterface.lowerReceiver(this),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* Method aimed at maximizing the complexity
*
* This should return an error if `numbers.a == numbers.b` otherwise it should return numbers back
* unchanged.
* @param {CallbackInterfaceNumbers} numbers
* @returns {Promise<CallbackInterfaceNumbers>}}
*/
async throwIfEqual(
numbers) {
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = await UniFFIScaffolding.callAsync(
189, // uniffi_uniffi_bindings_tests_fn_method_asynctesttraitinterface_throw_if_equal
FfiConverterTypeAsyncTestTraitInterface.lowerReceiver(this),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
}
// FfiConverter for a trait interface. This is a hybrid of the FFIConverter regular interfaces and
// for callback interfaces.
//
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeAsyncTestTraitInterface extends FfiConverter {
// lift works like a regular interface
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new AsyncTestTraitInterface(opts);
}
// lower treats value like a callback interface
static lower(value) {
return uniffiCallbackHandlerUniffiBindingsTestsAsyncTestTraitInterface.storeCallbackObj(value)
}
// lowerReceiver is used when calling methods on an interface we got from Rust,
// it treats value like a regular interface.
static lowerReceiver(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'AsyncTestTraitInterface' instance");
}
return ptr;
}
static read(dataStream) {
return this.lift(dataStream.readPointer(17));
}
static write(dataStream, value) {
dataStream.writePointer(17, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
const uniffiCallbackHandlerUniffiBindingsTestsAsyncTestTraitInterface = new UniFFICallbackHandler(
"AsyncTestTraitInterface",
5,
[
new UniFFICallbackMethodHandler(
"noop",
[
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"getValue",
[
],
FfiConverterUInt32.lower.bind(FfiConverterUInt32),
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"setValue",
[
FfiConverterUInt32,
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"throwIfEqual",
[
FfiConverterTypeCallbackInterfaceNumbers,
],
FfiConverterTypeCallbackInterfaceNumbers.lower.bind(FfiConverterTypeCallbackInterfaceNumbers),
(e) => {
if (e instanceof TestError) {
return FfiConverterTypeTestError.lower(e);
}
throw e;
}
),
]
);
// Allow the shutdown-related functionality to be tested in the unit tests
UnitTestObjs.uniffiCallbackHandlerUniffiBindingsTestsAsyncTestTraitInterface = uniffiCallbackHandlerUniffiBindingsTestsAsyncTestTraitInterface;
/**
* ComplexMethods
*/
export class ComplexMethods {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
/**
* init
* @returns {ComplexMethods}
*/
static init() {
const result = UniFFIScaffolding.callSync(
190, // uniffi_uniffi_bindings_tests_fn_constructor_complexmethods_new
)
return handleRustResult(
result,
FfiConverterTypeComplexMethods.lift.bind(FfiConverterTypeComplexMethods),
null,
)
}
/**
* methodWithDefault
* @param {string} arg
* @returns {string}
*/
methodWithDefault(
arg = "DEFAULT") {
if (arg instanceof UniffiSkipJsTypeCheck) {
arg = arg.value;
} else {
FfiConverterString.checkType(arg);
}
const result = UniFFIScaffolding.callSync(
191, // uniffi_uniffi_bindings_tests_fn_method_complexmethods_method_with_default
FfiConverterTypeComplexMethods.lowerReceiver(this),
FfiConverterString.lower(arg),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
/**
* methodWithMultiWordArg
* @param {string} theArgument
* @returns {string}
*/
methodWithMultiWordArg(
theArgument) {
if (theArgument instanceof UniffiSkipJsTypeCheck) {
theArgument = theArgument.value;
} else {
FfiConverterString.checkType(theArgument);
}
const result = UniFFIScaffolding.callSync(
192, // uniffi_uniffi_bindings_tests_fn_method_complexmethods_method_with_multi_word_arg
FfiConverterTypeComplexMethods.lowerReceiver(this),
FfiConverterString.lower(theArgument),
)
return handleRustResult(
result,
FfiConverterString.lift.bind(FfiConverterString),
null,
)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeComplexMethods extends FfiConverter {
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new ComplexMethods(opts);
}
static lower(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'ComplexMethods' instance");
}
return ptr;
}
static lowerReceiver(value) {
// This works exactly the same as lower for non-trait interfaces
return this.lower(value);
}
static read(dataStream) {
return this.lift(dataStream.readPointer(18));
}
static write(dataStream, value) {
dataStream.writePointer(18, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
/**
* TestTraitInterface
*/
export class TestTraitInterface {
// Use `init` to instantiate this class.
// DO NOT USE THIS CONSTRUCTOR DIRECTLY
constructor(opts) {
if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
"Please use a UDL defined constructor, or the init function for the primary constructor")
}
if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
}
this[uniffiObjectPtr] = opts[constructUniffiObject];
}
/**
* No-op function, this tests if that we can make calls at all
*/
noop() {
const result = UniFFIScaffolding.callSync(
193, // uniffi_uniffi_bindings_tests_fn_method_testtraitinterface_noop
FfiConverterTypeTestTraitInterface.lowerReceiver(this),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* Get the internal value
* @returns {number}
*/
getValue() {
const result = UniFFIScaffolding.callSync(
194, // uniffi_uniffi_bindings_tests_fn_method_testtraitinterface_get_value
FfiConverterTypeTestTraitInterface.lowerReceiver(this),
)
return handleRustResult(
result,
FfiConverterUInt32.lift.bind(FfiConverterUInt32),
null,
)
}
/**
* Set the internal value
* @param {number} value
*/
setValue(
value) {
if (value instanceof UniffiSkipJsTypeCheck) {
value = value.value;
} else {
FfiConverterUInt32.checkType(value);
}
const result = UniFFIScaffolding.callSync(
195, // uniffi_uniffi_bindings_tests_fn_method_testtraitinterface_set_value
FfiConverterTypeTestTraitInterface.lowerReceiver(this),
FfiConverterUInt32.lower(value),
)
return handleRustResult(
result,
(result) => undefined,
null,
)
}
/**
* Method aimed at maximizing the complexity
*
* This should return an error if `numbers.a == numbers.b` otherwise it should return numbers back
* unchanged.
* @param {CallbackInterfaceNumbers} numbers
* @returns {CallbackInterfaceNumbers}
*/
throwIfEqual(
numbers) {
if (numbers instanceof UniffiSkipJsTypeCheck) {
numbers = numbers.value;
} else {
FfiConverterTypeCallbackInterfaceNumbers.checkType(numbers);
}
const result = UniFFIScaffolding.callSync(
196, // uniffi_uniffi_bindings_tests_fn_method_testtraitinterface_throw_if_equal
FfiConverterTypeTestTraitInterface.lowerReceiver(this),
FfiConverterTypeCallbackInterfaceNumbers.lower(numbers),
)
return handleRustResult(
result,
FfiConverterTypeCallbackInterfaceNumbers.lift.bind(FfiConverterTypeCallbackInterfaceNumbers),
FfiConverterTypeTestError.lift.bind(FfiConverterTypeTestError),
)
}
}
// FfiConverter for a trait interface. This is a hybrid of the FFIConverter regular interfaces and
// for callback interfaces.
//
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestTraitInterface extends FfiConverter {
// lift works like a regular interface
static lift(value) {
const opts = {};
opts[constructUniffiObject] = value;
return new TestTraitInterface(opts);
}
// lower treats value like a callback interface
static lower(value) {
return uniffiCallbackHandlerUniffiBindingsTestsTestTraitInterface.storeCallbackObj(value)
}
// lowerReceiver is used when calling methods on an interface we got from Rust,
// it treats value like a regular interface.
static lowerReceiver(value) {
const ptr = value[uniffiObjectPtr];
if (!(ptr instanceof UniFFIPointer)) {
throw new UniFFITypeError("Object is not a 'TestTraitInterface' instance");
}
return ptr;
}
static read(dataStream) {
return this.lift(dataStream.readPointer(19));
}
static write(dataStream, value) {
dataStream.writePointer(19, this.lower(value));
}
static computeSize(value) {
return 8;
}
}
const uniffiCallbackHandlerUniffiBindingsTestsTestTraitInterface = new UniFFICallbackHandler(
"TestTraitInterface",
6,
[
new UniFFICallbackMethodHandler(
"noop",
[
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"getValue",
[
],
FfiConverterUInt32.lower.bind(FfiConverterUInt32),
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"setValue",
[
FfiConverterUInt32,
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"throwIfEqual",
[
FfiConverterTypeCallbackInterfaceNumbers,
],
FfiConverterTypeCallbackInterfaceNumbers.lower.bind(FfiConverterTypeCallbackInterfaceNumbers),
(e) => {
if (e instanceof TestError) {
return FfiConverterTypeTestError.lower(e);
}
throw e;
}
),
]
);
// Allow the shutdown-related functionality to be tested in the unit tests
UnitTestObjs.uniffiCallbackHandlerUniffiBindingsTestsTestTraitInterface = uniffiCallbackHandlerUniffiBindingsTestsTestTraitInterface;
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestAsyncCallbackInterface extends FfiConverter {
static lower(callbackObj) {
return uniffiCallbackHandlerUniffiBindingsTestsTestAsyncCallbackInterface.storeCallbackObj(callbackObj)
}
static lift(handleId) {
return uniffiCallbackHandlerUniffiBindingsTestsTestAsyncCallbackInterface.getCallbackObj(handleId)
}
static read(dataStream) {
return this.lift(dataStream.readInt64())
}
static write(dataStream, callbackObj) {
dataStream.writeInt64(this.lower(callbackObj))
}
static computeSize(callbackObj) {
return 8;
}
}const uniffiCallbackHandlerUniffiBindingsTestsTestAsyncCallbackInterface = new UniFFICallbackHandler(
"TestAsyncCallbackInterface",
3,
[
new UniFFICallbackMethodHandler(
"noop",
[
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"getValue",
[
],
FfiConverterUInt32.lower.bind(FfiConverterUInt32),
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"setValue",
[
FfiConverterUInt32,
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"throwIfEqual",
[
FfiConverterTypeCallbackInterfaceNumbers,
],
FfiConverterTypeCallbackInterfaceNumbers.lower.bind(FfiConverterTypeCallbackInterfaceNumbers),
(e) => {
if (e instanceof TestError) {
return FfiConverterTypeTestError.lower(e);
}
throw e;
}
),
]
);
// Allow the shutdown-related functionality to be tested in the unit tests
UnitTestObjs.uniffiCallbackHandlerUniffiBindingsTestsTestAsyncCallbackInterface = uniffiCallbackHandlerUniffiBindingsTestsTestAsyncCallbackInterface;
// Export the FFIConverter object to make external types work.
export class FfiConverterTypeTestCallbackInterface extends FfiConverter {
static lower(callbackObj) {
return uniffiCallbackHandlerUniffiBindingsTestsTestCallbackInterface.storeCallbackObj(callbackObj)
}
static lift(handleId) {
return uniffiCallbackHandlerUniffiBindingsTestsTestCallbackInterface.getCallbackObj(handleId)
}
static read(dataStream) {
return this.lift(dataStream.readInt64())
}
static write(dataStream, callbackObj) {
dataStream.writeInt64(this.lower(callbackObj))
}
static computeSize(callbackObj) {
return 8;
}
}const uniffiCallbackHandlerUniffiBindingsTestsTestCallbackInterface = new UniFFICallbackHandler(
"TestCallbackInterface",
4,
[
new UniFFICallbackMethodHandler(
"noop",
[
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"getValue",
[
],
FfiConverterUInt32.lower.bind(FfiConverterUInt32),
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"setValue",
[
FfiConverterUInt32,
],
(result) => undefined,
(e) => {
throw e;
}
),
new UniFFICallbackMethodHandler(
"throwIfEqual",
[
FfiConverterTypeCallbackInterfaceNumbers,
],
FfiConverterTypeCallbackInterfaceNumbers.lower.bind(FfiConverterTypeCallbackInterfaceNumbers),
(e) => {
if (e instanceof TestError) {
return FfiConverterTypeTestError.lower(e);
}
throw e;
}
),
]
);
// Allow the shutdown-related functionality to be tested in the unit tests
UnitTestObjs.uniffiCallbackHandlerUniffiBindingsTestsTestCallbackInterface = uniffiCallbackHandlerUniffiBindingsTestsTestCallbackInterface;
// Export the FFIConverter object to make external types work.
export class FfiConverterMapStringString extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const map = new Map();
for (let i = 0; i < len; i++) {
const key = FfiConverterString.read(dataStream);
const value = FfiConverterString.read(dataStream);
map.set(key, value);
}
return map;
}
static write(dataStream, map) {
dataStream.writeInt32(map.size);
for (const [key, value] of map) {
FfiConverterString.write(dataStream, key);
FfiConverterString.write(dataStream, value);
}
}
static computeSize(map) {
// The size of the length
let size = 4;
for (const [key, value] of map) {
size += FfiConverterString.computeSize(key);
size += FfiConverterString.computeSize(value);
}
return size;
}
static checkType(map) {
for (const [key, value] of map) {
try {
FfiConverterString.checkType(key);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("(key)");
}
throw e;
}
try {
FfiConverterString.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${key}]`);
}
throw e;
}
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceUInt32 extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterUInt32.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterUInt32.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterUInt32.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterUInt32.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterBoolean extends FfiConverter {
static computeSize(_value) {
return 1;
}
static lift(value) {
return value == 1;
}
static lower(value) {
if (value) {
return 1;
} else {
return 0;
}
}
static write(dataStream, value) {
dataStream.writeUint8(this.lower(value))
}
static read(dataStream) {
return this.lift(dataStream.readUint8())
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterMapStringUInt32 extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const map = new Map();
for (let i = 0; i < len; i++) {
const key = FfiConverterString.read(dataStream);
const value = FfiConverterUInt32.read(dataStream);
map.set(key, value);
}
return map;
}
static write(dataStream, map) {
dataStream.writeInt32(map.size);
for (const [key, value] of map) {
FfiConverterString.write(dataStream, key);
FfiConverterUInt32.write(dataStream, value);
}
}
static computeSize(map) {
// The size of the length
let size = 4;
for (const [key, value] of map) {
size += FfiConverterString.computeSize(key);
size += FfiConverterUInt32.computeSize(value);
}
return size;
}
static checkType(map) {
for (const [key, value] of map) {
try {
FfiConverterString.checkType(key);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart("(key)");
}
throw e;
}
try {
FfiConverterUInt32.checkType(value);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${key}]`);
}
throw e;
}
}
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceMapStringUInt32 extends FfiConverterArrayBuffer {
static read(dataStream) {
const len = dataStream.readInt32();
const arr = [];
for (let i = 0; i < len; i++) {
arr.push(FfiConverterMapStringUInt32.read(dataStream));
}
return arr;
}
static write(dataStream, value) {
dataStream.writeInt32(value.length);
value.forEach((innerValue) => {
FfiConverterMapStringUInt32.write(dataStream, innerValue);
})
}
static computeSize(value) {
// The size of the length
let size = 4;
for (const innerValue of value) {
size += FfiConverterMapStringUInt32.computeSize(innerValue);
}
return size;
}
static checkType(value) {
if (!Array.isArray(value)) {
throw new UniFFITypeError(`${value} is not an array`);
}
value.forEach((innerValue, idx) => {
try {
FfiConverterMapStringUInt32.checkType(innerValue);
} catch (e) {
if (e instanceof UniFFITypeError) {
e.addItemDescriptionPart(`[${idx}]`);
}
throw e;
}
})
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalSequenceMapStringUInt32 extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterSequenceMapStringUInt32.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterSequenceMapStringUInt32.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterSequenceMapStringUInt32.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterSequenceMapStringUInt32.computeSize(value)
}
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalUInt32 extends FfiConverterArrayBuffer {
static checkType(value) {
if (value !== undefined && value !== null) {
FfiConverterUInt32.checkType(value)
}
}
static read(dataStream) {
const code = dataStream.readUint8(0);
switch (code) {
case 0:
return null
case 1:
return FfiConverterUInt32.read(dataStream)
default:
throw new UniFFIError(`Unexpected code: ${code}`);
}
}
static write(dataStream, value) {
if (value === null || value === undefined) {
dataStream.writeUint8(0);
return;
}
dataStream.writeUint8(1);
FfiConverterUInt32.write(dataStream, value)
}
static computeSize(value) {
if (value === null || value === undefined) {
return 1;
}
return 1 + FfiConverterUInt32.computeSize(value)
}
}
// Wrapper to skip type checking for function arguments
//
// This is only defined and used on test fixtures. The goal is to skip the JS type checking so that
// we can test the lower-level C++ type checking.
export class UniffiSkipJsTypeCheck {
constructor(value) {
this.value = value;
}
}