• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { TimeZone } from "./TimeZone.mjs"
3import wasm from "./diplomat-wasm.mjs";
4import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
6
7
8export class TimeZoneAndCanonicalAndNormalized {
9
10    #timeZone;
11
12    get timeZone()  {
13        return this.#timeZone;
14    }
15
16    #canonical;
17
18    get canonical()  {
19        return this.#canonical;
20    }
21
22    #normalized;
23
24    get normalized()  {
25        return this.#normalized;
26    }
27
28    #internalConstructor(structObj, internalConstructor) {
29        if (typeof structObj !== "object") {
30            throw new Error("TimeZoneAndCanonicalAndNormalized's constructor takes an object of TimeZoneAndCanonicalAndNormalized's fields.");
31        }
32
33        if (internalConstructor !== diplomatRuntime.internalConstructor) {
34            throw new Error("TimeZoneAndCanonicalAndNormalized is an out struct and can only be created internally.");
35        }
36        if ("timeZone" in structObj) {
37            this.#timeZone = structObj.timeZone;
38        } else {
39            throw new Error("Missing required field timeZone.");
40        }
41
42        if ("canonical" in structObj) {
43            this.#canonical = structObj.canonical;
44        } else {
45            throw new Error("Missing required field canonical.");
46        }
47
48        if ("normalized" in structObj) {
49            this.#normalized = structObj.normalized;
50        } else {
51            throw new Error("Missing required field normalized.");
52        }
53
54        return this;
55    }
56
57    // Return this struct in FFI function friendly format.
58    // Returns an array that can be expanded with spread syntax (...)
59    // If this struct contains any slices, their lifetime-edge-relevant information will be
60    // set up here, and can be appended to any relevant lifetime arrays here. <lifetime>AppendArray accepts a list
61    // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple
62    // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from.
63    _intoFFI(
64        functionCleanupArena,
65        appendArrayMap
66    ) {
67        return [this.#timeZone.ffiValue, ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).splat(), ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized)).splat()]
68    }
69
70    static _fromSuppliedValue(internalConstructor, obj) {
71        if (internalConstructor !== diplomatRuntime.internalConstructor) {
72            throw new Error("_fromSuppliedValue cannot be called externally.");
73        }
74
75        if (obj instanceof TimeZoneAndCanonicalAndNormalized) {
76            return obj;
77        }
78
79        return TimeZoneAndCanonicalAndNormalized.fromFields(obj);
80    }
81
82    _writeToArrayBuffer(
83        arrayBuffer,
84        offset,
85        functionCleanupArena,
86        appendArrayMap
87    ) {
88        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array);
89        diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4);
90        diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized)).writePtrLenToArrayBuffer(arrayBuffer, offset + 12);
91    }
92
93    static _fromFFI(internalConstructor, ptr, aEdges) {
94        if (internalConstructor !== diplomatRuntime.internalConstructor) {
95            throw new Error("TimeZoneAndCanonicalAndNormalized._fromFFI is not meant to be called externally. Please use the default constructor.");
96        }
97        let structObj = {};
98        const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr);
99        structObj.timeZone = new TimeZone(diplomatRuntime.internalConstructor, timeZoneDeref, []);
100        const canonicalDeref = ptr + 4;
101        structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref,  "string8", aEdges).getValue();
102        const normalizedDeref = ptr + 12;
103        structObj.normalized = new diplomatRuntime.DiplomatSliceStr(wasm, normalizedDeref,  "string8", aEdges).getValue();
104
105        return new TimeZoneAndCanonicalAndNormalized(structObj, internalConstructor);
106    }
107
108    // Return all fields corresponding to lifetime `'a`
109    // without handling lifetime dependencies (this is the job of the caller)
110    // This is all fields that may be borrowed from if borrowing `'a`,
111    // assuming that there are no `'other: a`. bounds. In case of such bounds,
112    // the caller should take care to also call _fieldsForLifetimeOther
113    get _fieldsForLifetimeA() {
114        return [canonical, normalized];
115    };
116
117    constructor(structObj, internalConstructor) {
118        return this.#internalConstructor(...arguments)
119    }
120}