Source code

Revision control

Copy as Markdown

Other Tools

// generated by diplomat-tool
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";
export class PluralCategories {
#zero;
get zero() {
return this.#zero;
}
#one;
get one() {
return this.#one;
}
#two;
get two() {
return this.#two;
}
#few;
get few() {
return this.#few;
}
#many;
get many() {
return this.#many;
}
#other;
get other() {
return this.#other;
}
#internalConstructor(structObj, internalConstructor) {
if (typeof structObj !== "object") {
throw new Error("PluralCategories's constructor takes an object of PluralCategories's fields.");
}
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("PluralCategories is an out struct and can only be created internally.");
}
if ("zero" in structObj) {
this.#zero = structObj.zero;
} else {
throw new Error("Missing required field zero.");
}
if ("one" in structObj) {
this.#one = structObj.one;
} else {
throw new Error("Missing required field one.");
}
if ("two" in structObj) {
this.#two = structObj.two;
} else {
throw new Error("Missing required field two.");
}
if ("few" in structObj) {
this.#few = structObj.few;
} else {
throw new Error("Missing required field few.");
}
if ("many" in structObj) {
this.#many = structObj.many;
} else {
throw new Error("Missing required field many.");
}
if ("other" in structObj) {
this.#other = structObj.other;
} else {
throw new Error("Missing required field other.");
}
return this;
}
// Return this struct in FFI function friendly format.
// Returns an array that can be expanded with spread syntax (...)
_intoFFI(
functionCleanupArena,
appendArrayMap
) {
return [this.#zero, this.#one, this.#two, this.#few, this.#many, this.#other]
}
static _fromSuppliedValue(internalConstructor, obj) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("_fromSuppliedValue cannot be called externally.");
}
if (obj instanceof PluralCategories) {
return obj;
}
return PluralCategories.fromFields(obj);
}
_writeToArrayBuffer(
arrayBuffer,
offset,
functionCleanupArena,
appendArrayMap
) {
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#zero, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#one, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#two, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#few, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#many, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#other, Uint8Array);
}
// This struct contains borrowed fields, so this takes in a list of
// "edges" corresponding to where each lifetime's data may have been borrowed from
// and passes it down to individual fields containing the borrow.
// This method does not attempt to handle any dependencies between lifetimes, the caller
// should handle this when constructing edge arrays.
static _fromFFI(internalConstructor, ptr) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("PluralCategories._fromFFI is not meant to be called externally. Please use the default constructor.");
}
let structObj = {};
const zeroDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] === 1;
structObj.zero = zeroDeref;
const oneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] === 1;
structObj.one = oneDeref;
const twoDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] === 1;
structObj.two = twoDeref;
const fewDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] === 1;
structObj.few = fewDeref;
const manyDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] === 1;
structObj.many = manyDeref;
const otherDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] === 1;
structObj.other = otherDeref;
return new PluralCategories(structObj, internalConstructor);
}
constructor(structObj, internalConstructor) {
return this.#internalConstructor(...arguments)
}
}