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 IsoWeekOfYear {
#weekNumber;
get weekNumber() {
return this.#weekNumber;
}
set weekNumber(value){
this.#weekNumber = value;
}
#isoYear;
get isoYear() {
return this.#isoYear;
}
set isoYear(value){
this.#isoYear = value;
}
/** Create `IsoWeekOfYear` from an object that contains all of `IsoWeekOfYear`s fields.
* Optional fields do not need to be included in the provided object.
*/
static fromFields(structObj) {
return new IsoWeekOfYear(structObj);
}
#internalConstructor(structObj) {
if (typeof structObj !== "object") {
throw new Error("IsoWeekOfYear's constructor takes an object of IsoWeekOfYear's fields.");
}
if ("weekNumber" in structObj) {
this.#weekNumber = structObj.weekNumber;
} else {
throw new Error("Missing required field weekNumber.");
}
if ("isoYear" in structObj) {
this.#isoYear = structObj.isoYear;
} else {
throw new Error("Missing required field isoYear.");
}
return this;
}
// Return this struct in FFI function friendly format.
// Returns an array that can be expanded with spread syntax (...)
// JS structs need to be generated with or without padding depending on whether they are being passed as aggregates or splatted out into fields.
// Most of the time this is known beforehand: large structs (>2 scalar fields) always get padding, and structs passed directly in parameters omit padding
// if they are small. However small structs within large structs also get padding, and we signal that by setting forcePadding.
_intoFFI(
functionCleanupArena,
appendArrayMap,
forcePadding
) {
return [this.#weekNumber, ...diplomatRuntime.maybePaddingFields(forcePadding, 3 /* x i8 */), this.#isoYear]
}
static _fromSuppliedValue(internalConstructor, obj) {
if (internalConstructor !== diplomatRuntime.internalConstructor) {
throw new Error("_fromSuppliedValue cannot be called externally.");
}
if (obj instanceof IsoWeekOfYear) {
return obj;
}
return IsoWeekOfYear.fromFields(obj);
}
_writeToArrayBuffer(
arrayBuffer,
offset,
functionCleanupArena,
appendArrayMap,
forcePadding
) {
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#weekNumber, Uint8Array);
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#isoYear, Int32Array);
}
// 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("IsoWeekOfYear._fromFFI is not meant to be called externally. Please use the default constructor.");
}
let structObj = {};
const weekNumberDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0];
structObj.weekNumber = weekNumberDeref;
const isoYearDeref = (new Int32Array(wasm.memory.buffer, ptr + 4, 1))[0];
structObj.isoYear = isoYearDeref;
return new IsoWeekOfYear(structObj);
}
constructor(structObj) {
return this.#internalConstructor(...arguments)
}
}