@stryke/capnp 0.12.57 → 0.12.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/bin/capnpc.cjs +11454 -175
  2. package/bin/capnpc.mjs +11461 -174
  3. package/bin/capnpc.mjs.map +1 -1
  4. package/dist/capnp-es.GpvEvMIK-BH8YrftV.mjs +2362 -0
  5. package/dist/{capnp-es.GpvEvMIK-BsgDzeBH.mjs.map → capnp-es.GpvEvMIK-BH8YrftV.mjs.map} +1 -1
  6. package/dist/capnp-es.GpvEvMIK-BY4gHyC5.cjs +3171 -0
  7. package/dist/compile-Cxf2WDt0.mjs +3524 -0
  8. package/dist/{compile-DGAyhMqI.mjs.map → compile-Cxf2WDt0.mjs.map} +1 -1
  9. package/dist/compile-WDbSb0OW.cjs +3536 -0
  10. package/dist/compile.cjs +5 -1
  11. package/dist/compile.mjs +4 -1
  12. package/dist/dist-BZ3g4lB8.cjs +3889 -0
  13. package/dist/dist-Qno9L0HI.mjs +3693 -0
  14. package/dist/{dist-CK47iMja.mjs.map → dist-Qno9L0HI.mjs.map} +1 -1
  15. package/dist/helpers-BuE0WAt5.mjs +2457 -0
  16. package/dist/{helpers-rVOvMK2d.mjs.map → helpers-BuE0WAt5.mjs.map} +1 -1
  17. package/dist/helpers-a9QXtt7l.cjs +2471 -0
  18. package/dist/helpers.cjs +3 -1
  19. package/dist/helpers.mjs +3 -1
  20. package/dist/index.cjs +67 -1
  21. package/dist/index.mjs +7 -1
  22. package/dist/rpc-helpers.cjs +116 -1
  23. package/dist/rpc-helpers.mjs +114 -1
  24. package/dist/rpc-helpers.mjs.map +1 -1
  25. package/dist/types-Cuj2daUE.mjs +8 -0
  26. package/dist/{types-BujoAx-K.mjs.map → types-Cuj2daUE.mjs.map} +1 -1
  27. package/dist/types-DHrjS-69.cjs +13 -0
  28. package/dist/types.cjs +3 -1
  29. package/dist/types.mjs +3 -1
  30. package/package.json +4 -4
  31. package/schemas/cpp.cjs +6 -1
  32. package/schemas/cpp.mjs +5 -1
  33. package/schemas/cpp.mjs.map +1 -1
  34. package/schemas/persistent.cjs +204 -1
  35. package/schemas/persistent.mjs +198 -1
  36. package/schemas/persistent.mjs.map +1 -1
  37. package/schemas/rpc-twoparty.cjs +211 -1
  38. package/schemas/rpc-twoparty.mjs +204 -1
  39. package/schemas/rpc-twoparty.mjs.map +1 -1
  40. package/schemas/rpc.cjs +2424 -1
  41. package/schemas/rpc.mjs +2395 -1
  42. package/schemas/rpc.mjs.map +1 -1
  43. package/schemas/schema.cjs +2576 -1
  44. package/schemas/schema.mjs +2531 -1
  45. package/schemas/schema.mjs.map +1 -1
  46. package/schemas/src-BvgdYlCi.mjs +3067 -0
  47. package/schemas/{src-DqIy7I3p.mjs.map → src-BvgdYlCi.mjs.map} +1 -1
  48. package/schemas/src-C4qUIogl.cjs +3157 -0
  49. package/schemas/ts.cjs +6 -1
  50. package/schemas/ts.mjs +5 -1
  51. package/schemas/ts.mjs.map +1 -1
  52. package/dist/capnp-es.GpvEvMIK-BsgDzeBH.mjs +0 -12
  53. package/dist/capnp-es.GpvEvMIK-xNDcbmgx.cjs +0 -11
  54. package/dist/compile-B7Tm_xbT.cjs +0 -169
  55. package/dist/compile-DGAyhMqI.mjs +0 -163
  56. package/dist/dist-C1gSYYrg.cjs +0 -1
  57. package/dist/dist-CK47iMja.mjs +0 -2
  58. package/dist/helpers-DmrSADWE.cjs +0 -26
  59. package/dist/helpers-rVOvMK2d.mjs +0 -27
  60. package/dist/types-BujoAx-K.mjs +0 -2
  61. package/dist/types-D6FuBB1k.cjs +0 -1
  62. package/schemas/src-CGrmR2BO.cjs +0 -11
  63. package/schemas/src-DqIy7I3p.mjs +0 -12
@@ -0,0 +1,2362 @@
1
+ //#region ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.3/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs
2
+ var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
3
+ ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
4
+ ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
5
+ ListElementSize2[ListElementSize2["BYTE"] = 2] = "BYTE";
6
+ ListElementSize2[ListElementSize2["BYTE_2"] = 3] = "BYTE_2";
7
+ ListElementSize2[ListElementSize2["BYTE_4"] = 4] = "BYTE_4";
8
+ ListElementSize2[ListElementSize2["BYTE_8"] = 5] = "BYTE_8";
9
+ ListElementSize2[ListElementSize2["POINTER"] = 6] = "POINTER";
10
+ ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
11
+ return ListElementSize2;
12
+ })(ListElementSize || {});
13
+ const tmpWord = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
14
+ new Uint16Array(tmpWord.buffer)[0] = 258;
15
+ const DEFAULT_BUFFER_SIZE = 4096;
16
+ const DEFAULT_TRAVERSE_LIMIT = 64 << 20;
17
+ const LIST_SIZE_MASK = 7;
18
+ const MAX_BUFFER_DUMP_BYTES = 8192;
19
+ const MAX_INT32 = 2147483647;
20
+ const MAX_UINT32 = 4294967295;
21
+ const MIN_SINGLE_SEGMENT_GROWTH = 4096;
22
+ const NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
23
+ const PACK_SPAN_THRESHOLD = 2;
24
+ const POINTER_DOUBLE_FAR_MASK = 4;
25
+ const POINTER_TYPE_MASK = 3;
26
+ const MAX_DEPTH = MAX_INT32;
27
+ const MAX_SEGMENT_LENGTH = MAX_UINT32;
28
+ const INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
29
+ function assertNever(n) {
30
+ throw new Error(`CAPNP-TS000 Unreachable code detected. (never block hit with: ${n})`);
31
+ }
32
+ const MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
33
+ const MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
34
+ const MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
35
+ const MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
36
+ const NOT_IMPLEMENTED = "CAPNP-TS006 %s is not implemented.";
37
+ const PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
38
+ const PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
39
+ const PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
40
+ const PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
41
+ const PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
42
+ const PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
43
+ const PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
44
+ const PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
45
+ const PTR_INVALID_UNION_ACCESS = "CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
46
+ const PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
47
+ const PTR_STRUCT_DATA_OUT_OF_BOUNDS = "CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
48
+ const PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
49
+ const PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
50
+ const PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
51
+ const PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
52
+ const SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
53
+ const SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
54
+ const SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
55
+ const SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
56
+ const SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
57
+ const TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
58
+ const LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
59
+ const LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
60
+ const RPC_NULL_CLIENT = "CAPNP-TS100 Call on null client.";
61
+ const RPC_CALL_QUEUE_FULL = "CAPNP-TS101 Promised answer call queue full.";
62
+ const RPC_QUEUE_CALL_CANCEL = "CAPNP-TS102 Queue call canceled.";
63
+ const RPC_ZERO_REF = "CAPNP-TS105 Ref() called on zeroed refcount.";
64
+ const RPC_IMPORT_CLOSED = "CAPNP-TS106 Call on closed import.";
65
+ const RPC_METHOD_NOT_IMPLEMENTED = "CAPNP-TS107 Method not implemented.";
66
+ const RPC_BAD_TARGET = "CAPNP-TS109 Target not found.";
67
+ const RPC_RETURN_FOR_UNKNOWN_QUESTION = "CAPNP-TS111 Received return for unknown question (id=%s).";
68
+ const RPC_QUESTION_ID_REUSED = "CAPNP-TS112 Attempted to re-use question id (%s).";
69
+ const RPC_UNKNOWN_EXPORT_ID = "CAPNP-TS113 Capability table references unknown export ID (%s).";
70
+ const RPC_UNKNOWN_ANSWER_ID = "CAPNP-TS114 Capability table references unknown answer ID (%s).";
71
+ const RPC_UNKNOWN_CAP_DESCRIPTOR = "CAPNP-TS115 Unknown cap descriptor type (which: %s).";
72
+ const RPC_METHOD_ERROR = "CAPNP-TS116 RPC method failed at %s.%s(): %s";
73
+ const RPC_ERROR = "CAPNP-TS117 RPC call failed, reason: %s";
74
+ const RPC_NO_MAIN_INTERFACE = "CAPNP-TS118 Received bootstrap message without main interface set.";
75
+ const RPC_FINISH_UNKNOWN_ANSWER = "CAPNP-TS119 Received finish message for unknown answer ID (%s).";
76
+ const RPC_FULFILL_ALREADY_CALLED = "CAPNP-TS120 Fulfill called more than once for question (%s).";
77
+ function bufferToHex(buffer) {
78
+ const a = new Uint8Array(buffer);
79
+ const h = [];
80
+ for (let i = 0; i < a.byteLength; i++) h.push(pad(a[i].toString(16), 2));
81
+ return `[${h.join(" ")}]`;
82
+ }
83
+ function dumpBuffer(buffer) {
84
+ const b = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
85
+ const byteLength = Math.min(b.byteLength, MAX_BUFFER_DUMP_BYTES);
86
+ let r = format("\n=== buffer[%d] ===", byteLength);
87
+ for (let j = 0; j < byteLength; j += 16) {
88
+ r += `
89
+ ${pad(j.toString(16), 8)}: `;
90
+ let s = "";
91
+ let k;
92
+ for (k = 0; k < 16 && j + k < b.byteLength; k++) {
93
+ const v = b[j + k];
94
+ r += `${pad(v.toString(16), 2)} `;
95
+ s += v > 31 && v < 255 ? String.fromCharCode(v) : "·";
96
+ if (k === 7) r += " ";
97
+ }
98
+ r += `${" ".repeat((17 - k) * 3)}${s}`;
99
+ }
100
+ r += "\n";
101
+ if (byteLength !== b.byteLength) r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
102
+ return r;
103
+ }
104
+ function format(s, ...args) {
105
+ const n = s.length;
106
+ let arg;
107
+ let argIndex = 0;
108
+ let c;
109
+ let escaped = false;
110
+ let i = 0;
111
+ let leadingZero = false;
112
+ let precision;
113
+ let result = "";
114
+ function nextArg() {
115
+ return args[argIndex++];
116
+ }
117
+ function slurpNumber() {
118
+ let digits = "";
119
+ while (/\d/.test(s[i])) {
120
+ digits += s[i++];
121
+ c = s[i];
122
+ }
123
+ return digits.length > 0 ? Number.parseInt(digits, 10) : null;
124
+ }
125
+ for (; i < n; ++i) {
126
+ c = s[i];
127
+ if (escaped) {
128
+ escaped = false;
129
+ if (c === ".") {
130
+ leadingZero = false;
131
+ c = s[++i];
132
+ } else if (c === "0" && s[i + 1] === ".") {
133
+ leadingZero = true;
134
+ i += 2;
135
+ c = s[i];
136
+ } else leadingZero = true;
137
+ precision = slurpNumber();
138
+ switch (c) {
139
+ case "a":
140
+ result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
141
+ break;
142
+ case "b":
143
+ result += Number.parseInt(String(nextArg()), 10).toString(2);
144
+ break;
145
+ case "c":
146
+ arg = nextArg();
147
+ result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
148
+ break;
149
+ case "d":
150
+ result += Number.parseInt(String(nextArg()), 10);
151
+ break;
152
+ case "f": {
153
+ const tmp = Number.parseFloat(String(nextArg())).toFixed(precision || 6);
154
+ result += leadingZero ? tmp : tmp.replace(/^0/, "");
155
+ break;
156
+ }
157
+ case "j":
158
+ result += JSON.stringify(nextArg());
159
+ break;
160
+ case "o":
161
+ result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
162
+ break;
163
+ case "s":
164
+ result += nextArg();
165
+ break;
166
+ case "x":
167
+ result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
168
+ break;
169
+ case "X":
170
+ result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
171
+ break;
172
+ default:
173
+ result += c;
174
+ break;
175
+ }
176
+ } else if (c === "%") escaped = true;
177
+ else result += c;
178
+ }
179
+ return result;
180
+ }
181
+ function pad(v, width, pad2 = "0") {
182
+ return v.length >= width ? v : Array.from({ length: width - v.length + 1 }).join(pad2) + v;
183
+ }
184
+ function padToWord$1(size) {
185
+ return size + 7 & -8;
186
+ }
187
+ var ObjectSize = class {
188
+ /**
189
+ * Creates a new ObjectSize instance.
190
+ *
191
+ * @param dataByteLength - The number of bytes in the data section of the struct
192
+ * @param pointerLength - The number of pointers in the pointer section of the struct
193
+ */
194
+ constructor(dataByteLength, pointerLength) {
195
+ this.dataByteLength = dataByteLength;
196
+ this.pointerLength = pointerLength;
197
+ }
198
+ toString() {
199
+ return format("ObjectSize_dw:%d,pc:%d", getDataWordLength(this), this.pointerLength);
200
+ }
201
+ };
202
+ function getByteLength(o) {
203
+ return o.dataByteLength + o.pointerLength * 8;
204
+ }
205
+ function getDataWordLength(o) {
206
+ return o.dataByteLength / 8;
207
+ }
208
+ function getWordLength(o) {
209
+ return o.dataByteLength / 8 + o.pointerLength;
210
+ }
211
+ function padToWord(o) {
212
+ return new ObjectSize(padToWord$1(o.dataByteLength), o.pointerLength);
213
+ }
214
+ var Orphan = class {
215
+ /** If this member is not present then the orphan has already been adopted, or something went very wrong. */
216
+ _capnp;
217
+ byteOffset;
218
+ segment;
219
+ constructor(src) {
220
+ const c = getContent(src);
221
+ this.segment = c.segment;
222
+ this.byteOffset = c.byteOffset;
223
+ this._capnp = {};
224
+ this._capnp.type = getTargetPointerType(src);
225
+ switch (this._capnp.type) {
226
+ case PointerType.STRUCT:
227
+ this._capnp.size = getTargetStructSize(src);
228
+ break;
229
+ case PointerType.LIST:
230
+ this._capnp.length = getTargetListLength(src);
231
+ this._capnp.elementSize = getTargetListElementSize(src);
232
+ if (this._capnp.elementSize === ListElementSize.COMPOSITE) this._capnp.size = getTargetCompositeListSize(src);
233
+ break;
234
+ case PointerType.OTHER:
235
+ this._capnp.capId = getCapabilityId(src);
236
+ break;
237
+ default: throw new Error(PTR_INVALID_POINTER_TYPE);
238
+ }
239
+ erasePointer(src);
240
+ }
241
+ /**
242
+ * Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed.
243
+ *
244
+ * @param dst The destination pointer.
245
+ */
246
+ _moveTo(dst) {
247
+ if (this._capnp === void 0) throw new Error(format(PTR_ALREADY_ADOPTED, this));
248
+ if (this.segment.message !== dst.segment.message) throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst));
249
+ erase(dst);
250
+ const res = initPointer(this.segment, this.byteOffset, dst);
251
+ switch (this._capnp.type) {
252
+ case PointerType.STRUCT:
253
+ setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
254
+ break;
255
+ case PointerType.LIST: {
256
+ let { offsetWords } = res;
257
+ if (this._capnp.elementSize === ListElementSize.COMPOSITE) offsetWords--;
258
+ setListPointer(offsetWords, this._capnp.elementSize, this._capnp.length, res.pointer, this._capnp.size);
259
+ break;
260
+ }
261
+ case PointerType.OTHER:
262
+ setInterfacePointer(this._capnp.capId, res.pointer);
263
+ break;
264
+ default: throw new Error(PTR_INVALID_POINTER_TYPE);
265
+ }
266
+ this._capnp = void 0;
267
+ }
268
+ dispose() {
269
+ if (this._capnp === void 0) return;
270
+ switch (this._capnp.type) {
271
+ case PointerType.STRUCT:
272
+ this.segment.fillZeroWords(this.byteOffset, getWordLength(this._capnp.size));
273
+ break;
274
+ case PointerType.LIST: {
275
+ const byteLength = getListByteLength(this._capnp.elementSize, this._capnp.length, this._capnp.size);
276
+ this.segment.fillZeroWords(this.byteOffset, byteLength);
277
+ break;
278
+ }
279
+ }
280
+ this._capnp = void 0;
281
+ }
282
+ [Symbol.for("nodejs.util.inspect.custom")]() {
283
+ return format("Orphan_%d@%a,type:%s", this.segment.id, this.byteOffset, this._capnp && this._capnp.type);
284
+ }
285
+ };
286
+ function adopt(src, p) {
287
+ src._moveTo(p);
288
+ }
289
+ function disown(p) {
290
+ return new Orphan(p);
291
+ }
292
+ function dump$1(p) {
293
+ return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8));
294
+ }
295
+ function getListByteLength(elementSize, length, compositeSize) {
296
+ switch (elementSize) {
297
+ case ListElementSize.BIT: return padToWord$1(length + 7 >>> 3);
298
+ case ListElementSize.BYTE:
299
+ case ListElementSize.BYTE_2:
300
+ case ListElementSize.BYTE_4:
301
+ case ListElementSize.BYTE_8:
302
+ case ListElementSize.POINTER:
303
+ case ListElementSize.VOID: return padToWord$1(getListElementByteLength(elementSize) * length);
304
+ case ListElementSize.COMPOSITE:
305
+ if (compositeSize === void 0) throw new Error(format(PTR_INVALID_LIST_SIZE, NaN));
306
+ return length * padToWord$1(getByteLength(compositeSize));
307
+ default: throw new Error(PTR_INVALID_LIST_SIZE);
308
+ }
309
+ }
310
+ function getListElementByteLength(elementSize) {
311
+ switch (elementSize) {
312
+ case ListElementSize.BIT: return NaN;
313
+ case ListElementSize.BYTE: return 1;
314
+ case ListElementSize.BYTE_2: return 2;
315
+ case ListElementSize.BYTE_4: return 4;
316
+ case ListElementSize.BYTE_8:
317
+ case ListElementSize.POINTER: return 8;
318
+ case ListElementSize.COMPOSITE: return NaN;
319
+ case ListElementSize.VOID: return 0;
320
+ default: throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
321
+ }
322
+ }
323
+ function add(offset, p) {
324
+ return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit);
325
+ }
326
+ function copyFrom(src, p) {
327
+ if (p.segment === src.segment && p.byteOffset === src.byteOffset) return;
328
+ erase(p);
329
+ if (isNull(src)) return;
330
+ switch (getTargetPointerType(src)) {
331
+ case PointerType.STRUCT:
332
+ copyFromStruct(src, p);
333
+ break;
334
+ case PointerType.LIST:
335
+ copyFromList(src, p);
336
+ break;
337
+ case PointerType.OTHER:
338
+ copyFromInterface(src, p);
339
+ break;
340
+ default: throw new Error(format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p)));
341
+ }
342
+ }
343
+ function erase(p) {
344
+ if (isNull(p)) return;
345
+ let c;
346
+ switch (getTargetPointerType(p)) {
347
+ case PointerType.STRUCT: {
348
+ const size = getTargetStructSize(p);
349
+ c = getContent(p);
350
+ c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
351
+ for (let i = 0; i < size.pointerLength; i++) erase(add(i * 8, c));
352
+ break;
353
+ }
354
+ case PointerType.LIST: {
355
+ const elementSize = getTargetListElementSize(p);
356
+ const length = getTargetListLength(p);
357
+ let contentWords = padToWord$1(length * getListElementByteLength(elementSize));
358
+ c = getContent(p);
359
+ if (elementSize === ListElementSize.POINTER) {
360
+ for (let i = 0; i < length; i++) erase(new Pointer(c.segment, c.byteOffset + i * 8, p._capnp.depthLimit - 1));
361
+ break;
362
+ } else if (elementSize === ListElementSize.COMPOSITE) {
363
+ const tag = add(-8, c);
364
+ const compositeSize = getStructSize(tag);
365
+ const compositeByteLength = getByteLength(compositeSize);
366
+ contentWords = getOffsetWords(tag);
367
+ c.segment.setWordZero(c.byteOffset - 8);
368
+ for (let i = 0; i < length; i++) for (let j = 0; j < compositeSize.pointerLength; j++) erase(new Pointer(c.segment, c.byteOffset + i * compositeByteLength + j * 8, p._capnp.depthLimit - 1));
369
+ }
370
+ c.segment.fillZeroWords(c.byteOffset, contentWords);
371
+ break;
372
+ }
373
+ case PointerType.OTHER: break;
374
+ default: throw new Error(format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p)));
375
+ }
376
+ erasePointer(p);
377
+ }
378
+ function erasePointer(p) {
379
+ if (getPointerType(p) === PointerType.FAR) {
380
+ const landingPad = followFar(p);
381
+ if (isDoubleFar(p)) landingPad.segment.setWordZero(landingPad.byteOffset + 8);
382
+ landingPad.segment.setWordZero(landingPad.byteOffset);
383
+ }
384
+ p.segment.setWordZero(p.byteOffset);
385
+ }
386
+ function followFar(p) {
387
+ return new Pointer(p.segment.message.getSegment(p.segment.getUint32(p.byteOffset + 4)), (p.segment.getUint32(p.byteOffset) >>> 3) * 8, p._capnp.depthLimit - 1);
388
+ }
389
+ function followFars(p) {
390
+ if (getPointerType(p) === PointerType.FAR) {
391
+ const landingPad = followFar(p);
392
+ if (isDoubleFar(p)) landingPad.byteOffset += 8;
393
+ return landingPad;
394
+ }
395
+ return p;
396
+ }
397
+ function getCapabilityId(p) {
398
+ return p.segment.getUint32(p.byteOffset + 4);
399
+ }
400
+ function isCompositeList(p) {
401
+ return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
402
+ }
403
+ function getContent(p, ignoreCompositeIndex) {
404
+ let c;
405
+ if (isDoubleFar(p)) {
406
+ const landingPad = followFar(p);
407
+ c = new Pointer(p.segment.message.getSegment(getFarSegmentId(landingPad)), getOffsetWords(landingPad) * 8);
408
+ } else {
409
+ const target = followFars(p);
410
+ c = new Pointer(target.segment, target.byteOffset + 8 + getOffsetWords(target) * 8);
411
+ }
412
+ if (isCompositeList(p)) c.byteOffset += 8;
413
+ if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
414
+ c.byteOffset -= 8;
415
+ c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
416
+ }
417
+ return c;
418
+ }
419
+ function getFarSegmentId(p) {
420
+ return p.segment.getUint32(p.byteOffset + 4);
421
+ }
422
+ function getListElementSize(p) {
423
+ return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
424
+ }
425
+ function getListLength(p) {
426
+ return p.segment.getUint32(p.byteOffset + 4) >>> 3;
427
+ }
428
+ function getOffsetWords(p) {
429
+ const o = p.segment.getInt32(p.byteOffset);
430
+ return o & 2 ? o >> 3 : o >> 2;
431
+ }
432
+ function getPointerType(p) {
433
+ return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
434
+ }
435
+ function getStructDataWords(p) {
436
+ return p.segment.getUint16(p.byteOffset + 4);
437
+ }
438
+ function getStructPointerLength(p) {
439
+ return p.segment.getUint16(p.byteOffset + 6);
440
+ }
441
+ function getStructSize(p) {
442
+ return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
443
+ }
444
+ function getTargetCompositeListTag(p) {
445
+ const c = getContent(p);
446
+ c.byteOffset -= 8;
447
+ return c;
448
+ }
449
+ function getTargetCompositeListSize(p) {
450
+ return getStructSize(getTargetCompositeListTag(p));
451
+ }
452
+ function getTargetListElementSize(p) {
453
+ return getListElementSize(followFars(p));
454
+ }
455
+ function getTargetListLength(p) {
456
+ const t = followFars(p);
457
+ if (getListElementSize(t) === ListElementSize.COMPOSITE) return getOffsetWords(getTargetCompositeListTag(p));
458
+ return getListLength(t);
459
+ }
460
+ function getTargetPointerType(p) {
461
+ const t = getPointerType(followFars(p));
462
+ if (t === PointerType.FAR) throw new Error(format(PTR_INVALID_FAR_TARGET, p));
463
+ return t;
464
+ }
465
+ function getTargetStructSize(p) {
466
+ return getStructSize(followFars(p));
467
+ }
468
+ function initPointer(contentSegment, contentOffset, p) {
469
+ if (p.segment !== contentSegment) {
470
+ if (!contentSegment.hasCapacity(8)) {
471
+ const landingPad2 = p.segment.allocate(16);
472
+ setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
473
+ setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
474
+ landingPad2.byteOffset += 8;
475
+ return new PointerAllocationResult(landingPad2, 0);
476
+ }
477
+ const landingPad = contentSegment.allocate(8);
478
+ if (landingPad.segment.id !== contentSegment.id) throw new Error(INVARIANT_UNREACHABLE_CODE);
479
+ setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
480
+ return new PointerAllocationResult(landingPad, (contentOffset - landingPad.byteOffset - 8) / 8);
481
+ }
482
+ return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
483
+ }
484
+ function isDoubleFar(p) {
485
+ return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
486
+ }
487
+ function isNull(p) {
488
+ return p.segment.isWordZero(p.byteOffset);
489
+ }
490
+ function relocateTo(dst, src) {
491
+ const t = followFars(src);
492
+ const lo = t.segment.getUint8(t.byteOffset) & 3;
493
+ const hi = t.segment.getUint32(t.byteOffset + 4);
494
+ erase(dst);
495
+ const res = initPointer(t.segment, t.byteOffset + 8 + getOffsetWords(t) * 8, dst);
496
+ res.pointer.segment.setUint32(res.pointer.byteOffset, lo | res.offsetWords << 2);
497
+ res.pointer.segment.setUint32(res.pointer.byteOffset + 4, hi);
498
+ erasePointer(src);
499
+ }
500
+ function setFarPointer(doubleFar, offsetWords, segmentId, p) {
501
+ const A = PointerType.FAR;
502
+ const B = doubleFar ? 1 : 0;
503
+ const C = offsetWords;
504
+ const D = segmentId;
505
+ p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
506
+ p.segment.setUint32(p.byteOffset + 4, D);
507
+ }
508
+ function setInterfacePointer(capId, p) {
509
+ p.segment.setUint32(p.byteOffset, PointerType.OTHER);
510
+ p.segment.setUint32(p.byteOffset + 4, capId);
511
+ }
512
+ function getInterfacePointer(p) {
513
+ return p.segment.getUint32(p.byteOffset + 4);
514
+ }
515
+ function setListPointer(offsetWords, size, length, p, compositeSize) {
516
+ const A = PointerType.LIST;
517
+ const B = offsetWords;
518
+ const C = size;
519
+ let D = length;
520
+ if (size === ListElementSize.COMPOSITE) {
521
+ if (compositeSize === void 0) throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
522
+ D *= getWordLength(compositeSize);
523
+ }
524
+ p.segment.setUint32(p.byteOffset, A | B << 2);
525
+ p.segment.setUint32(p.byteOffset + 4, C | D << 3);
526
+ }
527
+ function setStructPointer(offsetWords, size, p) {
528
+ const A = PointerType.STRUCT;
529
+ const B = offsetWords;
530
+ const C = getDataWordLength(size);
531
+ const D = size.pointerLength;
532
+ p.segment.setUint32(p.byteOffset, A | B << 2);
533
+ p.segment.setUint16(p.byteOffset + 4, C);
534
+ p.segment.setUint16(p.byteOffset + 6, D);
535
+ }
536
+ function validate(pointerType, p, elementSize) {
537
+ if (isNull(p)) return;
538
+ const t = followFars(p);
539
+ if ((t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK) !== pointerType) throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
540
+ if (elementSize !== void 0) {
541
+ if ((t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK) !== elementSize) throw new Error(format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize]));
542
+ }
543
+ }
544
+ function copyFromInterface(src, dst) {
545
+ const srcCapId = getInterfacePointer(src);
546
+ if (srcCapId < 0) return;
547
+ const srcCapTable = src.segment.message._capnp.capTable;
548
+ if (!srcCapTable) return;
549
+ const client = srcCapTable[srcCapId];
550
+ if (!client) return;
551
+ setInterfacePointer(dst.segment.message.addCap(client), dst);
552
+ }
553
+ function copyFromList(src, dst) {
554
+ if (dst._capnp.depthLimit <= 0) throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);
555
+ const srcContent = getContent(src);
556
+ const srcElementSize = getTargetListElementSize(src);
557
+ const srcLength = getTargetListLength(src);
558
+ let srcCompositeSize;
559
+ let srcStructByteLength;
560
+ let dstContent;
561
+ if (srcElementSize === ListElementSize.POINTER) {
562
+ dstContent = dst.segment.allocate(srcLength << 3);
563
+ for (let i = 0; i < srcLength; i++) copyFrom(new Pointer(srcContent.segment, srcContent.byteOffset + (i << 3), src._capnp.depthLimit - 1), new Pointer(dstContent.segment, dstContent.byteOffset + (i << 3), dst._capnp.depthLimit - 1));
564
+ } else if (srcElementSize === ListElementSize.COMPOSITE) {
565
+ srcCompositeSize = padToWord(getTargetCompositeListSize(src));
566
+ srcStructByteLength = getByteLength(srcCompositeSize);
567
+ dstContent = dst.segment.allocate(getByteLength(srcCompositeSize) * srcLength + 8);
568
+ dstContent.segment.copyWord(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset - 8);
569
+ if (srcCompositeSize.dataByteLength > 0) {
570
+ const wordLength = getWordLength(srcCompositeSize) * srcLength;
571
+ dstContent.segment.copyWords(dstContent.byteOffset + 8, srcContent.segment, srcContent.byteOffset, wordLength);
572
+ }
573
+ for (let i = 0; i < srcLength; i++) for (let j = 0; j < srcCompositeSize.pointerLength; j++) {
574
+ const offset = i * srcStructByteLength + srcCompositeSize.dataByteLength + (j << 3);
575
+ copyFrom(new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1), new Pointer(dstContent.segment, dstContent.byteOffset + offset + 8, dst._capnp.depthLimit - 1));
576
+ }
577
+ } else {
578
+ const byteLength = padToWord$1(srcElementSize === ListElementSize.BIT ? srcLength + 7 >>> 3 : getListElementByteLength(srcElementSize) * srcLength);
579
+ const wordLength = byteLength >>> 3;
580
+ dstContent = dst.segment.allocate(byteLength);
581
+ dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, wordLength);
582
+ }
583
+ const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);
584
+ setListPointer(res.offsetWords, srcElementSize, srcLength, res.pointer, srcCompositeSize);
585
+ }
586
+ function copyFromStruct(src, dst) {
587
+ if (dst._capnp.depthLimit <= 0) throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);
588
+ const srcContent = getContent(src);
589
+ const srcSize = getTargetStructSize(src);
590
+ const srcDataWordLength = getDataWordLength(srcSize);
591
+ const dstContent = dst.segment.allocate(getByteLength(srcSize));
592
+ dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, srcDataWordLength);
593
+ for (let i = 0; i < srcSize.pointerLength; i++) {
594
+ const offset = srcSize.dataByteLength + i * 8;
595
+ copyFrom(new Pointer(srcContent.segment, srcContent.byteOffset + offset, src._capnp.depthLimit - 1), new Pointer(dstContent.segment, dstContent.byteOffset + offset, dst._capnp.depthLimit - 1));
596
+ }
597
+ if (dst._capnp.compositeList) return;
598
+ const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);
599
+ setStructPointer(res.offsetWords, srcSize, res.pointer);
600
+ }
601
+ function trackPointerAllocation(message, p) {
602
+ message._capnp.traversalLimit -= 8;
603
+ if (message._capnp.traversalLimit <= 0) throw new Error(format(PTR_TRAVERSAL_LIMIT_EXCEEDED, p));
604
+ }
605
+ var PointerAllocationResult = class {
606
+ constructor(pointer, offsetWords) {
607
+ this.pointer = pointer;
608
+ this.offsetWords = offsetWords;
609
+ }
610
+ };
611
+ var PointerType = /* @__PURE__ */ ((PointerType2) => {
612
+ PointerType2[PointerType2["STRUCT"] = 0] = "STRUCT";
613
+ PointerType2[PointerType2["LIST"] = 1] = "LIST";
614
+ PointerType2[PointerType2["FAR"] = 2] = "FAR";
615
+ PointerType2[PointerType2["OTHER"] = 3] = "OTHER";
616
+ return PointerType2;
617
+ })(PointerType || {});
618
+ var Pointer = class {
619
+ static _capnp = { displayName: "Pointer" };
620
+ _capnp;
621
+ /** Offset, in bytes, from the start of the segment to the beginning of this pointer. */
622
+ byteOffset;
623
+ /**
624
+ * The starting segment for this pointer's data. In the case of a far pointer, the actual content this pointer is
625
+ * referencing will be in another segment within the same message.
626
+ */
627
+ segment;
628
+ constructor(segment, byteOffset, depthLimit = MAX_DEPTH) {
629
+ this._capnp = {
630
+ compositeList: false,
631
+ depthLimit
632
+ };
633
+ this.segment = segment;
634
+ this.byteOffset = byteOffset;
635
+ if (depthLimit < 1) throw new Error(format(PTR_DEPTH_LIMIT_EXCEEDED, this));
636
+ trackPointerAllocation(segment.message, this);
637
+ if (byteOffset < 0 || byteOffset > segment.byteLength) throw new Error(format(PTR_OFFSET_OUT_OF_BOUNDS, byteOffset));
638
+ }
639
+ [Symbol.toStringTag]() {
640
+ return format("Pointer_%d", this.segment.id);
641
+ }
642
+ toString() {
643
+ return format("->%d@%a%s", this.segment.id, this.byteOffset, dump$1(this));
644
+ }
645
+ };
646
+ var List = class List extends Pointer {
647
+ static _capnp = {
648
+ displayName: "List<Generic>",
649
+ size: ListElementSize.VOID
650
+ };
651
+ constructor(segment, byteOffset, depthLimit) {
652
+ super(segment, byteOffset, depthLimit);
653
+ return new Proxy(this, List.#proxyHandler);
654
+ }
655
+ static #proxyHandler = { get(target, prop, receiver) {
656
+ const val = Reflect.get(target, prop, receiver);
657
+ if (val !== void 0) return val;
658
+ if (typeof prop === "string") return target.get(+prop);
659
+ } };
660
+ get length() {
661
+ return getTargetListLength(this);
662
+ }
663
+ toArray() {
664
+ const { length } = this;
665
+ const res = Array.from({ length });
666
+ for (let i = 0; i < length; i++) res[i] = this.at(i);
667
+ return res;
668
+ }
669
+ get(_index) {
670
+ throw new TypeError("Cannot get from a generic list.");
671
+ }
672
+ set(_index, _value) {
673
+ throw new TypeError("Cannot set on a generic list.");
674
+ }
675
+ at(index) {
676
+ return this.get(index < 0 ? this.length + index : index);
677
+ }
678
+ concat(other) {
679
+ const { length } = this;
680
+ const otherLength = other.length;
681
+ const res = Array.from({ length: length + otherLength });
682
+ for (let i = 0; i < length; i++) res[i] = this.at(i);
683
+ for (let i = 0; i < otherLength; i++) res[i + length] = other.at(i);
684
+ return res;
685
+ }
686
+ some(cb, _this) {
687
+ for (let i = 0; i < this.length; i++) if (cb.call(_this, this.at(i), i, this)) return true;
688
+ return false;
689
+ }
690
+ filter(cb, _this) {
691
+ const res = [];
692
+ for (let i = 0; i < this.length; i++) {
693
+ const value = this.at(i);
694
+ if (cb.call(_this, value, i, this)) res.push(value);
695
+ }
696
+ return res;
697
+ }
698
+ find(cb, _this) {
699
+ for (let i = 0; i < this.length; i++) {
700
+ const value = this.at(i);
701
+ if (cb.call(_this, value, i, this)) return value;
702
+ }
703
+ }
704
+ findIndex(cb, _this) {
705
+ for (let i = 0; i < this.length; i++) {
706
+ const value = this.at(i);
707
+ if (cb.call(_this, value, i, this)) return i;
708
+ }
709
+ return -1;
710
+ }
711
+ forEach(cb, _this) {
712
+ for (let i = 0; i < this.length; i++) cb.call(_this, this.at(i), i, this);
713
+ }
714
+ map(cb, _this) {
715
+ const { length } = this;
716
+ const res = Array.from({ length });
717
+ for (let i = 0; i < length; i++) res[i] = cb.call(_this, this.at(i), i, this);
718
+ return res;
719
+ }
720
+ flatMap(cb, _this) {
721
+ const res = [];
722
+ for (let i = 0; i < this.length; i++) {
723
+ const r = cb.call(_this, this.at(i), i, this);
724
+ res.push(...Array.isArray(r) ? r : [r]);
725
+ }
726
+ return res;
727
+ }
728
+ every(cb, _this) {
729
+ for (let i = 0; i < this.length; i++) if (!cb.call(_this, this.at(i), i, this)) return false;
730
+ return true;
731
+ }
732
+ reduce(cb, initialValue) {
733
+ let i = 0;
734
+ let res;
735
+ if (initialValue === void 0) {
736
+ res = this.at(0);
737
+ i++;
738
+ } else res = initialValue;
739
+ for (; i < this.length; i++) res = cb(res, this.at(i), i, this);
740
+ return res;
741
+ }
742
+ reduceRight(cb, initialValue) {
743
+ let i = this.length - 1;
744
+ let res;
745
+ if (initialValue === void 0) {
746
+ res = this.at(i);
747
+ i--;
748
+ } else res = initialValue;
749
+ for (; i >= 0; i--) res = cb(res, this.at(i), i, this);
750
+ return res;
751
+ }
752
+ slice(start = 0, end) {
753
+ const length = end ? Math.min(this.length, end) : this.length;
754
+ const res = Array.from({ length: length - start });
755
+ for (let i = start; i < length; i++) res[i] = this.at(i);
756
+ return res;
757
+ }
758
+ join(separator) {
759
+ return this.toArray().join(separator);
760
+ }
761
+ toReversed() {
762
+ return this.toArray().reverse();
763
+ }
764
+ toSorted(compareFn) {
765
+ return this.toArray().sort(compareFn);
766
+ }
767
+ toSpliced(start, deleteCount, ...items) {
768
+ return this.toArray().splice(start, deleteCount, ...items);
769
+ }
770
+ fill(value, start, end) {
771
+ const { length } = this;
772
+ const s = Math.max(start ?? 0, 0);
773
+ const e = Math.min(end ?? length, length);
774
+ for (let i = s; i < e; i++) this.set(i, value);
775
+ return this;
776
+ }
777
+ copyWithin(target, start, end) {
778
+ const { length } = this;
779
+ const e = end ?? length;
780
+ const s = start < 0 ? Math.max(length + start, 0) : start;
781
+ const t = target < 0 ? Math.max(length + target, 0) : target;
782
+ const len = Math.min(e - s, length - t);
783
+ for (let i = 0; i < len; i++) this.set(t + i, this.at(s + i));
784
+ return this;
785
+ }
786
+ keys() {
787
+ return Array.from({ length: this.length }, (_, i) => i)[Symbol.iterator]();
788
+ }
789
+ values() {
790
+ return this.toArray().values();
791
+ }
792
+ entries() {
793
+ return this.toArray().entries();
794
+ }
795
+ flat(depth) {
796
+ return this.toArray().flat(depth);
797
+ }
798
+ with(index, value) {
799
+ return this.toArray().with(index, value);
800
+ }
801
+ includes(_searchElement, _fromIndex) {
802
+ throw new Error(LIST_NO_SEARCH);
803
+ }
804
+ findLast(_cb, _thisArg) {
805
+ throw new Error(LIST_NO_SEARCH);
806
+ }
807
+ findLastIndex(_cb, _t) {
808
+ throw new Error(LIST_NO_SEARCH);
809
+ }
810
+ indexOf(_searchElement, _fromIndex) {
811
+ throw new Error(LIST_NO_SEARCH);
812
+ }
813
+ lastIndexOf(_searchElement, _fromIndex) {
814
+ throw new Error(LIST_NO_SEARCH);
815
+ }
816
+ pop() {
817
+ throw new Error(LIST_NO_MUTABLE);
818
+ }
819
+ push(..._items) {
820
+ throw new Error(LIST_NO_MUTABLE);
821
+ }
822
+ reverse() {
823
+ throw new Error(LIST_NO_MUTABLE);
824
+ }
825
+ shift() {
826
+ throw new Error(LIST_NO_MUTABLE);
827
+ }
828
+ unshift(..._items) {
829
+ throw new Error(LIST_NO_MUTABLE);
830
+ }
831
+ splice(_start, _deleteCount, ..._rest) {
832
+ throw new Error(LIST_NO_MUTABLE);
833
+ }
834
+ sort(_fn) {
835
+ throw new Error(LIST_NO_MUTABLE);
836
+ }
837
+ get [Symbol.unscopables]() {
838
+ return Array.prototype[Symbol.unscopables];
839
+ }
840
+ [Symbol.iterator]() {
841
+ return this.values();
842
+ }
843
+ toJSON() {
844
+ return this.toArray();
845
+ }
846
+ toString() {
847
+ return this.join(",");
848
+ }
849
+ toLocaleString(_locales, _options) {
850
+ return this.toString();
851
+ }
852
+ [Symbol.toStringTag]() {
853
+ return "[object Array]";
854
+ }
855
+ static [Symbol.toStringTag]() {
856
+ return this._capnp.displayName;
857
+ }
858
+ };
859
+ function initList$1(elementSize, length, list, compositeSize) {
860
+ let c;
861
+ switch (elementSize) {
862
+ case ListElementSize.BIT:
863
+ c = list.segment.allocate(Math.ceil(length / 8));
864
+ break;
865
+ case ListElementSize.BYTE:
866
+ case ListElementSize.BYTE_2:
867
+ case ListElementSize.BYTE_4:
868
+ case ListElementSize.BYTE_8:
869
+ case ListElementSize.POINTER:
870
+ c = list.segment.allocate(length * getListElementByteLength(elementSize));
871
+ break;
872
+ case ListElementSize.COMPOSITE: {
873
+ if (compositeSize === void 0) throw new Error(format(PTR_COMPOSITE_SIZE_UNDEFINED));
874
+ compositeSize = padToWord(compositeSize);
875
+ const byteLength = getByteLength(compositeSize) * length;
876
+ c = list.segment.allocate(byteLength + 8);
877
+ setStructPointer(length, compositeSize, c);
878
+ break;
879
+ }
880
+ case ListElementSize.VOID:
881
+ setListPointer(0, elementSize, length, list);
882
+ return;
883
+ default: throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
884
+ }
885
+ const res = initPointer(c.segment, c.byteOffset, list);
886
+ setListPointer(res.offsetWords, elementSize, length, res.pointer, compositeSize);
887
+ }
888
+ var Data = class extends List {
889
+ static fromPointer(pointer) {
890
+ validate(PointerType.LIST, pointer, ListElementSize.BYTE);
891
+ return this._fromPointerUnchecked(pointer);
892
+ }
893
+ static _fromPointerUnchecked(pointer) {
894
+ return new this(pointer.segment, pointer.byteOffset, pointer._capnp.depthLimit);
895
+ }
896
+ /**
897
+ * Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the
898
+ * remaining bytes will be zeroed out. Extra bytes in `src` are ignored.
899
+ *
900
+ * @param src The source buffer.
901
+ */
902
+ copyBuffer(src) {
903
+ const c = getContent(this);
904
+ const dstLength = this.length;
905
+ const srcLength = src.byteLength;
906
+ const i = src instanceof ArrayBuffer ? new Uint8Array(src) : new Uint8Array(src.buffer, src.byteOffset, Math.min(dstLength, srcLength));
907
+ const o = new Uint8Array(c.segment.buffer, c.byteOffset, this.length);
908
+ o.set(i);
909
+ if (dstLength > srcLength) o.fill(0, srcLength, dstLength);
910
+ }
911
+ /**
912
+ * Read a byte from the specified offset.
913
+ *
914
+ * @param byteOffset The byte offset to read.
915
+ * @returns The byte value.
916
+ */
917
+ get(byteOffset) {
918
+ const c = getContent(this);
919
+ return c.segment.getUint8(c.byteOffset + byteOffset);
920
+ }
921
+ /**
922
+ * Write a byte at the specified offset.
923
+ *
924
+ * @param byteOffset The byte offset to set.
925
+ * @param value The byte value to set.
926
+ */
927
+ set(byteOffset, value) {
928
+ const c = getContent(this);
929
+ c.segment.setUint8(c.byteOffset + byteOffset, value);
930
+ }
931
+ /**
932
+ * Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer.
933
+ *
934
+ * To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`.
935
+ *
936
+ * @returns A copy of this data buffer.
937
+ */
938
+ toArrayBuffer() {
939
+ const c = getContent(this);
940
+ return c.segment.buffer.slice(c.byteOffset, c.byteOffset + this.length);
941
+ }
942
+ /**
943
+ * Convert this Data pointer to a DataView representing the pointer's contents.
944
+ *
945
+ * WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the
946
+ * DataView or else BAD THINGS.
947
+ *
948
+ * @returns A live reference to the underlying buffer.
949
+ */
950
+ toDataView() {
951
+ const c = getContent(this);
952
+ return new DataView(c.segment.buffer, c.byteOffset, this.length);
953
+ }
954
+ [Symbol.toStringTag]() {
955
+ return `Data_${super.toString()}`;
956
+ }
957
+ /**
958
+ * Convert this Data pointer to a Uint8Array representing the pointer's contents.
959
+ *
960
+ * WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the
961
+ * Uint8Array or else BAD THINGS.
962
+ *
963
+ * @returns A live reference to the underlying buffer.
964
+ */
965
+ toUint8Array() {
966
+ const c = getContent(this);
967
+ return new Uint8Array(c.segment.buffer, c.byteOffset, this.length);
968
+ }
969
+ };
970
+ const textEncoder = new TextEncoder();
971
+ const textDecoder = new TextDecoder();
972
+ var Text = class extends List {
973
+ static fromPointer(pointer) {
974
+ validate(PointerType.LIST, pointer, ListElementSize.BYTE);
975
+ return textFromPointerUnchecked(pointer);
976
+ }
977
+ /**
978
+ * Read a utf-8 encoded string value from this pointer.
979
+ *
980
+ * @param index The index at which to start reading; defaults to zero.
981
+ * @returns The string value.
982
+ */
983
+ get(index = 0) {
984
+ if (isNull(this)) return "";
985
+ const c = getContent(this);
986
+ return textDecoder.decode(new Uint8Array(c.segment.buffer, c.byteOffset + index, this.length - index));
987
+ }
988
+ /**
989
+ * Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte.
990
+ *
991
+ * @returns The number of bytes allocated for the text.
992
+ */
993
+ get length() {
994
+ return super.length - 1;
995
+ }
996
+ /**
997
+ * Write a utf-8 encoded string value starting at the specified index.
998
+ *
999
+ * @param index The index at which to start copying the string. Note that if this is not zero the bytes
1000
+ * before `index` will be left as-is. All bytes after `index` will be overwritten.
1001
+ * @param value The string value to set.
1002
+ */
1003
+ set(index, value) {
1004
+ const src = textEncoder.encode(value);
1005
+ const dstLength = src.byteLength + index;
1006
+ let c;
1007
+ let original;
1008
+ if (!isNull(this)) {
1009
+ c = getContent(this);
1010
+ const originalLength = Math.min(this.length, index);
1011
+ original = new Uint8Array(c.segment.buffer.slice(c.byteOffset, c.byteOffset + originalLength));
1012
+ erase(this);
1013
+ }
1014
+ initList$1(ListElementSize.BYTE, dstLength + 1, this);
1015
+ c = getContent(this);
1016
+ const dst = new Uint8Array(c.segment.buffer, c.byteOffset, dstLength);
1017
+ if (original) dst.set(original);
1018
+ dst.set(src, index);
1019
+ }
1020
+ toString() {
1021
+ return this.get();
1022
+ }
1023
+ toJSON() {
1024
+ return this.get();
1025
+ }
1026
+ [Symbol.toPrimitive]() {
1027
+ return this.get();
1028
+ }
1029
+ [Symbol.toStringTag]() {
1030
+ return `Text_${super.toString()}`;
1031
+ }
1032
+ };
1033
+ function textFromPointerUnchecked(pointer) {
1034
+ return new Text(pointer.segment, pointer.byteOffset, pointer._capnp.depthLimit);
1035
+ }
1036
+ var Struct = class extends Pointer {
1037
+ static _capnp = { displayName: "Struct" };
1038
+ /**
1039
+ * Create a new pointer to a struct.
1040
+ *
1041
+ * @param segment The segment the pointer resides in.
1042
+ * @param byteOffset The offset from the beginning of the segment to the beginning of the pointer data.
1043
+ * @param depthLimit The nesting depth limit for this object.
1044
+ * @param compositeIndex If set, then this pointer is actually a reference to a composite list
1045
+ * (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within
1046
+ * the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when
1047
+ * the list pointer is initialized.
1048
+ */
1049
+ constructor(segment, byteOffset, depthLimit = MAX_DEPTH, compositeIndex) {
1050
+ super(segment, byteOffset, depthLimit);
1051
+ this._capnp.compositeIndex = compositeIndex;
1052
+ this._capnp.compositeList = compositeIndex !== void 0;
1053
+ }
1054
+ static [Symbol.toStringTag]() {
1055
+ return this._capnp.displayName;
1056
+ }
1057
+ [Symbol.toStringTag]() {
1058
+ return `Struct_${super.toString()}${this._capnp.compositeIndex === void 0 ? "" : `,ci:${this._capnp.compositeIndex}`} > ${getContent(this).toString()}`;
1059
+ }
1060
+ };
1061
+ var AnyStruct = class extends Struct {
1062
+ static _capnp = {
1063
+ displayName: "AnyStruct",
1064
+ id: "0",
1065
+ size: new ObjectSize(0, 0)
1066
+ };
1067
+ };
1068
+ var FixedAnswer = class {
1069
+ struct() {
1070
+ return Promise.resolve(this.structSync());
1071
+ }
1072
+ };
1073
+ var ErrorAnswer = class extends FixedAnswer {
1074
+ constructor(err) {
1075
+ super();
1076
+ this.err = err;
1077
+ }
1078
+ structSync() {
1079
+ throw this.err;
1080
+ }
1081
+ pipelineCall(_transform, _call) {
1082
+ return this;
1083
+ }
1084
+ pipelineClose(_transform) {
1085
+ throw this.err;
1086
+ }
1087
+ };
1088
+ var ErrorClient = class {
1089
+ constructor(err) {
1090
+ this.err = err;
1091
+ }
1092
+ call(_call) {
1093
+ return new ErrorAnswer(this.err);
1094
+ }
1095
+ close() {
1096
+ throw this.err;
1097
+ }
1098
+ };
1099
+ function clientOrNull(client) {
1100
+ return client ?? new ErrorClient(new Error(RPC_NULL_CLIENT));
1101
+ }
1102
+ const TMP_WORD = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
1103
+ function initStruct(size, s) {
1104
+ if (s._capnp.compositeIndex !== void 0) throw new Error(format(PTR_INIT_COMPOSITE_STRUCT, s));
1105
+ erase(s);
1106
+ const c = s.segment.allocate(getByteLength(size));
1107
+ const res = initPointer(c.segment, c.byteOffset, s);
1108
+ setStructPointer(res.offsetWords, size, res.pointer);
1109
+ }
1110
+ function initStructAt(index, StructClass, p) {
1111
+ const s = getPointerAs(index, StructClass, p);
1112
+ initStruct(StructClass._capnp.size, s);
1113
+ return s;
1114
+ }
1115
+ function checkPointerBounds(index, s) {
1116
+ const { pointerLength } = getSize(s);
1117
+ if (index < 0 || index >= pointerLength) throw new Error(format(PTR_STRUCT_POINTER_OUT_OF_BOUNDS, s, index, pointerLength));
1118
+ }
1119
+ function getInterfaceClientOrNullAt(index, s) {
1120
+ return getInterfaceClientOrNull(getPointer(index, s));
1121
+ }
1122
+ function getInterfaceClientOrNull(p) {
1123
+ let client = null;
1124
+ const capId = getInterfacePointer(p);
1125
+ const { capTable } = p.segment.message._capnp;
1126
+ if (capTable && capId >= 0 && capId < capTable.length) client = capTable[capId];
1127
+ return clientOrNull(client);
1128
+ }
1129
+ function resize(dstSize, s) {
1130
+ const srcSize = getSize(s);
1131
+ const srcContent = getContent(s);
1132
+ const dstContent = s.segment.allocate(getByteLength(dstSize));
1133
+ dstContent.segment.copyWords(dstContent.byteOffset, srcContent.segment, srcContent.byteOffset, Math.min(getDataWordLength(srcSize), getDataWordLength(dstSize)));
1134
+ const res = initPointer(dstContent.segment, dstContent.byteOffset, s);
1135
+ setStructPointer(res.offsetWords, dstSize, res.pointer);
1136
+ for (let i = 0; i < Math.min(srcSize.pointerLength, dstSize.pointerLength); i++) {
1137
+ const srcPtr = new Pointer(srcContent.segment, srcContent.byteOffset + srcSize.dataByteLength + i * 8);
1138
+ if (isNull(srcPtr)) continue;
1139
+ const srcPtrTarget = followFars(srcPtr);
1140
+ const srcPtrContent = getContent(srcPtr);
1141
+ const dstPtr = new Pointer(dstContent.segment, dstContent.byteOffset + dstSize.dataByteLength + i * 8);
1142
+ if (getTargetPointerType(srcPtr) === PointerType.LIST && getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE) srcPtrContent.byteOffset -= 8;
1143
+ const r = initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr);
1144
+ const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 3;
1145
+ const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4);
1146
+ r.pointer.segment.setUint32(r.pointer.byteOffset, a | r.offsetWords << 2);
1147
+ r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b);
1148
+ }
1149
+ srcContent.segment.fillZeroWords(srcContent.byteOffset, getWordLength(srcSize));
1150
+ }
1151
+ function getAs(StructClass, s) {
1152
+ return new StructClass(s.segment, s.byteOffset, s._capnp.depthLimit, s._capnp.compositeIndex);
1153
+ }
1154
+ function getBit(bitOffset, s, defaultMask) {
1155
+ const byteOffset = Math.floor(bitOffset / 8);
1156
+ const bitMask = 1 << bitOffset % 8;
1157
+ checkDataBounds(byteOffset, 1, s);
1158
+ const ds = getDataSection(s);
1159
+ const v = ds.segment.getUint8(ds.byteOffset + byteOffset);
1160
+ if (defaultMask === void 0) return (v & bitMask) !== 0;
1161
+ return ((v ^ defaultMask.getUint8(0)) & bitMask) !== 0;
1162
+ }
1163
+ function getData(index, s, defaultValue) {
1164
+ checkPointerBounds(index, s);
1165
+ const ps = getPointerSection(s);
1166
+ ps.byteOffset += index * 8;
1167
+ const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1168
+ if (isNull(l)) if (defaultValue) copyFrom(defaultValue, l);
1169
+ else initList$1(ListElementSize.BYTE, 0, l);
1170
+ return l;
1171
+ }
1172
+ function getDataSection(s) {
1173
+ return getContent(s);
1174
+ }
1175
+ function getFloat32(byteOffset, s, defaultMask) {
1176
+ checkDataBounds(byteOffset, 4, s);
1177
+ const ds = getDataSection(s);
1178
+ if (defaultMask === void 0) return ds.segment.getFloat32(ds.byteOffset + byteOffset);
1179
+ const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
1180
+ TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN);
1181
+ return TMP_WORD.getFloat32(0, NATIVE_LITTLE_ENDIAN);
1182
+ }
1183
+ function getFloat64(byteOffset, s, defaultMask) {
1184
+ checkDataBounds(byteOffset, 8, s);
1185
+ const ds = getDataSection(s);
1186
+ if (defaultMask !== void 0) {
1187
+ const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
1188
+ const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
1189
+ TMP_WORD.setUint32(0, lo, NATIVE_LITTLE_ENDIAN);
1190
+ TMP_WORD.setUint32(4, hi, NATIVE_LITTLE_ENDIAN);
1191
+ return TMP_WORD.getFloat64(0, NATIVE_LITTLE_ENDIAN);
1192
+ }
1193
+ return ds.segment.getFloat64(ds.byteOffset + byteOffset);
1194
+ }
1195
+ function getInt16(byteOffset, s, defaultMask) {
1196
+ checkDataBounds(byteOffset, 2, s);
1197
+ const ds = getDataSection(s);
1198
+ if (defaultMask === void 0) return ds.segment.getInt16(ds.byteOffset + byteOffset);
1199
+ const v = ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
1200
+ TMP_WORD.setUint16(0, v, NATIVE_LITTLE_ENDIAN);
1201
+ return TMP_WORD.getInt16(0, NATIVE_LITTLE_ENDIAN);
1202
+ }
1203
+ function getInt32(byteOffset, s, defaultMask) {
1204
+ checkDataBounds(byteOffset, 4, s);
1205
+ const ds = getDataSection(s);
1206
+ if (defaultMask === void 0) return ds.segment.getInt32(ds.byteOffset + byteOffset);
1207
+ const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
1208
+ TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN);
1209
+ return TMP_WORD.getInt32(0, NATIVE_LITTLE_ENDIAN);
1210
+ }
1211
+ function getInt64(byteOffset, s, defaultMask) {
1212
+ checkDataBounds(byteOffset, 8, s);
1213
+ const ds = getDataSection(s);
1214
+ if (defaultMask !== void 0) {
1215
+ const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
1216
+ const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
1217
+ TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, lo, NATIVE_LITTLE_ENDIAN);
1218
+ TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, hi, NATIVE_LITTLE_ENDIAN);
1219
+ return TMP_WORD.getBigInt64(0, NATIVE_LITTLE_ENDIAN);
1220
+ }
1221
+ return ds.segment.getInt64(ds.byteOffset + byteOffset);
1222
+ }
1223
+ function getInt8(byteOffset, s, defaultMask) {
1224
+ checkDataBounds(byteOffset, 1, s);
1225
+ const ds = getDataSection(s);
1226
+ if (defaultMask === void 0) return ds.segment.getInt8(ds.byteOffset + byteOffset);
1227
+ const v = ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0);
1228
+ TMP_WORD.setUint8(0, v);
1229
+ return TMP_WORD.getInt8(0);
1230
+ }
1231
+ function getList(index, ListClass, s, defaultValue) {
1232
+ checkPointerBounds(index, s);
1233
+ const ps = getPointerSection(s);
1234
+ ps.byteOffset += index * 8;
1235
+ const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1236
+ if (isNull(l)) if (defaultValue) copyFrom(defaultValue, l);
1237
+ else initList$1(ListClass._capnp.size, 0, l, ListClass._capnp.compositeSize);
1238
+ else if (ListClass._capnp.compositeSize !== void 0) {
1239
+ const srcSize = getTargetCompositeListSize(l);
1240
+ const dstSize = ListClass._capnp.compositeSize;
1241
+ if (dstSize.dataByteLength > srcSize.dataByteLength || dstSize.pointerLength > srcSize.pointerLength) {
1242
+ const srcContent = getContent(l);
1243
+ const srcLength = getTargetListLength(l);
1244
+ const dstContent = l.segment.allocate(getByteLength(dstSize) * srcLength + 8);
1245
+ const res = initPointer(dstContent.segment, dstContent.byteOffset, l);
1246
+ setListPointer(res.offsetWords, ListClass._capnp.size, srcLength, res.pointer, dstSize);
1247
+ setStructPointer(srcLength, dstSize, dstContent);
1248
+ dstContent.byteOffset += 8;
1249
+ for (let i = 0; i < srcLength; i++) {
1250
+ const srcElementOffset = srcContent.byteOffset + i * getByteLength(srcSize);
1251
+ const dstElementOffset = dstContent.byteOffset + i * getByteLength(dstSize);
1252
+ dstContent.segment.copyWords(dstElementOffset, srcContent.segment, srcElementOffset, getWordLength(srcSize));
1253
+ for (let j = 0; j < srcSize.pointerLength; j++) {
1254
+ const srcPtr = new Pointer(srcContent.segment, srcElementOffset + srcSize.dataByteLength + j * 8);
1255
+ const dstPtr = new Pointer(dstContent.segment, dstElementOffset + dstSize.dataByteLength + j * 8);
1256
+ const srcPtrTarget = followFars(srcPtr);
1257
+ const srcPtrContent = getContent(srcPtr);
1258
+ if (getTargetPointerType(srcPtr) === PointerType.LIST && getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE) srcPtrContent.byteOffset -= 8;
1259
+ const r = initPointer(srcPtrContent.segment, srcPtrContent.byteOffset, dstPtr);
1260
+ const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 3;
1261
+ const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4);
1262
+ r.pointer.segment.setUint32(r.pointer.byteOffset, a | r.offsetWords << 2);
1263
+ r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b);
1264
+ }
1265
+ }
1266
+ srcContent.segment.fillZeroWords(srcContent.byteOffset, getWordLength(srcSize) * srcLength);
1267
+ }
1268
+ }
1269
+ return l;
1270
+ }
1271
+ function getPointer(index, s) {
1272
+ checkPointerBounds(index, s);
1273
+ const ps = getPointerSection(s);
1274
+ ps.byteOffset += index * 8;
1275
+ return new Pointer(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1276
+ }
1277
+ function getPointerAs(index, PointerClass, s) {
1278
+ checkPointerBounds(index, s);
1279
+ const ps = getPointerSection(s);
1280
+ ps.byteOffset += index * 8;
1281
+ return new PointerClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1282
+ }
1283
+ function getPointerSection(s) {
1284
+ const ps = getContent(s);
1285
+ ps.byteOffset += padToWord$1(getSize(s).dataByteLength);
1286
+ return ps;
1287
+ }
1288
+ function getSize(s) {
1289
+ if (s._capnp.compositeIndex !== void 0) {
1290
+ const c = getContent(s, true);
1291
+ c.byteOffset -= 8;
1292
+ return getStructSize(c);
1293
+ }
1294
+ return getTargetStructSize(s);
1295
+ }
1296
+ function getStruct(index, StructClass, s, defaultValue) {
1297
+ const t = getPointerAs(index, StructClass, s);
1298
+ if (isNull(t)) if (defaultValue) copyFrom(defaultValue, t);
1299
+ else initStruct(StructClass._capnp.size, t);
1300
+ else {
1301
+ validate(PointerType.STRUCT, t);
1302
+ const ts = getTargetStructSize(t);
1303
+ if (ts.dataByteLength < StructClass._capnp.size.dataByteLength || ts.pointerLength < StructClass._capnp.size.pointerLength) resize(StructClass._capnp.size, t);
1304
+ }
1305
+ return t;
1306
+ }
1307
+ function getText(index, s, defaultValue) {
1308
+ const t = Text.fromPointer(getPointer(index, s));
1309
+ if (isNull(t) && defaultValue) t.set(0, defaultValue);
1310
+ return t.get(0);
1311
+ }
1312
+ function getUint16(byteOffset, s, defaultMask) {
1313
+ checkDataBounds(byteOffset, 2, s);
1314
+ const ds = getDataSection(s);
1315
+ if (defaultMask === void 0) return ds.segment.getUint16(ds.byteOffset + byteOffset);
1316
+ return ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
1317
+ }
1318
+ function getUint32(byteOffset, s, defaultMask) {
1319
+ checkDataBounds(byteOffset, 4, s);
1320
+ const ds = getDataSection(s);
1321
+ if (defaultMask === void 0) return ds.segment.getUint32(ds.byteOffset + byteOffset);
1322
+ return ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
1323
+ }
1324
+ function getUint64(byteOffset, s, defaultMask) {
1325
+ checkDataBounds(byteOffset, 8, s);
1326
+ const ds = getDataSection(s);
1327
+ if (defaultMask !== void 0) {
1328
+ const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
1329
+ const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
1330
+ TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, lo, NATIVE_LITTLE_ENDIAN);
1331
+ TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, hi, NATIVE_LITTLE_ENDIAN);
1332
+ return TMP_WORD.getBigUint64(0, NATIVE_LITTLE_ENDIAN);
1333
+ }
1334
+ return ds.segment.getUint64(ds.byteOffset + byteOffset);
1335
+ }
1336
+ function getUint8(byteOffset, s, defaultMask) {
1337
+ checkDataBounds(byteOffset, 1, s);
1338
+ const ds = getDataSection(s);
1339
+ if (defaultMask === void 0) return ds.segment.getUint8(ds.byteOffset + byteOffset);
1340
+ return ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0);
1341
+ }
1342
+ function initData(index, length, s) {
1343
+ checkPointerBounds(index, s);
1344
+ const ps = getPointerSection(s);
1345
+ ps.byteOffset += index * 8;
1346
+ const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1347
+ erase(l);
1348
+ initList$1(ListElementSize.BYTE, length, l);
1349
+ return l;
1350
+ }
1351
+ function initList(index, ListClass, length, s) {
1352
+ checkPointerBounds(index, s);
1353
+ const ps = getPointerSection(s);
1354
+ ps.byteOffset += index * 8;
1355
+ const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
1356
+ erase(l);
1357
+ initList$1(ListClass._capnp.size, length, l, ListClass._capnp.compositeSize);
1358
+ return l;
1359
+ }
1360
+ function setBit(bitOffset, value, s, defaultMask) {
1361
+ const byteOffset = Math.floor(bitOffset / 8);
1362
+ const bitMask = 1 << bitOffset % 8;
1363
+ checkDataBounds(byteOffset, 1, s);
1364
+ const ds = getDataSection(s);
1365
+ const b = ds.segment.getUint8(ds.byteOffset + byteOffset);
1366
+ if (defaultMask !== void 0) value = (defaultMask.getUint8(0) & bitMask) === 0 ? value : !value;
1367
+ ds.segment.setUint8(ds.byteOffset + byteOffset, value ? b | bitMask : b & ~bitMask);
1368
+ }
1369
+ function setFloat32(byteOffset, value, s, defaultMask) {
1370
+ checkDataBounds(byteOffset, 4, s);
1371
+ const ds = getDataSection(s);
1372
+ if (defaultMask !== void 0) {
1373
+ TMP_WORD.setFloat32(0, value, NATIVE_LITTLE_ENDIAN);
1374
+ const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
1375
+ ds.segment.setUint32(ds.byteOffset + byteOffset, v);
1376
+ return;
1377
+ }
1378
+ ds.segment.setFloat32(ds.byteOffset + byteOffset, value);
1379
+ }
1380
+ function setFloat64(byteOffset, value, s, defaultMask) {
1381
+ checkDataBounds(byteOffset, 8, s);
1382
+ const ds = getDataSection(s);
1383
+ if (defaultMask !== void 0) {
1384
+ TMP_WORD.setFloat64(0, value, NATIVE_LITTLE_ENDIAN);
1385
+ const lo = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
1386
+ const hi = TMP_WORD.getUint32(4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
1387
+ ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
1388
+ ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
1389
+ return;
1390
+ }
1391
+ ds.segment.setFloat64(ds.byteOffset + byteOffset, value);
1392
+ }
1393
+ function setInt16(byteOffset, value, s, defaultMask) {
1394
+ checkDataBounds(byteOffset, 2, s);
1395
+ const ds = getDataSection(s);
1396
+ if (defaultMask !== void 0) {
1397
+ TMP_WORD.setInt16(0, value, NATIVE_LITTLE_ENDIAN);
1398
+ const v = TMP_WORD.getUint16(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint16(0, true);
1399
+ ds.segment.setUint16(ds.byteOffset + byteOffset, v);
1400
+ return;
1401
+ }
1402
+ ds.segment.setInt16(ds.byteOffset + byteOffset, value);
1403
+ }
1404
+ function setInt32(byteOffset, value, s, defaultMask) {
1405
+ checkDataBounds(byteOffset, 4, s);
1406
+ const ds = getDataSection(s);
1407
+ if (defaultMask !== void 0) {
1408
+ TMP_WORD.setInt32(0, value, NATIVE_LITTLE_ENDIAN);
1409
+ const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
1410
+ ds.segment.setUint32(ds.byteOffset + byteOffset, v);
1411
+ return;
1412
+ }
1413
+ ds.segment.setInt32(ds.byteOffset + byteOffset, value);
1414
+ }
1415
+ function setInt64(byteOffset, value, s, defaultMask) {
1416
+ checkDataBounds(byteOffset, 8, s);
1417
+ const ds = getDataSection(s);
1418
+ if (defaultMask !== void 0) {
1419
+ TMP_WORD.setBigInt64(0, value, NATIVE_LITTLE_ENDIAN);
1420
+ const lo = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
1421
+ const hi = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
1422
+ ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
1423
+ ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
1424
+ return;
1425
+ }
1426
+ ds.segment.setInt64(ds.byteOffset + byteOffset, value);
1427
+ }
1428
+ function setInt8(byteOffset, value, s, defaultMask) {
1429
+ checkDataBounds(byteOffset, 1, s);
1430
+ const ds = getDataSection(s);
1431
+ if (defaultMask !== void 0) {
1432
+ TMP_WORD.setInt8(0, value);
1433
+ const v = TMP_WORD.getUint8(0) ^ defaultMask.getUint8(0);
1434
+ ds.segment.setUint8(ds.byteOffset + byteOffset, v);
1435
+ return;
1436
+ }
1437
+ ds.segment.setInt8(ds.byteOffset + byteOffset, value);
1438
+ }
1439
+ function setText(index, value, s) {
1440
+ Text.fromPointer(getPointer(index, s)).set(0, value);
1441
+ }
1442
+ function setUint16(byteOffset, value, s, defaultMask) {
1443
+ checkDataBounds(byteOffset, 2, s);
1444
+ const ds = getDataSection(s);
1445
+ if (defaultMask !== void 0) value ^= defaultMask.getUint16(0, true);
1446
+ ds.segment.setUint16(ds.byteOffset + byteOffset, value);
1447
+ }
1448
+ function setUint32(byteOffset, value, s, defaultMask) {
1449
+ checkDataBounds(byteOffset, 4, s);
1450
+ const ds = getDataSection(s);
1451
+ if (defaultMask !== void 0) value ^= defaultMask.getUint32(0, true);
1452
+ ds.segment.setUint32(ds.byteOffset + byteOffset, value);
1453
+ }
1454
+ function setUint64(byteOffset, value, s, defaultMask) {
1455
+ checkDataBounds(byteOffset, 8, s);
1456
+ const ds = getDataSection(s);
1457
+ if (defaultMask !== void 0) {
1458
+ TMP_WORD.setBigUint64(0, value, NATIVE_LITTLE_ENDIAN);
1459
+ const lo = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
1460
+ const hi = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
1461
+ ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
1462
+ ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
1463
+ return;
1464
+ }
1465
+ ds.segment.setUint64(ds.byteOffset + byteOffset, value);
1466
+ }
1467
+ function setUint8(byteOffset, value, s, defaultMask) {
1468
+ checkDataBounds(byteOffset, 1, s);
1469
+ const ds = getDataSection(s);
1470
+ if (defaultMask !== void 0) value ^= defaultMask.getUint8(0);
1471
+ ds.segment.setUint8(ds.byteOffset + byteOffset, value);
1472
+ }
1473
+ function testWhich(name, found, wanted, s) {
1474
+ if (found !== wanted) throw new Error(format(PTR_INVALID_UNION_ACCESS, s, name, found, wanted));
1475
+ }
1476
+ function checkDataBounds(byteOffset, byteLength, s) {
1477
+ const { dataByteLength } = getSize(s);
1478
+ if (byteOffset < 0 || byteLength < 0 || byteOffset + byteLength > dataByteLength) throw new Error(format(PTR_STRUCT_DATA_OUT_OF_BOUNDS, s, byteLength, byteOffset, dataByteLength));
1479
+ }
1480
+
1481
+ //#endregion
1482
+ //#region ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.3/node_modules/capnp-es/dist/shared/capnp-es.BvfUH5E6.mjs
1483
+ function CompositeList(CompositeClass) {
1484
+ return class extends List {
1485
+ static _capnp = {
1486
+ compositeSize: CompositeClass._capnp.size,
1487
+ displayName: `List<${CompositeClass._capnp.displayName}>`,
1488
+ size: ListElementSize.COMPOSITE
1489
+ };
1490
+ get(index) {
1491
+ return new CompositeClass(this.segment, this.byteOffset, this._capnp.depthLimit - 1, index);
1492
+ }
1493
+ set(index, value) {
1494
+ copyFrom(value, this.get(index));
1495
+ }
1496
+ [Symbol.toStringTag]() {
1497
+ return `Composite_${super.toString()},cls:${CompositeClass.toString()}`;
1498
+ }
1499
+ };
1500
+ }
1501
+ function _makePrimitiveMaskFn(byteLength, setter) {
1502
+ return (x) => {
1503
+ const dv = new DataView(new ArrayBuffer(byteLength));
1504
+ setter.call(dv, 0, x, true);
1505
+ return dv;
1506
+ };
1507
+ }
1508
+ const getFloat32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setFloat32);
1509
+ const getFloat64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setFloat64);
1510
+ const getInt16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setInt16);
1511
+ const getInt32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setInt32);
1512
+ const getInt64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setBigInt64);
1513
+ const getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8);
1514
+ const getUint16Mask = _makePrimitiveMaskFn(2, DataView.prototype.setUint16);
1515
+ const getUint32Mask = _makePrimitiveMaskFn(4, DataView.prototype.setUint32);
1516
+ const getUint64Mask = _makePrimitiveMaskFn(8, DataView.prototype.setBigUint64);
1517
+ const getUint8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setUint8);
1518
+ function getBitMask(value, bitOffset) {
1519
+ const dv = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(1));
1520
+ if (!value) return dv;
1521
+ dv.setUint8(0, 1 << bitOffset % 8);
1522
+ return dv;
1523
+ }
1524
+
1525
+ //#endregion
1526
+ //#region ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.3/node_modules/capnp-es/dist/shared/capnp-es.GpvEvMIK.mjs
1527
+ var ArenaKind = /* @__PURE__ */ ((ArenaKind2) => {
1528
+ ArenaKind2[ArenaKind2["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT";
1529
+ ArenaKind2[ArenaKind2["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT";
1530
+ return ArenaKind2;
1531
+ })(ArenaKind || {});
1532
+ var ArenaAllocationResult = class {
1533
+ /**
1534
+ * The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended.
1535
+ */
1536
+ buffer;
1537
+ /**
1538
+ * The id of the newly-allocated segment.
1539
+ */
1540
+ id;
1541
+ constructor(id, buffer) {
1542
+ this.id = id;
1543
+ this.buffer = buffer;
1544
+ }
1545
+ };
1546
+ var MultiSegmentArena = class {
1547
+ constructor(buffers = [new ArrayBuffer(DEFAULT_BUFFER_SIZE)]) {
1548
+ this.buffers = buffers;
1549
+ let i = buffers.length;
1550
+ while (--i >= 0) if ((buffers[i].byteLength & 7) !== 0) throw new Error(format(SEG_NOT_WORD_ALIGNED, buffers[i].byteLength));
1551
+ }
1552
+ static allocate = allocate$2;
1553
+ static getBuffer = getBuffer$2;
1554
+ static getNumSegments = getNumSegments$2;
1555
+ kind = ArenaKind.MULTI_SEGMENT;
1556
+ toString() {
1557
+ return format("MultiSegmentArena_segments:%d", getNumSegments$2(this));
1558
+ }
1559
+ };
1560
+ function allocate$2(minSize, m) {
1561
+ const b = new ArrayBuffer(padToWord$1(Math.max(minSize, DEFAULT_BUFFER_SIZE)));
1562
+ m.buffers.push(b);
1563
+ return new ArenaAllocationResult(m.buffers.length - 1, b);
1564
+ }
1565
+ function getBuffer$2(id, m) {
1566
+ if (id < 0 || id >= m.buffers.length) throw new Error(format(SEG_ID_OUT_OF_BOUNDS, id));
1567
+ return m.buffers[id];
1568
+ }
1569
+ function getNumSegments$2(m) {
1570
+ return m.buffers.length;
1571
+ }
1572
+ var SingleSegmentArena = class {
1573
+ static allocate = allocate$1;
1574
+ static getBuffer = getBuffer$1;
1575
+ static getNumSegments = getNumSegments$1;
1576
+ buffer;
1577
+ kind = ArenaKind.SINGLE_SEGMENT;
1578
+ constructor(buffer = new ArrayBuffer(DEFAULT_BUFFER_SIZE)) {
1579
+ if ((buffer.byteLength & 7) !== 0) throw new Error(format(SEG_NOT_WORD_ALIGNED, buffer.byteLength));
1580
+ this.buffer = buffer;
1581
+ }
1582
+ toString() {
1583
+ return format("SingleSegmentArena_len:%x", this.buffer.byteLength);
1584
+ }
1585
+ };
1586
+ function allocate$1(minSize, segments, s) {
1587
+ const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer;
1588
+ minSize = minSize < MIN_SINGLE_SEGMENT_GROWTH ? MIN_SINGLE_SEGMENT_GROWTH : padToWord$1(minSize);
1589
+ s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize);
1590
+ new Float64Array(s.buffer).set(new Float64Array(srcBuffer));
1591
+ return new ArenaAllocationResult(0, s.buffer);
1592
+ }
1593
+ function getBuffer$1(id, s) {
1594
+ if (id !== 0) throw new Error(format(SEG_GET_NON_ZERO_SINGLE, id));
1595
+ return s.buffer;
1596
+ }
1597
+ function getNumSegments$1() {
1598
+ return 1;
1599
+ }
1600
+ var Arena = class {
1601
+ static allocate = allocate;
1602
+ static copy = copy$1;
1603
+ static getBuffer = getBuffer;
1604
+ static getNumSegments = getNumSegments;
1605
+ };
1606
+ function allocate(minSize, segments, a) {
1607
+ switch (a.kind) {
1608
+ case ArenaKind.MULTI_SEGMENT: return MultiSegmentArena.allocate(minSize, a);
1609
+ case ArenaKind.SINGLE_SEGMENT: return SingleSegmentArena.allocate(minSize, segments, a);
1610
+ default: return assertNever(a);
1611
+ }
1612
+ }
1613
+ function copy$1(a) {
1614
+ switch (a.kind) {
1615
+ case ArenaKind.MULTI_SEGMENT: {
1616
+ let i = a.buffers.length;
1617
+ const buffers = Array.from({ length: i });
1618
+ while (--i >= 0) buffers[i] = a.buffers[i].slice(0);
1619
+ return new MultiSegmentArena(buffers);
1620
+ }
1621
+ case ArenaKind.SINGLE_SEGMENT: return new SingleSegmentArena(a.buffer.slice(0));
1622
+ default: return assertNever(a);
1623
+ }
1624
+ }
1625
+ function getBuffer(id, a) {
1626
+ switch (a.kind) {
1627
+ case ArenaKind.MULTI_SEGMENT: return MultiSegmentArena.getBuffer(id, a);
1628
+ case ArenaKind.SINGLE_SEGMENT: return SingleSegmentArena.getBuffer(id, a);
1629
+ default: return assertNever(a);
1630
+ }
1631
+ }
1632
+ function getNumSegments(a) {
1633
+ switch (a.kind) {
1634
+ case ArenaKind.MULTI_SEGMENT: return MultiSegmentArena.getNumSegments(a);
1635
+ case ArenaKind.SINGLE_SEGMENT: return SingleSegmentArena.getNumSegments();
1636
+ default: return assertNever(a);
1637
+ }
1638
+ }
1639
+ function getHammingWeight(x) {
1640
+ let w = x - (x >> 1 & 1431655765);
1641
+ w = (w & 858993459) + (w >> 2 & 858993459);
1642
+ return (w + (w >> 4) & 252645135) * 16843009 >> 24;
1643
+ }
1644
+ function getTagByte(a, b, c, d, e, f, g, h) {
1645
+ return (a === 0 ? 0 : 1) | (b === 0 ? 0 : 2) | (c === 0 ? 0 : 4) | (d === 0 ? 0 : 8) | (e === 0 ? 0 : 16) | (f === 0 ? 0 : 32) | (g === 0 ? 0 : 64) | (h === 0 ? 0 : 128);
1646
+ }
1647
+ function getUnpackedByteLength(packed) {
1648
+ const p = new Uint8Array(packed);
1649
+ let wordCount = 0;
1650
+ let lastTag = 119;
1651
+ for (let i = 0; i < p.byteLength;) {
1652
+ const tag = p[i];
1653
+ if (lastTag === 0) {
1654
+ wordCount += tag;
1655
+ i++;
1656
+ lastTag = 119;
1657
+ } else if (lastTag === 255) {
1658
+ wordCount += tag;
1659
+ i += tag * 8 + 1;
1660
+ lastTag = 119;
1661
+ } else {
1662
+ wordCount++;
1663
+ i += getHammingWeight(tag) + 1;
1664
+ lastTag = tag;
1665
+ }
1666
+ }
1667
+ return wordCount * 8;
1668
+ }
1669
+ function getZeroByteCount(a, b, c, d, e, f, g, h) {
1670
+ return (a === 0 ? 1 : 0) + (b === 0 ? 1 : 0) + (c === 0 ? 1 : 0) + (d === 0 ? 1 : 0) + (e === 0 ? 1 : 0) + (f === 0 ? 1 : 0) + (g === 0 ? 1 : 0) + (h === 0 ? 1 : 0);
1671
+ }
1672
+ function pack(unpacked, byteOffset = 0, byteLength) {
1673
+ if (unpacked.byteLength % 8 !== 0) throw new Error(MSG_PACK_NOT_WORD_ALIGNED);
1674
+ const src = new Uint8Array(unpacked, byteOffset, byteLength);
1675
+ const dst = [];
1676
+ let lastTag = 119;
1677
+ let spanWordCountOffset = 0;
1678
+ let rangeWordCount = 0;
1679
+ for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) {
1680
+ const a = src[srcByteOffset];
1681
+ const b = src[srcByteOffset + 1];
1682
+ const c = src[srcByteOffset + 2];
1683
+ const d = src[srcByteOffset + 3];
1684
+ const e = src[srcByteOffset + 4];
1685
+ const f = src[srcByteOffset + 5];
1686
+ const g = src[srcByteOffset + 6];
1687
+ const h = src[srcByteOffset + 7];
1688
+ const tag = getTagByte(a, b, c, d, e, f, g, h);
1689
+ let skipWriteWord = true;
1690
+ switch (lastTag) {
1691
+ case 0:
1692
+ if (tag !== 0 || rangeWordCount >= 255) {
1693
+ dst.push(rangeWordCount);
1694
+ rangeWordCount = 0;
1695
+ skipWriteWord = false;
1696
+ } else rangeWordCount++;
1697
+ break;
1698
+ case 255:
1699
+ if (getZeroByteCount(a, b, c, d, e, f, g, h) >= PACK_SPAN_THRESHOLD || rangeWordCount >= 255) {
1700
+ dst[spanWordCountOffset] = rangeWordCount;
1701
+ rangeWordCount = 0;
1702
+ skipWriteWord = false;
1703
+ } else {
1704
+ dst.push(a, b, c, d, e, f, g, h);
1705
+ rangeWordCount++;
1706
+ }
1707
+ break;
1708
+ default:
1709
+ skipWriteWord = false;
1710
+ break;
1711
+ }
1712
+ if (skipWriteWord) continue;
1713
+ dst.push(tag);
1714
+ lastTag = tag;
1715
+ if (a !== 0) dst.push(a);
1716
+ if (b !== 0) dst.push(b);
1717
+ if (c !== 0) dst.push(c);
1718
+ if (d !== 0) dst.push(d);
1719
+ if (e !== 0) dst.push(e);
1720
+ if (f !== 0) dst.push(f);
1721
+ if (g !== 0) dst.push(g);
1722
+ if (h !== 0) dst.push(h);
1723
+ if (tag === 255) {
1724
+ spanWordCountOffset = dst.length;
1725
+ dst.push(0);
1726
+ }
1727
+ }
1728
+ if (lastTag === 0) dst.push(rangeWordCount);
1729
+ else if (lastTag === 255) dst[spanWordCountOffset] = rangeWordCount;
1730
+ return new Uint8Array(dst).buffer;
1731
+ }
1732
+ function unpack(packed) {
1733
+ const src = new Uint8Array(packed);
1734
+ const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed)));
1735
+ let lastTag = 119;
1736
+ for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength;) {
1737
+ const tag = src[srcByteOffset];
1738
+ if (lastTag === 0) {
1739
+ dstByteOffset += tag * 8;
1740
+ srcByteOffset++;
1741
+ lastTag = 119;
1742
+ } else if (lastTag === 255) {
1743
+ const spanByteLength = tag * 8;
1744
+ dst.set(src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength), dstByteOffset);
1745
+ dstByteOffset += spanByteLength;
1746
+ srcByteOffset += 1 + spanByteLength;
1747
+ lastTag = 119;
1748
+ } else {
1749
+ srcByteOffset++;
1750
+ for (let i = 1; i <= 128; i <<= 1) {
1751
+ if ((tag & i) !== 0) dst[dstByteOffset] = src[srcByteOffset++];
1752
+ dstByteOffset++;
1753
+ }
1754
+ lastTag = tag;
1755
+ }
1756
+ }
1757
+ return dst.buffer;
1758
+ }
1759
+ var Segment = class {
1760
+ constructor(id, message, buffer, byteLength = 0) {
1761
+ this.id = id;
1762
+ this.message = message;
1763
+ this.message = message;
1764
+ this.buffer = buffer;
1765
+ this._dv = new DataView(buffer);
1766
+ this.byteOffset = 0;
1767
+ this.byteLength = byteLength;
1768
+ }
1769
+ buffer;
1770
+ /** The number of bytes currently allocated in the segment. */
1771
+ byteLength;
1772
+ /**
1773
+ * This value should always be zero. It's only here to satisfy the DataView interface.
1774
+ *
1775
+ * In the future the Segment implementation (or a child class) may allow accessing the buffer from a nonzero offset,
1776
+ * but that adds a lot of extra arithmetic.
1777
+ */
1778
+ byteOffset;
1779
+ [Symbol.toStringTag] = "Segment";
1780
+ _dv;
1781
+ /**
1782
+ * Attempt to allocate the requested number of bytes in this segment. If this segment is full this method will return
1783
+ * a pointer to freshly allocated space in another segment from the same message.
1784
+ *
1785
+ * @param byteLength The number of bytes to allocate, will be rounded up to the nearest word.
1786
+ * @returns A pointer to the newly allocated space.
1787
+ */
1788
+ allocate(byteLength) {
1789
+ let segment = this;
1790
+ byteLength = padToWord$1(byteLength);
1791
+ if (byteLength > MAX_SEGMENT_LENGTH - 8) throw new Error(format(SEG_SIZE_OVERFLOW, byteLength));
1792
+ if (!segment.hasCapacity(byteLength)) segment = segment.message.allocateSegment(byteLength);
1793
+ const byteOffset = segment.byteLength;
1794
+ segment.byteLength += byteLength;
1795
+ return new Pointer(segment, byteOffset);
1796
+ }
1797
+ /**
1798
+ * Quickly copy a word (8 bytes) from `srcSegment` into this one at the given offset.
1799
+ *
1800
+ * @param byteOffset The offset to write the word to.
1801
+ * @param srcSegment The segment to copy the word from.
1802
+ * @param srcByteOffset The offset from the start of `srcSegment` to copy from.
1803
+ */
1804
+ copyWord(byteOffset, srcSegment, srcByteOffset) {
1805
+ const value = srcSegment._dv.getFloat64(srcByteOffset, NATIVE_LITTLE_ENDIAN);
1806
+ this._dv.setFloat64(byteOffset, value, NATIVE_LITTLE_ENDIAN);
1807
+ }
1808
+ /**
1809
+ * Quickly copy words from `srcSegment` into this one.
1810
+ *
1811
+ * @param byteOffset The offset to start copying into.
1812
+ * @param srcSegment The segment to copy from.
1813
+ * @param srcByteOffset The start offset to copy from.
1814
+ * @param wordLength The number of words to copy.
1815
+ */
1816
+ copyWords(byteOffset, srcSegment, srcByteOffset, wordLength) {
1817
+ const dst = new Float64Array(this.buffer, byteOffset, wordLength);
1818
+ const src = new Float64Array(srcSegment.buffer, srcByteOffset, wordLength);
1819
+ dst.set(src);
1820
+ }
1821
+ /**
1822
+ * Quickly fill a number of words in the buffer with zeroes.
1823
+ *
1824
+ * @param byteOffset The first byte to set to zero.
1825
+ * @param wordLength The number of words (not bytes!) to zero out.
1826
+ */
1827
+ fillZeroWords(byteOffset, wordLength) {
1828
+ new Float64Array(this.buffer, byteOffset, wordLength).fill(0);
1829
+ }
1830
+ getBigInt64(byteOffset, littleEndian) {
1831
+ return this._dv.getBigInt64(byteOffset, littleEndian);
1832
+ }
1833
+ getBigUint64(byteOffset, littleEndian) {
1834
+ return this._dv.getBigUint64(byteOffset, littleEndian);
1835
+ }
1836
+ /**
1837
+ * Get the total number of bytes available in this segment (the size of its underlying buffer).
1838
+ *
1839
+ * @returns The total number of bytes this segment can hold.
1840
+ */
1841
+ getCapacity() {
1842
+ return this.buffer.byteLength;
1843
+ }
1844
+ /**
1845
+ * Read a float32 value out of this segment.
1846
+ *
1847
+ * @param byteOffset The offset in bytes to the value.
1848
+ * @returns The value.
1849
+ */
1850
+ getFloat32(byteOffset) {
1851
+ return this._dv.getFloat32(byteOffset, true);
1852
+ }
1853
+ /**
1854
+ * Read a float64 value out of this segment.
1855
+ *
1856
+ * @param byteOffset The offset in bytes to the value.
1857
+ * @returns The value.
1858
+ */
1859
+ getFloat64(byteOffset) {
1860
+ return this._dv.getFloat64(byteOffset, true);
1861
+ }
1862
+ /**
1863
+ * Read an int16 value out of this segment.
1864
+ *
1865
+ * @param byteOffset The offset in bytes to the value.
1866
+ * @returns The value.
1867
+ */
1868
+ getInt16(byteOffset) {
1869
+ return this._dv.getInt16(byteOffset, true);
1870
+ }
1871
+ /**
1872
+ * Read an int32 value out of this segment.
1873
+ *
1874
+ * @param byteOffset The offset in bytes to the value.
1875
+ * @returns The value.
1876
+ */
1877
+ getInt32(byteOffset) {
1878
+ return this._dv.getInt32(byteOffset, true);
1879
+ }
1880
+ /**
1881
+ * Read an int64 value out of this segment.
1882
+ *
1883
+ * @param byteOffset The offset in bytes to the value.
1884
+ * @returns The value.
1885
+ */
1886
+ getInt64(byteOffset) {
1887
+ return this._dv.getBigInt64(byteOffset, true);
1888
+ }
1889
+ /**
1890
+ * Read an int8 value out of this segment.
1891
+ *
1892
+ * @param byteOffset The offset in bytes to the value.
1893
+ * @returns The value.
1894
+ */
1895
+ getInt8(byteOffset) {
1896
+ return this._dv.getInt8(byteOffset);
1897
+ }
1898
+ /**
1899
+ * Read a uint16 value out of this segment.
1900
+ *
1901
+ * @param byteOffset The offset in bytes to the value.
1902
+ * @returns The value.
1903
+ */
1904
+ getUint16(byteOffset) {
1905
+ return this._dv.getUint16(byteOffset, true);
1906
+ }
1907
+ /**
1908
+ * Read a uint32 value out of this segment.
1909
+ *
1910
+ * @param byteOffset The offset in bytes to the value.
1911
+ * @returns The value.
1912
+ */
1913
+ getUint32(byteOffset) {
1914
+ return this._dv.getUint32(byteOffset, true);
1915
+ }
1916
+ /**
1917
+ * Read a uint64 value (as a bigint) out of this segment.
1918
+ * NOTE: this does not copy the memory region, so updates to the underlying buffer will affect the returned value!
1919
+ *
1920
+ * @param byteOffset The offset in bytes to the value.
1921
+ * @returns The value.
1922
+ */
1923
+ getUint64(byteOffset) {
1924
+ return this._dv.getBigUint64(byteOffset, true);
1925
+ }
1926
+ /**
1927
+ * Read a uint8 value out of this segment.
1928
+ *
1929
+ * @param byteOffset The offset in bytes to the value.
1930
+ * @returns The value.
1931
+ */
1932
+ getUint8(byteOffset) {
1933
+ return this._dv.getUint8(byteOffset);
1934
+ }
1935
+ hasCapacity(byteLength) {
1936
+ return this.buffer.byteLength - this.byteLength >= byteLength;
1937
+ }
1938
+ /**
1939
+ * Quickly check the word at the given offset to see if it is equal to zero.
1940
+ *
1941
+ * PERF_V8: Fastest way to do this is by reading the whole word as a `number` (float64) in the _native_ endian format
1942
+ * and see if it's zero.
1943
+ *
1944
+ * Benchmark: http://jsben.ch/#/Pjooc
1945
+ *
1946
+ * @param byteOffset The offset to the word.
1947
+ * @returns `true` if the word is zero.
1948
+ */
1949
+ isWordZero(byteOffset) {
1950
+ return this._dv.getFloat64(byteOffset, NATIVE_LITTLE_ENDIAN) === 0;
1951
+ }
1952
+ /**
1953
+ * Swap out this segment's underlying buffer with a new one. It's assumed that the new buffer has the same content but
1954
+ * more free space, otherwise all existing pointers to this segment will be hilariously broken.
1955
+ *
1956
+ * @param buffer The new buffer to use.
1957
+ */
1958
+ replaceBuffer(buffer) {
1959
+ if (this.buffer === buffer) return;
1960
+ if (buffer.byteLength < this.byteLength) throw new Error(SEG_REPLACEMENT_BUFFER_TOO_SMALL);
1961
+ this._dv = new DataView(buffer);
1962
+ this.buffer = buffer;
1963
+ }
1964
+ setBigInt64(byteOffset, value, littleEndian) {
1965
+ this._dv.setBigInt64(byteOffset, value, littleEndian);
1966
+ }
1967
+ /** WARNING: This function is not yet implemented. */
1968
+ setBigUint64(byteOffset, value, littleEndian) {
1969
+ this._dv.setBigUint64(byteOffset, value, littleEndian);
1970
+ }
1971
+ /**
1972
+ * Write a float32 value to the specified offset.
1973
+ *
1974
+ * @param byteOffset The offset from the beginning of the buffer.
1975
+ * @param val The value to store.
1976
+ */
1977
+ setFloat32(byteOffset, val) {
1978
+ this._dv.setFloat32(byteOffset, val, true);
1979
+ }
1980
+ /**
1981
+ * Write an float64 value to the specified offset.
1982
+ *
1983
+ * @param byteOffset The offset from the beginning of the buffer.
1984
+ * @param val The value to store.
1985
+ */
1986
+ setFloat64(byteOffset, val) {
1987
+ this._dv.setFloat64(byteOffset, val, true);
1988
+ }
1989
+ /**
1990
+ * Write an int16 value to the specified offset.
1991
+ *
1992
+ * @param byteOffset The offset from the beginning of the buffer.
1993
+ * @param val The value to store.
1994
+ */
1995
+ setInt16(byteOffset, val) {
1996
+ this._dv.setInt16(byteOffset, val, true);
1997
+ }
1998
+ /**
1999
+ * Write an int32 value to the specified offset.
2000
+ *
2001
+ * @param byteOffset The offset from the beginning of the buffer.
2002
+ * @param val The value to store.
2003
+ */
2004
+ setInt32(byteOffset, val) {
2005
+ this._dv.setInt32(byteOffset, val, true);
2006
+ }
2007
+ /**
2008
+ * Write an int8 value to the specified offset.
2009
+ *
2010
+ * @param byteOffset The offset from the beginning of the buffer.
2011
+ * @param val The value to store.
2012
+ */
2013
+ setInt8(byteOffset, val) {
2014
+ this._dv.setInt8(byteOffset, val);
2015
+ }
2016
+ /**
2017
+ * Write an int64 value to the specified offset.
2018
+ *
2019
+ * @param byteOffset The offset from the beginning of the buffer.
2020
+ * @param val The value to store.
2021
+ */
2022
+ setInt64(byteOffset, val) {
2023
+ this._dv.setBigInt64(byteOffset, val, true);
2024
+ }
2025
+ /**
2026
+ * Write a uint16 value to the specified offset.
2027
+ *
2028
+ * @param byteOffset The offset from the beginning of the buffer.
2029
+ * @param val The value to store.
2030
+ */
2031
+ setUint16(byteOffset, val) {
2032
+ this._dv.setUint16(byteOffset, val, true);
2033
+ }
2034
+ /**
2035
+ * Write a uint32 value to the specified offset.
2036
+ *
2037
+ * @param byteOffset The offset from the beginning of the buffer.
2038
+ * @param val The value to store.
2039
+ */
2040
+ setUint32(byteOffset, val) {
2041
+ this._dv.setUint32(byteOffset, val, true);
2042
+ }
2043
+ /**
2044
+ * Write a uint64 value to the specified offset.
2045
+ *
2046
+ * @param byteOffset The offset from the beginning of the buffer.
2047
+ * @param val The value to store.
2048
+ */
2049
+ setUint64(byteOffset, val) {
2050
+ this._dv.setBigUint64(byteOffset, val, true);
2051
+ }
2052
+ /**
2053
+ * Write a uint8 (byte) value to the specified offset.
2054
+ *
2055
+ * @param byteOffset The offset from the beginning of the buffer.
2056
+ * @param val The value to store.
2057
+ */
2058
+ setUint8(byteOffset, val) {
2059
+ this._dv.setUint8(byteOffset, val);
2060
+ }
2061
+ /**
2062
+ * Write a zero word (8 bytes) to the specified offset. This is slightly faster than calling `setUint64` or
2063
+ * `setFloat64` with a zero value.
2064
+ *
2065
+ * Benchmark: http://jsben.ch/#/dUdPI
2066
+ *
2067
+ * @param byteOffset The offset of the word to set to zero.
2068
+ */
2069
+ setWordZero(byteOffset) {
2070
+ this._dv.setFloat64(byteOffset, 0, NATIVE_LITTLE_ENDIAN);
2071
+ }
2072
+ toString() {
2073
+ return format("Segment_id:%d,off:%a,len:%a,cap:%a", this.id, this.byteLength, this.byteOffset, this.buffer.byteLength);
2074
+ }
2075
+ };
2076
+ var Message = class {
2077
+ static allocateSegment = allocateSegment;
2078
+ static dump = dump;
2079
+ static getRoot = getRoot;
2080
+ static getSegment = getSegment;
2081
+ static initRoot = initRoot;
2082
+ static readRawPointer = readRawPointer;
2083
+ static toArrayBuffer = toArrayBuffer;
2084
+ static toPackedArrayBuffer = toPackedArrayBuffer;
2085
+ _capnp;
2086
+ /**
2087
+ * A Cap'n Proto message.
2088
+ *
2089
+ * SECURITY WARNING: In Node.js do not pass a Buffer's internal array buffer into this constructor. Pass the buffer
2090
+ * directly and everything will be fine. If not, your message will potentially be initialized with random memory
2091
+ * contents!
2092
+ *
2093
+ * The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer
2094
+ * to read from.
2095
+ *
2096
+ * @param src The source for the message.
2097
+ * A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the
2098
+ * root pointer; it will expand as you go. This is a reasonable choice for most messages.
2099
+ *
2100
+ * Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted
2101
+ * as-is.
2102
+ *
2103
+ * Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source
2104
+ * buffer; beware of the potential performance cost!
2105
+ *
2106
+ * @param packed Whether or not the message is packed. If `true` (the default), the message will be
2107
+ * unpacked.
2108
+ *
2109
+ * @param singleSegment If true, `src` will be treated as a message consisting of a single segment without
2110
+ * a framing header.
2111
+ *
2112
+ */
2113
+ constructor(src, packed = true, singleSegment = false) {
2114
+ this._capnp = initMessage(src, packed, singleSegment);
2115
+ if (src) preallocateSegments(this);
2116
+ }
2117
+ allocateSegment(byteLength) {
2118
+ return allocateSegment(byteLength, this);
2119
+ }
2120
+ /**
2121
+ * Copies the contents of this message into an identical message with its own ArrayBuffers.
2122
+ *
2123
+ * @returns A copy of this message.
2124
+ */
2125
+ copy() {
2126
+ return copy(this);
2127
+ }
2128
+ /**
2129
+ * Create a pretty-printed string dump of this message; incredibly useful for debugging.
2130
+ *
2131
+ * WARNING: Do not call this method on large messages!
2132
+ *
2133
+ * @returns A big steaming pile of pretty hex digits.
2134
+ */
2135
+ dump() {
2136
+ return dump(this);
2137
+ }
2138
+ /**
2139
+ * Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not
2140
+ * overwrite existing data.
2141
+ *
2142
+ * @param RootStruct The struct type to use as the root.
2143
+ * @returns A struct representing the root of the message.
2144
+ */
2145
+ getRoot(RootStruct) {
2146
+ return getRoot(RootStruct, this);
2147
+ }
2148
+ /**
2149
+ * Get a segment by its id.
2150
+ *
2151
+ * This will lazily allocate the first segment if it doesn't already exist.
2152
+ *
2153
+ * @param id The segment id.
2154
+ * @returns The requested segment.
2155
+ */
2156
+ getSegment(id) {
2157
+ return getSegment(id, this);
2158
+ }
2159
+ /**
2160
+ * Initialize a new message using the provided struct type as the root.
2161
+ *
2162
+ * @param RootStruct The struct type to use as the root.
2163
+ * @returns An initialized struct pointing to the root of the message.
2164
+ */
2165
+ initRoot(RootStruct) {
2166
+ return initRoot(RootStruct, this);
2167
+ }
2168
+ /**
2169
+ * Set the root of the message to a copy of the given pointer. Used internally
2170
+ * to make copies of pointers for default values.
2171
+ *
2172
+ * @param src The source pointer to copy.
2173
+ */
2174
+ setRoot(src) {
2175
+ setRoot(src, this);
2176
+ }
2177
+ /**
2178
+ * Combine the contents of this message's segments into a single array buffer and prepend a stream framing header
2179
+ * containing information about the following segment data.
2180
+ *
2181
+ * @returns An ArrayBuffer with the contents of this message.
2182
+ */
2183
+ toArrayBuffer() {
2184
+ return toArrayBuffer(this);
2185
+ }
2186
+ /**
2187
+ * Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to
2188
+ * use if you're sending the message over a network link or other slow I/O interface where size matters.
2189
+ *
2190
+ * @returns A packed message.
2191
+ */
2192
+ toPackedArrayBuffer() {
2193
+ return toPackedArrayBuffer(this);
2194
+ }
2195
+ addCap(client) {
2196
+ if (!this._capnp.capTable) this._capnp.capTable = [];
2197
+ const id = this._capnp.capTable.length;
2198
+ this._capnp.capTable.push(client);
2199
+ return id;
2200
+ }
2201
+ toString() {
2202
+ return `Message_arena:${this._capnp.arena}`;
2203
+ }
2204
+ };
2205
+ function initMessage(src, packed = true, singleSegment = false) {
2206
+ if (src === void 0) return {
2207
+ arena: new SingleSegmentArena(),
2208
+ segments: [],
2209
+ traversalLimit: DEFAULT_TRAVERSE_LIMIT
2210
+ };
2211
+ if (isAnyArena(src)) return {
2212
+ arena: src,
2213
+ segments: [],
2214
+ traversalLimit: DEFAULT_TRAVERSE_LIMIT
2215
+ };
2216
+ let buf = src;
2217
+ if (isArrayBufferView(buf)) buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
2218
+ if (packed) buf = unpack(buf);
2219
+ if (singleSegment) return {
2220
+ arena: new SingleSegmentArena(buf),
2221
+ segments: [],
2222
+ traversalLimit: DEFAULT_TRAVERSE_LIMIT
2223
+ };
2224
+ return {
2225
+ arena: new MultiSegmentArena(getFramedSegments(buf)),
2226
+ segments: [],
2227
+ traversalLimit: DEFAULT_TRAVERSE_LIMIT
2228
+ };
2229
+ }
2230
+ function getFramedSegments(message) {
2231
+ const dv = new DataView(message);
2232
+ const segmentCount = dv.getUint32(0, true) + 1;
2233
+ const segments = Array.from({ length: segmentCount });
2234
+ let byteOffset = 4 + segmentCount * 4;
2235
+ byteOffset += byteOffset % 8;
2236
+ if (byteOffset + segmentCount * 4 > message.byteLength) throw new Error(MSG_INVALID_FRAME_HEADER);
2237
+ for (let i = 0; i < segmentCount; i++) {
2238
+ const byteLength = dv.getUint32(4 + i * 4, true) * 8;
2239
+ if (byteOffset + byteLength > message.byteLength) throw new Error(MSG_INVALID_FRAME_HEADER);
2240
+ segments[i] = message.slice(byteOffset, byteOffset + byteLength);
2241
+ byteOffset += byteLength;
2242
+ }
2243
+ return segments;
2244
+ }
2245
+ function preallocateSegments(m) {
2246
+ const numSegments = Arena.getNumSegments(m._capnp.arena);
2247
+ m._capnp.segments = Array.from({ length: numSegments });
2248
+ for (let i = 0; i < numSegments; i++) {
2249
+ if (i === 0 && Arena.getBuffer(i, m._capnp.arena).byteLength < 8) throw new Error(MSG_SEGMENT_TOO_SMALL);
2250
+ const buffer = Arena.getBuffer(i, m._capnp.arena);
2251
+ const segment = new Segment(i, m, buffer, buffer.byteLength);
2252
+ m._capnp.segments[i] = segment;
2253
+ }
2254
+ }
2255
+ function isArrayBufferView(src) {
2256
+ return src.byteOffset !== void 0;
2257
+ }
2258
+ function isAnyArena(o) {
2259
+ return o.kind !== void 0;
2260
+ }
2261
+ function allocateSegment(byteLength, m) {
2262
+ const res = Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena);
2263
+ let s;
2264
+ if (res.id === m._capnp.segments.length) {
2265
+ s = new Segment(res.id, m, res.buffer);
2266
+ m._capnp.segments.push(s);
2267
+ } else if (res.id < 0 || res.id > m._capnp.segments.length) throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m));
2268
+ else {
2269
+ s = m._capnp.segments[res.id];
2270
+ s.replaceBuffer(res.buffer);
2271
+ }
2272
+ return s;
2273
+ }
2274
+ function dump(m) {
2275
+ let r = "";
2276
+ if (m._capnp.segments.length === 0) return "================\nNo Segments\n================\n";
2277
+ for (let i = 0; i < m._capnp.segments.length; i++) {
2278
+ r += `================
2279
+ Segment #${i}
2280
+ ================
2281
+ `;
2282
+ const { buffer, byteLength } = m._capnp.segments[i];
2283
+ const b = new Uint8Array(buffer, 0, byteLength);
2284
+ r += dumpBuffer(b);
2285
+ }
2286
+ return r;
2287
+ }
2288
+ function getRoot(RootStruct, m) {
2289
+ const root = new RootStruct(m.getSegment(0), 0);
2290
+ validate(PointerType.STRUCT, root);
2291
+ const ts = getTargetStructSize(root);
2292
+ if (ts.dataByteLength < RootStruct._capnp.size.dataByteLength || ts.pointerLength < RootStruct._capnp.size.pointerLength) resize(RootStruct._capnp.size, root);
2293
+ return root;
2294
+ }
2295
+ function getSegment(id, m) {
2296
+ const segmentLength = m._capnp.segments.length;
2297
+ if (id === 0 && segmentLength === 0) {
2298
+ if (Arena.getNumSegments(m._capnp.arena) === 0) allocateSegment(DEFAULT_BUFFER_SIZE, m);
2299
+ else m._capnp.segments[0] = new Segment(0, m, Arena.getBuffer(0, m._capnp.arena));
2300
+ if (!m._capnp.segments[0].hasCapacity(8)) throw new Error(MSG_SEGMENT_TOO_SMALL);
2301
+ m._capnp.segments[0].allocate(8);
2302
+ return m._capnp.segments[0];
2303
+ }
2304
+ if (id < 0 || id >= segmentLength) throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, id, m));
2305
+ return m._capnp.segments[id];
2306
+ }
2307
+ function initRoot(RootStruct, m) {
2308
+ const root = new RootStruct(m.getSegment(0), 0);
2309
+ initStruct(RootStruct._capnp.size, root);
2310
+ return root;
2311
+ }
2312
+ function readRawPointer(data) {
2313
+ return new Pointer(new Message(data).getSegment(0), 0);
2314
+ }
2315
+ function setRoot(src, m) {
2316
+ copyFrom(src, new Pointer(m.getSegment(0), 0));
2317
+ }
2318
+ function toArrayBuffer(m) {
2319
+ const streamFrame = getStreamFrame(m);
2320
+ if (m._capnp.segments.length === 0) getSegment(0, m);
2321
+ const { segments } = m._capnp;
2322
+ const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + padToWord$1(s.byteLength), 0);
2323
+ const out = new Uint8Array(new ArrayBuffer(totalLength));
2324
+ let o = streamFrame.byteLength;
2325
+ out.set(new Uint8Array(streamFrame));
2326
+ for (const s of segments) {
2327
+ const segmentLength = padToWord$1(s.byteLength);
2328
+ out.set(new Uint8Array(s.buffer, 0, segmentLength), o);
2329
+ o += segmentLength;
2330
+ }
2331
+ return out.buffer;
2332
+ }
2333
+ function toPackedArrayBuffer(m) {
2334
+ const streamFrame = pack(getStreamFrame(m));
2335
+ if (m._capnp.segments.length === 0) m.getSegment(0);
2336
+ const segments = m._capnp.segments.map((s) => pack(s.buffer, 0, padToWord$1(s.byteLength)));
2337
+ const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0);
2338
+ const out = new Uint8Array(new ArrayBuffer(totalLength));
2339
+ let o = streamFrame.byteLength;
2340
+ out.set(new Uint8Array(streamFrame));
2341
+ for (const s of segments) {
2342
+ out.set(new Uint8Array(s), o);
2343
+ o += s.byteLength;
2344
+ }
2345
+ return out.buffer;
2346
+ }
2347
+ function getStreamFrame(m) {
2348
+ const { length } = m._capnp.segments;
2349
+ if (length === 0) return new Float64Array(1).buffer;
2350
+ const frameLength = 4 + length * 4 + (1 - length % 2) * 4;
2351
+ const out = new DataView(new ArrayBuffer(frameLength));
2352
+ out.setUint32(0, length - 1, true);
2353
+ for (const [i, s] of m._capnp.segments.entries()) out.setUint32(i * 4 + 4, s.byteLength / 8, true);
2354
+ return out.buffer;
2355
+ }
2356
+ function copy(m) {
2357
+ return new Message(Arena.copy(m._capnp.arena));
2358
+ }
2359
+
2360
+ //#endregion
2361
+ export { clientOrNull as $, initData as $t, RPC_BAD_TARGET as A, getListElementSize as At, RPC_QUESTION_ID_REUSED as B, getStructPointerLength as Bt, MAX_DEPTH as C, setUint64 as Cn, getInt8 as Ct, Pointer as D, validate as Dn, getList as Dt, Orphan as E, trackPointerAllocation as En, getInterfacePointer as Et, RPC_IMPORT_CLOSED as F, getPointerSection as Ft, RPC_UNKNOWN_EXPORT_ID as G, getTargetListLength as Gt, RPC_RETURN_FOR_UNKNOWN_QUESTION as H, getTargetCompositeListSize as Ht, RPC_METHOD_ERROR as I, getPointerType as It, Text as J, getText as Jt, RPC_ZERO_REF as K, getTargetPointerType as Kt, RPC_METHOD_NOT_IMPLEMENTED as L, getSize as Lt, RPC_ERROR as M, getOffsetWords as Mt, RPC_FINISH_UNKNOWN_ANSWER as N, getPointer as Nt, PointerAllocationResult as O, getListByteLength as Ot, RPC_FULFILL_ALREADY_CALLED as P, getPointerAs as Pt, checkPointerBounds as Q, getUint8 as Qt, RPC_NO_MAIN_INTERFACE as R, getStruct as Rt, ListElementSize as S, setUint32 as Sn, getInt64 as St, ObjectSize as T, testWhich as Tn, getInterfaceClientOrNullAt as Tt, RPC_UNKNOWN_ANSWER_ID as U, getTargetCompositeListTag as Ut, RPC_QUEUE_CALL_CANCEL as V, getStructSize as Vt, RPC_UNKNOWN_CAP_DESCRIPTOR as W, getTargetListElementSize as Wt, adopt as X, getUint32 as Xt, add as Y, getUint16 as Yt, checkDataBounds as Z, getUint64 as Zt, ErrorAnswer as _, setInterfacePointer as _n, getFarSegmentId as _t, getFloat32Mask as a, isNull as an, dump$1 as at, INVARIANT_UNREACHABLE_CODE as b, setText as bn, getInt16 as bt, getInt32Mask as c, resize as cn, followFar as ct, getUint16Mask as d, setFloat32 as dn, getAs as dt, initList as en, copyFrom as et, getUint32Mask as f, setFloat64 as fn, getBit as ft, Data as g, setInt8 as gn, getDataSection as gt, AnyStruct as h, setInt64 as hn, getData as ht, getBitMask as i, isDoubleFar as in, disown as it, RPC_CALL_QUEUE_FULL as j, getListLength as jt, PointerType as k, getListElementByteLength as kt, getInt64Mask as l, setBit as ln, followFars as lt, getUint8Mask as m, setInt32 as mn, getContent as mt, readRawPointer as n, initStruct as nn, copyFromList as nt, getFloat64Mask as o, pad as on, erase as ot, getUint64Mask as p, setInt16 as pn, getCapabilityId as pt, Struct as q, getTargetStructSize as qt, CompositeList as r, initStructAt as rn, copyFromStruct as rt, getInt16Mask as s, relocateTo as sn, erasePointer as st, Message as t, initPointer as tn, copyFromInterface as tt, getInt8Mask as u, setFarPointer as un, format as ut, ErrorClient as v, setListPointer as vn, getFloat32 as vt, NOT_IMPLEMENTED as w, setUint8 as wn, getInterfaceClientOrNull as wt, List as x, setUint16 as xn, getInt32 as xt, FixedAnswer as y, setStructPointer as yn, getFloat64 as yt, RPC_NULL_CLIENT as z, getStructDataWords as zt };
2362
+ //# sourceMappingURL=capnp-es.GpvEvMIK-BH8YrftV.mjs.map