1// generated by diplomat-tool 2import wasm from "./diplomat-wasm.mjs"; 3import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6 7export class PluralCategories { 8 9 #zero; 10 11 get zero() { 12 return this.#zero; 13 } 14 15 #one; 16 17 get one() { 18 return this.#one; 19 } 20 21 #two; 22 23 get two() { 24 return this.#two; 25 } 26 27 #few; 28 29 get few() { 30 return this.#few; 31 } 32 33 #many; 34 35 get many() { 36 return this.#many; 37 } 38 39 #other; 40 41 get other() { 42 return this.#other; 43 } 44 45 #internalConstructor(structObj, internalConstructor) { 46 if (typeof structObj !== "object") { 47 throw new Error("PluralCategories's constructor takes an object of PluralCategories's fields."); 48 } 49 50 if (internalConstructor !== diplomatRuntime.internalConstructor) { 51 throw new Error("PluralCategories is an out struct and can only be created internally."); 52 } 53 if ("zero" in structObj) { 54 this.#zero = structObj.zero; 55 } else { 56 throw new Error("Missing required field zero."); 57 } 58 59 if ("one" in structObj) { 60 this.#one = structObj.one; 61 } else { 62 throw new Error("Missing required field one."); 63 } 64 65 if ("two" in structObj) { 66 this.#two = structObj.two; 67 } else { 68 throw new Error("Missing required field two."); 69 } 70 71 if ("few" in structObj) { 72 this.#few = structObj.few; 73 } else { 74 throw new Error("Missing required field few."); 75 } 76 77 if ("many" in structObj) { 78 this.#many = structObj.many; 79 } else { 80 throw new Error("Missing required field many."); 81 } 82 83 if ("other" in structObj) { 84 this.#other = structObj.other; 85 } else { 86 throw new Error("Missing required field other."); 87 } 88 89 return this; 90 } 91 92 // Return this struct in FFI function friendly format. 93 // Returns an array that can be expanded with spread syntax (...) 94 95 _intoFFI( 96 functionCleanupArena, 97 appendArrayMap 98 ) { 99 return [this.#zero, this.#one, this.#two, this.#few, this.#many, this.#other] 100 } 101 102 static _fromSuppliedValue(internalConstructor, obj) { 103 if (internalConstructor !== diplomatRuntime.internalConstructor) { 104 throw new Error("_fromSuppliedValue cannot be called externally."); 105 } 106 107 if (obj instanceof PluralCategories) { 108 return obj; 109 } 110 111 return PluralCategories.fromFields(obj); 112 } 113 114 _writeToArrayBuffer( 115 arrayBuffer, 116 offset, 117 functionCleanupArena, 118 appendArrayMap 119 ) { 120 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#zero, Uint8Array); 121 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#one, Uint8Array); 122 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#two, Uint8Array); 123 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#few, Uint8Array); 124 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#many, Uint8Array); 125 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#other, Uint8Array); 126 } 127 128 // This struct contains borrowed fields, so this takes in a list of 129 // "edges" corresponding to where each lifetime's data may have been borrowed from 130 // and passes it down to individual fields containing the borrow. 131 // This method does not attempt to handle any dependencies between lifetimes, the caller 132 // should handle this when constructing edge arrays. 133 static _fromFFI(internalConstructor, ptr) { 134 if (internalConstructor !== diplomatRuntime.internalConstructor) { 135 throw new Error("PluralCategories._fromFFI is not meant to be called externally. Please use the default constructor."); 136 } 137 let structObj = {}; 138 const zeroDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] === 1; 139 structObj.zero = zeroDeref; 140 const oneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] === 1; 141 structObj.one = oneDeref; 142 const twoDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] === 1; 143 structObj.two = twoDeref; 144 const fewDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] === 1; 145 structObj.few = fewDeref; 146 const manyDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] === 1; 147 structObj.many = manyDeref; 148 const otherDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] === 1; 149 structObj.other = otherDeref; 150 151 return new PluralCategories(structObj, internalConstructor); 152 } 153 154 constructor(structObj, internalConstructor) { 155 return this.#internalConstructor(...arguments) 156 } 157}