@stryke/capnp 0.10.1 → 0.10.2
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.
- package/dist/chunk-3IOIINHW.js +895 -0
- package/dist/chunk-3ZOLKZQQ.cjs +895 -0
- package/dist/chunk-55455L4M.cjs +4103 -0
- package/dist/chunk-5VHN3KGS.js +3305 -0
- package/dist/chunk-CCU32X36.js +15 -0
- package/dist/chunk-GWW6WBAL.js +4103 -0
- package/dist/chunk-IBMXNAOT.cjs +4877 -0
- package/dist/chunk-KXWOF6H4.cjs +3305 -0
- package/dist/chunk-N2KNXTXN.js +4877 -0
- package/dist/chunk-R2JXWA7Q.cjs +15 -0
- package/dist/compile.cjs +7 -74
- package/dist/compile.js +6 -73
- package/dist/helpers.cjs +4 -67
- package/dist/helpers.js +3 -66
- package/dist/index.cjs +138 -4
- package/dist/index.js +138 -4
- package/dist/rpc.cjs +6 -117
- package/dist/rpc.js +5 -116
- package/dist/types.cjs +3 -8
- package/dist/types.js +3 -8
- package/package.json +3 -3
|
@@ -0,0 +1,3305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-SHUYVCID.js";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs
|
|
6
|
+
var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
|
|
7
|
+
ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
|
|
8
|
+
ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
|
|
9
|
+
ListElementSize2[ListElementSize2["BYTE"] = 2] = "BYTE";
|
|
10
|
+
ListElementSize2[ListElementSize2["BYTE_2"] = 3] = "BYTE_2";
|
|
11
|
+
ListElementSize2[ListElementSize2["BYTE_4"] = 4] = "BYTE_4";
|
|
12
|
+
ListElementSize2[ListElementSize2["BYTE_8"] = 5] = "BYTE_8";
|
|
13
|
+
ListElementSize2[ListElementSize2["POINTER"] = 6] = "POINTER";
|
|
14
|
+
ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
|
|
15
|
+
return ListElementSize2;
|
|
16
|
+
})(ListElementSize || {});
|
|
17
|
+
var tmpWord = new DataView(new ArrayBuffer(8));
|
|
18
|
+
new Uint16Array(tmpWord.buffer)[0] = 258;
|
|
19
|
+
var DEFAULT_BUFFER_SIZE = 4096;
|
|
20
|
+
var DEFAULT_TRAVERSE_LIMIT = 64 << 20;
|
|
21
|
+
var LIST_SIZE_MASK = 7;
|
|
22
|
+
var MAX_BUFFER_DUMP_BYTES = 8192;
|
|
23
|
+
var MAX_INT32 = 2147483647;
|
|
24
|
+
var MAX_UINT32 = 4294967295;
|
|
25
|
+
var MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
|
26
|
+
var NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
|
|
27
|
+
var PACK_SPAN_THRESHOLD = 2;
|
|
28
|
+
var POINTER_DOUBLE_FAR_MASK = 4;
|
|
29
|
+
var POINTER_TYPE_MASK = 3;
|
|
30
|
+
var MAX_DEPTH = MAX_INT32;
|
|
31
|
+
var MAX_SEGMENT_LENGTH = MAX_UINT32;
|
|
32
|
+
var INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
|
33
|
+
function assertNever(n) {
|
|
34
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
|
35
|
+
}
|
|
36
|
+
__name(assertNever, "assertNever");
|
|
37
|
+
var MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
|
38
|
+
var MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
|
39
|
+
var MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
|
40
|
+
var MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
|
41
|
+
var NOT_IMPLEMENTED = "CAPNP-TS006 %s is not implemented.";
|
|
42
|
+
var PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
|
43
|
+
var PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
|
44
|
+
var PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
|
45
|
+
var PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
|
46
|
+
var PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
|
47
|
+
var PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
|
48
|
+
var PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
|
49
|
+
var PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
|
50
|
+
var 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).";
|
|
51
|
+
var PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
|
52
|
+
var 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).";
|
|
53
|
+
var PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
|
54
|
+
var PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
|
55
|
+
var PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
|
56
|
+
var PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
|
57
|
+
var SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
|
58
|
+
var SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
|
59
|
+
var SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
|
60
|
+
var SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
|
61
|
+
var SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
|
62
|
+
var TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
|
63
|
+
var LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
|
|
64
|
+
var LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
|
|
65
|
+
var RPC_NULL_CLIENT = "CAPNP-TS100 Call on null client.";
|
|
66
|
+
var RPC_CALL_QUEUE_FULL = "CAPNP-TS101 Promised answer call queue full.";
|
|
67
|
+
var RPC_QUEUE_CALL_CANCEL = "CAPNP-TS102 Queue call canceled.";
|
|
68
|
+
var RPC_ZERO_REF = "CAPNP-TS105 Ref() called on zeroed refcount.";
|
|
69
|
+
var RPC_IMPORT_CLOSED = "CAPNP-TS106 Call on closed import.";
|
|
70
|
+
var RPC_METHOD_NOT_IMPLEMENTED = "CAPNP-TS107 Method not implemented.";
|
|
71
|
+
var RPC_BAD_TARGET = "CAPNP-TS109 Target not found.";
|
|
72
|
+
var RPC_RETURN_FOR_UNKNOWN_QUESTION = "CAPNP-TS111 Received return for unknown question (id=%s).";
|
|
73
|
+
var RPC_QUESTION_ID_REUSED = "CAPNP-TS112 Attempted to re-use question id (%s).";
|
|
74
|
+
var RPC_UNKNOWN_EXPORT_ID = "CAPNP-TS113 Capability table references unknown export ID (%s).";
|
|
75
|
+
var RPC_UNKNOWN_ANSWER_ID = "CAPNP-TS114 Capability table references unknown answer ID (%s).";
|
|
76
|
+
var RPC_UNKNOWN_CAP_DESCRIPTOR = "CAPNP-TS115 Unknown cap descriptor type (which: %s).";
|
|
77
|
+
var RPC_METHOD_ERROR = "CAPNP-TS116 RPC method failed at %s.%s(): %s";
|
|
78
|
+
var RPC_ERROR = "CAPNP-TS117 RPC call failed, reason: %s";
|
|
79
|
+
var RPC_NO_MAIN_INTERFACE = "CAPNP-TS118 Received bootstrap message without main interface set.";
|
|
80
|
+
var RPC_FINISH_UNKNOWN_ANSWER = "CAPNP-TS119 Received finish message for unknown answer ID (%s).";
|
|
81
|
+
var RPC_FULFILL_ALREADY_CALLED = "CAPNP-TS120 Fulfill called more than once for question (%s).";
|
|
82
|
+
function bufferToHex(buffer) {
|
|
83
|
+
const a = new Uint8Array(buffer);
|
|
84
|
+
const h = [];
|
|
85
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
86
|
+
h.push(pad(a[i].toString(16), 2));
|
|
87
|
+
}
|
|
88
|
+
return `[${h.join(" ")}]`;
|
|
89
|
+
}
|
|
90
|
+
__name(bufferToHex, "bufferToHex");
|
|
91
|
+
function dumpBuffer(buffer) {
|
|
92
|
+
const b = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
93
|
+
const byteLength = Math.min(b.byteLength, MAX_BUFFER_DUMP_BYTES);
|
|
94
|
+
let r = format("\n=== buffer[%d] ===", byteLength);
|
|
95
|
+
for (let j = 0; j < byteLength; j += 16) {
|
|
96
|
+
r += `
|
|
97
|
+
${pad(j.toString(16), 8)}: `;
|
|
98
|
+
let s = "";
|
|
99
|
+
let k;
|
|
100
|
+
for (k = 0; k < 16 && j + k < b.byteLength; k++) {
|
|
101
|
+
const v = b[j + k];
|
|
102
|
+
r += `${pad(v.toString(16), 2)} `;
|
|
103
|
+
s += v > 31 && v < 255 ? String.fromCharCode(v) : "\xB7";
|
|
104
|
+
if (k === 7) {
|
|
105
|
+
r += " ";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
r += `${" ".repeat((17 - k) * 3)}${s}`;
|
|
109
|
+
}
|
|
110
|
+
r += "\n";
|
|
111
|
+
if (byteLength !== b.byteLength) {
|
|
112
|
+
r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
|
|
113
|
+
}
|
|
114
|
+
return r;
|
|
115
|
+
}
|
|
116
|
+
__name(dumpBuffer, "dumpBuffer");
|
|
117
|
+
function format(s, ...args) {
|
|
118
|
+
const n = s.length;
|
|
119
|
+
let arg;
|
|
120
|
+
let argIndex = 0;
|
|
121
|
+
let c;
|
|
122
|
+
let escaped = false;
|
|
123
|
+
let i = 0;
|
|
124
|
+
let leadingZero = false;
|
|
125
|
+
let precision;
|
|
126
|
+
let result = "";
|
|
127
|
+
function nextArg() {
|
|
128
|
+
return args[argIndex++];
|
|
129
|
+
}
|
|
130
|
+
__name(nextArg, "nextArg");
|
|
131
|
+
function slurpNumber() {
|
|
132
|
+
let digits = "";
|
|
133
|
+
while (/\d/.test(s[i])) {
|
|
134
|
+
digits += s[i++];
|
|
135
|
+
c = s[i];
|
|
136
|
+
}
|
|
137
|
+
return digits.length > 0 ? Number.parseInt(digits, 10) : null;
|
|
138
|
+
}
|
|
139
|
+
__name(slurpNumber, "slurpNumber");
|
|
140
|
+
for (; i < n; ++i) {
|
|
141
|
+
c = s[i];
|
|
142
|
+
if (escaped) {
|
|
143
|
+
escaped = false;
|
|
144
|
+
if (c === ".") {
|
|
145
|
+
leadingZero = false;
|
|
146
|
+
c = s[++i];
|
|
147
|
+
} else if (c === "0" && s[i + 1] === ".") {
|
|
148
|
+
leadingZero = true;
|
|
149
|
+
i += 2;
|
|
150
|
+
c = s[i];
|
|
151
|
+
} else {
|
|
152
|
+
leadingZero = true;
|
|
153
|
+
}
|
|
154
|
+
precision = slurpNumber();
|
|
155
|
+
switch (c) {
|
|
156
|
+
case "a": {
|
|
157
|
+
result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case "b": {
|
|
161
|
+
result += Number.parseInt(String(nextArg()), 10).toString(2);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "c": {
|
|
165
|
+
arg = nextArg();
|
|
166
|
+
result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "d": {
|
|
170
|
+
result += Number.parseInt(String(nextArg()), 10);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case "f": {
|
|
174
|
+
const tmp = Number.parseFloat(String(nextArg())).toFixed(
|
|
175
|
+
precision || 6
|
|
176
|
+
);
|
|
177
|
+
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "j": {
|
|
181
|
+
result += JSON.stringify(nextArg());
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "o": {
|
|
185
|
+
result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case "s": {
|
|
189
|
+
result += nextArg();
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "x": {
|
|
193
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "X": {
|
|
197
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
default: {
|
|
201
|
+
result += c;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
} else if (c === "%") {
|
|
206
|
+
escaped = true;
|
|
207
|
+
} else {
|
|
208
|
+
result += c;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
__name(format, "format");
|
|
214
|
+
function pad(v, width, pad2 = "0") {
|
|
215
|
+
return v.length >= width ? v : Array.from({ length: width - v.length + 1 }).join(pad2) + v;
|
|
216
|
+
}
|
|
217
|
+
__name(pad, "pad");
|
|
218
|
+
function padToWord$1(size) {
|
|
219
|
+
return size + 7 & -8;
|
|
220
|
+
}
|
|
221
|
+
__name(padToWord$1, "padToWord$1");
|
|
222
|
+
var ObjectSize = class {
|
|
223
|
+
static {
|
|
224
|
+
__name(this, "ObjectSize");
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Creates a new ObjectSize instance.
|
|
228
|
+
*
|
|
229
|
+
* @param dataByteLength - The number of bytes in the data section of the struct
|
|
230
|
+
* @param pointerLength - The number of pointers in the pointer section of the struct
|
|
231
|
+
*/
|
|
232
|
+
constructor(dataByteLength, pointerLength) {
|
|
233
|
+
this.dataByteLength = dataByteLength;
|
|
234
|
+
this.pointerLength = pointerLength;
|
|
235
|
+
}
|
|
236
|
+
toString() {
|
|
237
|
+
return format(
|
|
238
|
+
"ObjectSize_dw:%d,pc:%d",
|
|
239
|
+
getDataWordLength(this),
|
|
240
|
+
this.pointerLength
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function getByteLength(o) {
|
|
245
|
+
return o.dataByteLength + o.pointerLength * 8;
|
|
246
|
+
}
|
|
247
|
+
__name(getByteLength, "getByteLength");
|
|
248
|
+
function getDataWordLength(o) {
|
|
249
|
+
return o.dataByteLength / 8;
|
|
250
|
+
}
|
|
251
|
+
__name(getDataWordLength, "getDataWordLength");
|
|
252
|
+
function getWordLength(o) {
|
|
253
|
+
return o.dataByteLength / 8 + o.pointerLength;
|
|
254
|
+
}
|
|
255
|
+
__name(getWordLength, "getWordLength");
|
|
256
|
+
function padToWord(o) {
|
|
257
|
+
return new ObjectSize(padToWord$1(o.dataByteLength), o.pointerLength);
|
|
258
|
+
}
|
|
259
|
+
__name(padToWord, "padToWord");
|
|
260
|
+
var Orphan = class {
|
|
261
|
+
static {
|
|
262
|
+
__name(this, "Orphan");
|
|
263
|
+
}
|
|
264
|
+
/** If this member is not present then the orphan has already been adopted, or something went very wrong. */
|
|
265
|
+
_capnp;
|
|
266
|
+
byteOffset;
|
|
267
|
+
segment;
|
|
268
|
+
constructor(src) {
|
|
269
|
+
const c = getContent(src);
|
|
270
|
+
this.segment = c.segment;
|
|
271
|
+
this.byteOffset = c.byteOffset;
|
|
272
|
+
this._capnp = {};
|
|
273
|
+
this._capnp.type = getTargetPointerType(src);
|
|
274
|
+
switch (this._capnp.type) {
|
|
275
|
+
case PointerType.STRUCT: {
|
|
276
|
+
this._capnp.size = getTargetStructSize(src);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case PointerType.LIST: {
|
|
280
|
+
this._capnp.length = getTargetListLength(src);
|
|
281
|
+
this._capnp.elementSize = getTargetListElementSize(src);
|
|
282
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
283
|
+
this._capnp.size = getTargetCompositeListSize(src);
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case PointerType.OTHER: {
|
|
288
|
+
this._capnp.capId = getCapabilityId(src);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
default: {
|
|
292
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
erasePointer(src);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed.
|
|
299
|
+
*
|
|
300
|
+
* @param dst The destination pointer.
|
|
301
|
+
*/
|
|
302
|
+
_moveTo(dst) {
|
|
303
|
+
if (this._capnp === void 0) {
|
|
304
|
+
throw new Error(format(PTR_ALREADY_ADOPTED, this));
|
|
305
|
+
}
|
|
306
|
+
if (this.segment.message !== dst.segment.message) {
|
|
307
|
+
throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst));
|
|
308
|
+
}
|
|
309
|
+
erase(dst);
|
|
310
|
+
const res = initPointer(this.segment, this.byteOffset, dst);
|
|
311
|
+
switch (this._capnp.type) {
|
|
312
|
+
case PointerType.STRUCT: {
|
|
313
|
+
setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case PointerType.LIST: {
|
|
317
|
+
let { offsetWords } = res;
|
|
318
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
319
|
+
offsetWords--;
|
|
320
|
+
}
|
|
321
|
+
setListPointer(
|
|
322
|
+
offsetWords,
|
|
323
|
+
this._capnp.elementSize,
|
|
324
|
+
this._capnp.length,
|
|
325
|
+
res.pointer,
|
|
326
|
+
this._capnp.size
|
|
327
|
+
);
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case PointerType.OTHER: {
|
|
331
|
+
setInterfacePointer(this._capnp.capId, res.pointer);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
/* istanbul ignore next */
|
|
335
|
+
default: {
|
|
336
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this._capnp = void 0;
|
|
340
|
+
}
|
|
341
|
+
dispose() {
|
|
342
|
+
if (this._capnp === void 0) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
switch (this._capnp.type) {
|
|
346
|
+
case PointerType.STRUCT: {
|
|
347
|
+
this.segment.fillZeroWords(
|
|
348
|
+
this.byteOffset,
|
|
349
|
+
getWordLength(this._capnp.size)
|
|
350
|
+
);
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
case PointerType.LIST: {
|
|
354
|
+
const byteLength = getListByteLength(
|
|
355
|
+
this._capnp.elementSize,
|
|
356
|
+
this._capnp.length,
|
|
357
|
+
this._capnp.size
|
|
358
|
+
);
|
|
359
|
+
this.segment.fillZeroWords(this.byteOffset, byteLength);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
this._capnp = void 0;
|
|
364
|
+
}
|
|
365
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
366
|
+
return format(
|
|
367
|
+
"Orphan_%d@%a,type:%s",
|
|
368
|
+
this.segment.id,
|
|
369
|
+
this.byteOffset,
|
|
370
|
+
this._capnp && this._capnp.type
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
function adopt(src, p) {
|
|
375
|
+
src._moveTo(p);
|
|
376
|
+
}
|
|
377
|
+
__name(adopt, "adopt");
|
|
378
|
+
function disown(p) {
|
|
379
|
+
return new Orphan(p);
|
|
380
|
+
}
|
|
381
|
+
__name(disown, "disown");
|
|
382
|
+
function dump(p) {
|
|
383
|
+
return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8));
|
|
384
|
+
}
|
|
385
|
+
__name(dump, "dump");
|
|
386
|
+
function getListByteLength(elementSize, length, compositeSize) {
|
|
387
|
+
switch (elementSize) {
|
|
388
|
+
case ListElementSize.BIT: {
|
|
389
|
+
return padToWord$1(length + 7 >>> 3);
|
|
390
|
+
}
|
|
391
|
+
case ListElementSize.BYTE:
|
|
392
|
+
case ListElementSize.BYTE_2:
|
|
393
|
+
case ListElementSize.BYTE_4:
|
|
394
|
+
case ListElementSize.BYTE_8:
|
|
395
|
+
case ListElementSize.POINTER:
|
|
396
|
+
case ListElementSize.VOID: {
|
|
397
|
+
return padToWord$1(getListElementByteLength(elementSize) * length);
|
|
398
|
+
}
|
|
399
|
+
/* istanbul ignore next */
|
|
400
|
+
case ListElementSize.COMPOSITE: {
|
|
401
|
+
if (compositeSize === void 0) {
|
|
402
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));
|
|
403
|
+
}
|
|
404
|
+
return length * padToWord$1(getByteLength(compositeSize));
|
|
405
|
+
}
|
|
406
|
+
/* istanbul ignore next */
|
|
407
|
+
default: {
|
|
408
|
+
throw new Error(PTR_INVALID_LIST_SIZE);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
__name(getListByteLength, "getListByteLength");
|
|
413
|
+
function getListElementByteLength(elementSize) {
|
|
414
|
+
switch (elementSize) {
|
|
415
|
+
/* istanbul ignore next */
|
|
416
|
+
case ListElementSize.BIT: {
|
|
417
|
+
return Number.NaN;
|
|
418
|
+
}
|
|
419
|
+
case ListElementSize.BYTE: {
|
|
420
|
+
return 1;
|
|
421
|
+
}
|
|
422
|
+
case ListElementSize.BYTE_2: {
|
|
423
|
+
return 2;
|
|
424
|
+
}
|
|
425
|
+
case ListElementSize.BYTE_4: {
|
|
426
|
+
return 4;
|
|
427
|
+
}
|
|
428
|
+
case ListElementSize.BYTE_8:
|
|
429
|
+
case ListElementSize.POINTER: {
|
|
430
|
+
return 8;
|
|
431
|
+
}
|
|
432
|
+
/* istanbul ignore next */
|
|
433
|
+
case ListElementSize.COMPOSITE: {
|
|
434
|
+
return Number.NaN;
|
|
435
|
+
}
|
|
436
|
+
/* istanbul ignore next */
|
|
437
|
+
case ListElementSize.VOID: {
|
|
438
|
+
return 0;
|
|
439
|
+
}
|
|
440
|
+
/* istanbul ignore next */
|
|
441
|
+
default: {
|
|
442
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
__name(getListElementByteLength, "getListElementByteLength");
|
|
447
|
+
function add(offset, p) {
|
|
448
|
+
return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit);
|
|
449
|
+
}
|
|
450
|
+
__name(add, "add");
|
|
451
|
+
function copyFrom(src, p) {
|
|
452
|
+
if (p.segment === src.segment && p.byteOffset === src.byteOffset) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
erase(p);
|
|
456
|
+
if (isNull(src)) return;
|
|
457
|
+
switch (getTargetPointerType(src)) {
|
|
458
|
+
case PointerType.STRUCT: {
|
|
459
|
+
copyFromStruct(src, p);
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
case PointerType.LIST: {
|
|
463
|
+
copyFromList(src, p);
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
case PointerType.OTHER: {
|
|
467
|
+
copyFromInterface(src, p);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
/* istanbul ignore next */
|
|
471
|
+
default: {
|
|
472
|
+
throw new Error(
|
|
473
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
__name(copyFrom, "copyFrom");
|
|
479
|
+
function erase(p) {
|
|
480
|
+
if (isNull(p)) return;
|
|
481
|
+
let c;
|
|
482
|
+
switch (getTargetPointerType(p)) {
|
|
483
|
+
case PointerType.STRUCT: {
|
|
484
|
+
const size = getTargetStructSize(p);
|
|
485
|
+
c = getContent(p);
|
|
486
|
+
c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
|
|
487
|
+
for (let i = 0; i < size.pointerLength; i++) {
|
|
488
|
+
erase(add(i * 8, c));
|
|
489
|
+
}
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
case PointerType.LIST: {
|
|
493
|
+
const elementSize = getTargetListElementSize(p);
|
|
494
|
+
const length = getTargetListLength(p);
|
|
495
|
+
let contentWords = padToWord$1(
|
|
496
|
+
length * getListElementByteLength(elementSize)
|
|
497
|
+
);
|
|
498
|
+
c = getContent(p);
|
|
499
|
+
if (elementSize === ListElementSize.POINTER) {
|
|
500
|
+
for (let i = 0; i < length; i++) {
|
|
501
|
+
erase(
|
|
502
|
+
new Pointer(
|
|
503
|
+
c.segment,
|
|
504
|
+
c.byteOffset + i * 8,
|
|
505
|
+
p._capnp.depthLimit - 1
|
|
506
|
+
)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
break;
|
|
510
|
+
} else if (elementSize === ListElementSize.COMPOSITE) {
|
|
511
|
+
const tag = add(-8, c);
|
|
512
|
+
const compositeSize = getStructSize(tag);
|
|
513
|
+
const compositeByteLength = getByteLength(compositeSize);
|
|
514
|
+
contentWords = getOffsetWords(tag);
|
|
515
|
+
c.segment.setWordZero(c.byteOffset - 8);
|
|
516
|
+
for (let i = 0; i < length; i++) {
|
|
517
|
+
for (let j = 0; j < compositeSize.pointerLength; j++) {
|
|
518
|
+
erase(
|
|
519
|
+
new Pointer(
|
|
520
|
+
c.segment,
|
|
521
|
+
c.byteOffset + i * compositeByteLength + j * 8,
|
|
522
|
+
p._capnp.depthLimit - 1
|
|
523
|
+
)
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
c.segment.fillZeroWords(c.byteOffset, contentWords);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
case PointerType.OTHER: {
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
default: {
|
|
535
|
+
throw new Error(
|
|
536
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
erasePointer(p);
|
|
541
|
+
}
|
|
542
|
+
__name(erase, "erase");
|
|
543
|
+
function erasePointer(p) {
|
|
544
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
545
|
+
const landingPad = followFar(p);
|
|
546
|
+
if (isDoubleFar(p)) {
|
|
547
|
+
landingPad.segment.setWordZero(landingPad.byteOffset + 8);
|
|
548
|
+
}
|
|
549
|
+
landingPad.segment.setWordZero(landingPad.byteOffset);
|
|
550
|
+
}
|
|
551
|
+
p.segment.setWordZero(p.byteOffset);
|
|
552
|
+
}
|
|
553
|
+
__name(erasePointer, "erasePointer");
|
|
554
|
+
function followFar(p) {
|
|
555
|
+
const targetSegment = p.segment.message.getSegment(
|
|
556
|
+
p.segment.getUint32(p.byteOffset + 4)
|
|
557
|
+
);
|
|
558
|
+
const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;
|
|
559
|
+
return new Pointer(
|
|
560
|
+
targetSegment,
|
|
561
|
+
targetWordOffset * 8,
|
|
562
|
+
p._capnp.depthLimit - 1
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
__name(followFar, "followFar");
|
|
566
|
+
function followFars(p) {
|
|
567
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
568
|
+
const landingPad = followFar(p);
|
|
569
|
+
if (isDoubleFar(p)) {
|
|
570
|
+
landingPad.byteOffset += 8;
|
|
571
|
+
}
|
|
572
|
+
return landingPad;
|
|
573
|
+
}
|
|
574
|
+
return p;
|
|
575
|
+
}
|
|
576
|
+
__name(followFars, "followFars");
|
|
577
|
+
function getCapabilityId(p) {
|
|
578
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
579
|
+
}
|
|
580
|
+
__name(getCapabilityId, "getCapabilityId");
|
|
581
|
+
function isCompositeList(p) {
|
|
582
|
+
return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
|
|
583
|
+
}
|
|
584
|
+
__name(isCompositeList, "isCompositeList");
|
|
585
|
+
function getContent(p, ignoreCompositeIndex) {
|
|
586
|
+
let c;
|
|
587
|
+
if (isDoubleFar(p)) {
|
|
588
|
+
const landingPad = followFar(p);
|
|
589
|
+
c = new Pointer(
|
|
590
|
+
p.segment.message.getSegment(getFarSegmentId(landingPad)),
|
|
591
|
+
getOffsetWords(landingPad) * 8
|
|
592
|
+
);
|
|
593
|
+
} else {
|
|
594
|
+
const target = followFars(p);
|
|
595
|
+
c = new Pointer(
|
|
596
|
+
target.segment,
|
|
597
|
+
target.byteOffset + 8 + getOffsetWords(target) * 8
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
if (isCompositeList(p)) {
|
|
601
|
+
c.byteOffset += 8;
|
|
602
|
+
}
|
|
603
|
+
if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
|
|
604
|
+
c.byteOffset -= 8;
|
|
605
|
+
c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
|
|
606
|
+
}
|
|
607
|
+
return c;
|
|
608
|
+
}
|
|
609
|
+
__name(getContent, "getContent");
|
|
610
|
+
function getFarSegmentId(p) {
|
|
611
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
612
|
+
}
|
|
613
|
+
__name(getFarSegmentId, "getFarSegmentId");
|
|
614
|
+
function getListElementSize(p) {
|
|
615
|
+
return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
|
|
616
|
+
}
|
|
617
|
+
__name(getListElementSize, "getListElementSize");
|
|
618
|
+
function getListLength(p) {
|
|
619
|
+
return p.segment.getUint32(p.byteOffset + 4) >>> 3;
|
|
620
|
+
}
|
|
621
|
+
__name(getListLength, "getListLength");
|
|
622
|
+
function getOffsetWords(p) {
|
|
623
|
+
const o = p.segment.getInt32(p.byteOffset);
|
|
624
|
+
return o & 2 ? o >> 3 : o >> 2;
|
|
625
|
+
}
|
|
626
|
+
__name(getOffsetWords, "getOffsetWords");
|
|
627
|
+
function getPointerType(p) {
|
|
628
|
+
return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
|
|
629
|
+
}
|
|
630
|
+
__name(getPointerType, "getPointerType");
|
|
631
|
+
function getStructDataWords(p) {
|
|
632
|
+
return p.segment.getUint16(p.byteOffset + 4);
|
|
633
|
+
}
|
|
634
|
+
__name(getStructDataWords, "getStructDataWords");
|
|
635
|
+
function getStructPointerLength(p) {
|
|
636
|
+
return p.segment.getUint16(p.byteOffset + 6);
|
|
637
|
+
}
|
|
638
|
+
__name(getStructPointerLength, "getStructPointerLength");
|
|
639
|
+
function getStructSize(p) {
|
|
640
|
+
return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
|
|
641
|
+
}
|
|
642
|
+
__name(getStructSize, "getStructSize");
|
|
643
|
+
function getTargetCompositeListTag(p) {
|
|
644
|
+
const c = getContent(p);
|
|
645
|
+
c.byteOffset -= 8;
|
|
646
|
+
return c;
|
|
647
|
+
}
|
|
648
|
+
__name(getTargetCompositeListTag, "getTargetCompositeListTag");
|
|
649
|
+
function getTargetCompositeListSize(p) {
|
|
650
|
+
return getStructSize(getTargetCompositeListTag(p));
|
|
651
|
+
}
|
|
652
|
+
__name(getTargetCompositeListSize, "getTargetCompositeListSize");
|
|
653
|
+
function getTargetListElementSize(p) {
|
|
654
|
+
return getListElementSize(followFars(p));
|
|
655
|
+
}
|
|
656
|
+
__name(getTargetListElementSize, "getTargetListElementSize");
|
|
657
|
+
function getTargetListLength(p) {
|
|
658
|
+
const t = followFars(p);
|
|
659
|
+
if (getListElementSize(t) === ListElementSize.COMPOSITE) {
|
|
660
|
+
return getOffsetWords(getTargetCompositeListTag(p));
|
|
661
|
+
}
|
|
662
|
+
return getListLength(t);
|
|
663
|
+
}
|
|
664
|
+
__name(getTargetListLength, "getTargetListLength");
|
|
665
|
+
function getTargetPointerType(p) {
|
|
666
|
+
const t = getPointerType(followFars(p));
|
|
667
|
+
if (t === PointerType.FAR) {
|
|
668
|
+
throw new Error(format(PTR_INVALID_FAR_TARGET, p));
|
|
669
|
+
}
|
|
670
|
+
return t;
|
|
671
|
+
}
|
|
672
|
+
__name(getTargetPointerType, "getTargetPointerType");
|
|
673
|
+
function getTargetStructSize(p) {
|
|
674
|
+
return getStructSize(followFars(p));
|
|
675
|
+
}
|
|
676
|
+
__name(getTargetStructSize, "getTargetStructSize");
|
|
677
|
+
function initPointer(contentSegment, contentOffset, p) {
|
|
678
|
+
if (p.segment !== contentSegment) {
|
|
679
|
+
if (!contentSegment.hasCapacity(8)) {
|
|
680
|
+
const landingPad2 = p.segment.allocate(16);
|
|
681
|
+
setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
|
|
682
|
+
setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
|
|
683
|
+
landingPad2.byteOffset += 8;
|
|
684
|
+
return new PointerAllocationResult(landingPad2, 0);
|
|
685
|
+
}
|
|
686
|
+
const landingPad = contentSegment.allocate(8);
|
|
687
|
+
if (landingPad.segment.id !== contentSegment.id) {
|
|
688
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
|
689
|
+
}
|
|
690
|
+
setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
|
|
691
|
+
return new PointerAllocationResult(
|
|
692
|
+
landingPad,
|
|
693
|
+
(contentOffset - landingPad.byteOffset - 8) / 8
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
|
|
697
|
+
}
|
|
698
|
+
__name(initPointer, "initPointer");
|
|
699
|
+
function isDoubleFar(p) {
|
|
700
|
+
return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
|
|
701
|
+
}
|
|
702
|
+
__name(isDoubleFar, "isDoubleFar");
|
|
703
|
+
function isNull(p) {
|
|
704
|
+
return p.segment.isWordZero(p.byteOffset);
|
|
705
|
+
}
|
|
706
|
+
__name(isNull, "isNull");
|
|
707
|
+
function relocateTo(dst, src) {
|
|
708
|
+
const t = followFars(src);
|
|
709
|
+
const lo = t.segment.getUint8(t.byteOffset) & 3;
|
|
710
|
+
const hi = t.segment.getUint32(t.byteOffset + 4);
|
|
711
|
+
erase(dst);
|
|
712
|
+
const res = initPointer(
|
|
713
|
+
t.segment,
|
|
714
|
+
t.byteOffset + 8 + getOffsetWords(t) * 8,
|
|
715
|
+
dst
|
|
716
|
+
);
|
|
717
|
+
res.pointer.segment.setUint32(
|
|
718
|
+
res.pointer.byteOffset,
|
|
719
|
+
lo | res.offsetWords << 2
|
|
720
|
+
);
|
|
721
|
+
res.pointer.segment.setUint32(res.pointer.byteOffset + 4, hi);
|
|
722
|
+
erasePointer(src);
|
|
723
|
+
}
|
|
724
|
+
__name(relocateTo, "relocateTo");
|
|
725
|
+
function setFarPointer(doubleFar, offsetWords, segmentId, p) {
|
|
726
|
+
const A = PointerType.FAR;
|
|
727
|
+
const B = doubleFar ? 1 : 0;
|
|
728
|
+
const C = offsetWords;
|
|
729
|
+
const D = segmentId;
|
|
730
|
+
p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
|
|
731
|
+
p.segment.setUint32(p.byteOffset + 4, D);
|
|
732
|
+
}
|
|
733
|
+
__name(setFarPointer, "setFarPointer");
|
|
734
|
+
function setInterfacePointer(capId, p) {
|
|
735
|
+
p.segment.setUint32(p.byteOffset, PointerType.OTHER);
|
|
736
|
+
p.segment.setUint32(p.byteOffset + 4, capId);
|
|
737
|
+
}
|
|
738
|
+
__name(setInterfacePointer, "setInterfacePointer");
|
|
739
|
+
function getInterfacePointer(p) {
|
|
740
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
741
|
+
}
|
|
742
|
+
__name(getInterfacePointer, "getInterfacePointer");
|
|
743
|
+
function setListPointer(offsetWords, size, length, p, compositeSize) {
|
|
744
|
+
const A = PointerType.LIST;
|
|
745
|
+
const B = offsetWords;
|
|
746
|
+
const C = size;
|
|
747
|
+
let D = length;
|
|
748
|
+
if (size === ListElementSize.COMPOSITE) {
|
|
749
|
+
if (compositeSize === void 0) {
|
|
750
|
+
throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
|
|
751
|
+
}
|
|
752
|
+
D *= getWordLength(compositeSize);
|
|
753
|
+
}
|
|
754
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
755
|
+
p.segment.setUint32(p.byteOffset + 4, C | D << 3);
|
|
756
|
+
}
|
|
757
|
+
__name(setListPointer, "setListPointer");
|
|
758
|
+
function setStructPointer(offsetWords, size, p) {
|
|
759
|
+
const A = PointerType.STRUCT;
|
|
760
|
+
const B = offsetWords;
|
|
761
|
+
const C = getDataWordLength(size);
|
|
762
|
+
const D = size.pointerLength;
|
|
763
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
764
|
+
p.segment.setUint16(p.byteOffset + 4, C);
|
|
765
|
+
p.segment.setUint16(p.byteOffset + 6, D);
|
|
766
|
+
}
|
|
767
|
+
__name(setStructPointer, "setStructPointer");
|
|
768
|
+
function validate(pointerType, p, elementSize) {
|
|
769
|
+
if (isNull(p)) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
const t = followFars(p);
|
|
773
|
+
const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;
|
|
774
|
+
if (A !== pointerType) {
|
|
775
|
+
throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
|
|
776
|
+
}
|
|
777
|
+
if (elementSize !== void 0) {
|
|
778
|
+
const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;
|
|
779
|
+
if (C !== elementSize) {
|
|
780
|
+
throw new Error(
|
|
781
|
+
format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
__name(validate, "validate");
|
|
787
|
+
function copyFromInterface(src, dst) {
|
|
788
|
+
const srcCapId = getInterfacePointer(src);
|
|
789
|
+
if (srcCapId < 0) {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const srcCapTable = src.segment.message._capnp.capTable;
|
|
793
|
+
if (!srcCapTable) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
const client = srcCapTable[srcCapId];
|
|
797
|
+
if (!client) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const dstCapId = dst.segment.message.addCap(client);
|
|
801
|
+
setInterfacePointer(dstCapId, dst);
|
|
802
|
+
}
|
|
803
|
+
__name(copyFromInterface, "copyFromInterface");
|
|
804
|
+
function copyFromList(src, dst) {
|
|
805
|
+
if (dst._capnp.depthLimit <= 0) {
|
|
806
|
+
throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);
|
|
807
|
+
}
|
|
808
|
+
const srcContent = getContent(src);
|
|
809
|
+
const srcElementSize = getTargetListElementSize(src);
|
|
810
|
+
const srcLength = getTargetListLength(src);
|
|
811
|
+
let srcCompositeSize;
|
|
812
|
+
let srcStructByteLength;
|
|
813
|
+
let dstContent;
|
|
814
|
+
if (srcElementSize === ListElementSize.POINTER) {
|
|
815
|
+
dstContent = dst.segment.allocate(srcLength << 3);
|
|
816
|
+
for (let i = 0; i < srcLength; i++) {
|
|
817
|
+
const srcPtr = new Pointer(
|
|
818
|
+
srcContent.segment,
|
|
819
|
+
srcContent.byteOffset + (i << 3),
|
|
820
|
+
src._capnp.depthLimit - 1
|
|
821
|
+
);
|
|
822
|
+
const dstPtr = new Pointer(
|
|
823
|
+
dstContent.segment,
|
|
824
|
+
dstContent.byteOffset + (i << 3),
|
|
825
|
+
dst._capnp.depthLimit - 1
|
|
826
|
+
);
|
|
827
|
+
copyFrom(srcPtr, dstPtr);
|
|
828
|
+
}
|
|
829
|
+
} else if (srcElementSize === ListElementSize.COMPOSITE) {
|
|
830
|
+
srcCompositeSize = padToWord(getTargetCompositeListSize(src));
|
|
831
|
+
srcStructByteLength = getByteLength(srcCompositeSize);
|
|
832
|
+
dstContent = dst.segment.allocate(
|
|
833
|
+
getByteLength(srcCompositeSize) * srcLength + 8
|
|
834
|
+
);
|
|
835
|
+
dstContent.segment.copyWord(
|
|
836
|
+
dstContent.byteOffset,
|
|
837
|
+
srcContent.segment,
|
|
838
|
+
srcContent.byteOffset - 8
|
|
839
|
+
);
|
|
840
|
+
if (srcCompositeSize.dataByteLength > 0) {
|
|
841
|
+
const wordLength = getWordLength(srcCompositeSize) * srcLength;
|
|
842
|
+
dstContent.segment.copyWords(
|
|
843
|
+
dstContent.byteOffset + 8,
|
|
844
|
+
srcContent.segment,
|
|
845
|
+
srcContent.byteOffset,
|
|
846
|
+
wordLength
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
for (let i = 0; i < srcLength; i++) {
|
|
850
|
+
for (let j = 0; j < srcCompositeSize.pointerLength; j++) {
|
|
851
|
+
const offset = i * srcStructByteLength + srcCompositeSize.dataByteLength + (j << 3);
|
|
852
|
+
const srcPtr = new Pointer(
|
|
853
|
+
srcContent.segment,
|
|
854
|
+
srcContent.byteOffset + offset,
|
|
855
|
+
src._capnp.depthLimit - 1
|
|
856
|
+
);
|
|
857
|
+
const dstPtr = new Pointer(
|
|
858
|
+
dstContent.segment,
|
|
859
|
+
dstContent.byteOffset + offset + 8,
|
|
860
|
+
dst._capnp.depthLimit - 1
|
|
861
|
+
);
|
|
862
|
+
copyFrom(srcPtr, dstPtr);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
} else {
|
|
866
|
+
const byteLength = padToWord$1(
|
|
867
|
+
srcElementSize === ListElementSize.BIT ? srcLength + 7 >>> 3 : getListElementByteLength(srcElementSize) * srcLength
|
|
868
|
+
);
|
|
869
|
+
const wordLength = byteLength >>> 3;
|
|
870
|
+
dstContent = dst.segment.allocate(byteLength);
|
|
871
|
+
dstContent.segment.copyWords(
|
|
872
|
+
dstContent.byteOffset,
|
|
873
|
+
srcContent.segment,
|
|
874
|
+
srcContent.byteOffset,
|
|
875
|
+
wordLength
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);
|
|
879
|
+
setListPointer(
|
|
880
|
+
res.offsetWords,
|
|
881
|
+
srcElementSize,
|
|
882
|
+
srcLength,
|
|
883
|
+
res.pointer,
|
|
884
|
+
srcCompositeSize
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
__name(copyFromList, "copyFromList");
|
|
888
|
+
function copyFromStruct(src, dst) {
|
|
889
|
+
if (dst._capnp.depthLimit <= 0) {
|
|
890
|
+
throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);
|
|
891
|
+
}
|
|
892
|
+
const srcContent = getContent(src);
|
|
893
|
+
const srcSize = getTargetStructSize(src);
|
|
894
|
+
const srcDataWordLength = getDataWordLength(srcSize);
|
|
895
|
+
const dstContent = dst.segment.allocate(getByteLength(srcSize));
|
|
896
|
+
dstContent.segment.copyWords(
|
|
897
|
+
dstContent.byteOffset,
|
|
898
|
+
srcContent.segment,
|
|
899
|
+
srcContent.byteOffset,
|
|
900
|
+
srcDataWordLength
|
|
901
|
+
);
|
|
902
|
+
for (let i = 0; i < srcSize.pointerLength; i++) {
|
|
903
|
+
const offset = srcSize.dataByteLength + i * 8;
|
|
904
|
+
const srcPtr = new Pointer(
|
|
905
|
+
srcContent.segment,
|
|
906
|
+
srcContent.byteOffset + offset,
|
|
907
|
+
src._capnp.depthLimit - 1
|
|
908
|
+
);
|
|
909
|
+
const dstPtr = new Pointer(
|
|
910
|
+
dstContent.segment,
|
|
911
|
+
dstContent.byteOffset + offset,
|
|
912
|
+
dst._capnp.depthLimit - 1
|
|
913
|
+
);
|
|
914
|
+
copyFrom(srcPtr, dstPtr);
|
|
915
|
+
}
|
|
916
|
+
if (dst._capnp.compositeList) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);
|
|
920
|
+
setStructPointer(res.offsetWords, srcSize, res.pointer);
|
|
921
|
+
}
|
|
922
|
+
__name(copyFromStruct, "copyFromStruct");
|
|
923
|
+
function trackPointerAllocation(message, p) {
|
|
924
|
+
message._capnp.traversalLimit -= 8;
|
|
925
|
+
if (message._capnp.traversalLimit <= 0) {
|
|
926
|
+
throw new Error(format(PTR_TRAVERSAL_LIMIT_EXCEEDED, p));
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
__name(trackPointerAllocation, "trackPointerAllocation");
|
|
930
|
+
var PointerAllocationResult = class {
|
|
931
|
+
static {
|
|
932
|
+
__name(this, "PointerAllocationResult");
|
|
933
|
+
}
|
|
934
|
+
constructor(pointer, offsetWords) {
|
|
935
|
+
this.pointer = pointer;
|
|
936
|
+
this.offsetWords = offsetWords;
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
var PointerType = /* @__PURE__ */ ((PointerType2) => {
|
|
940
|
+
PointerType2[PointerType2["STRUCT"] = 0] = "STRUCT";
|
|
941
|
+
PointerType2[PointerType2["LIST"] = 1] = "LIST";
|
|
942
|
+
PointerType2[PointerType2["FAR"] = 2] = "FAR";
|
|
943
|
+
PointerType2[PointerType2["OTHER"] = 3] = "OTHER";
|
|
944
|
+
return PointerType2;
|
|
945
|
+
})(PointerType || {});
|
|
946
|
+
var Pointer = class {
|
|
947
|
+
static {
|
|
948
|
+
__name(this, "Pointer");
|
|
949
|
+
}
|
|
950
|
+
static _capnp = {
|
|
951
|
+
displayName: "Pointer"
|
|
952
|
+
};
|
|
953
|
+
_capnp;
|
|
954
|
+
/** Offset, in bytes, from the start of the segment to the beginning of this pointer. */
|
|
955
|
+
byteOffset;
|
|
956
|
+
/**
|
|
957
|
+
* The starting segment for this pointer's data. In the case of a far pointer, the actual content this pointer is
|
|
958
|
+
* referencing will be in another segment within the same message.
|
|
959
|
+
*/
|
|
960
|
+
segment;
|
|
961
|
+
constructor(segment, byteOffset, depthLimit = MAX_DEPTH) {
|
|
962
|
+
this._capnp = { compositeList: false, depthLimit };
|
|
963
|
+
this.segment = segment;
|
|
964
|
+
this.byteOffset = byteOffset;
|
|
965
|
+
if (depthLimit < 1) {
|
|
966
|
+
throw new Error(format(PTR_DEPTH_LIMIT_EXCEEDED, this));
|
|
967
|
+
}
|
|
968
|
+
trackPointerAllocation(segment.message, this);
|
|
969
|
+
if (byteOffset < 0 || byteOffset > segment.byteLength) {
|
|
970
|
+
throw new Error(format(PTR_OFFSET_OUT_OF_BOUNDS, byteOffset));
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
[Symbol.toStringTag]() {
|
|
974
|
+
return format("Pointer_%d", this.segment.id);
|
|
975
|
+
}
|
|
976
|
+
toString() {
|
|
977
|
+
return format("->%d@%a%s", this.segment.id, this.byteOffset, dump(this));
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
var List = class _List extends Pointer {
|
|
981
|
+
static {
|
|
982
|
+
__name(this, "List");
|
|
983
|
+
}
|
|
984
|
+
static _capnp = {
|
|
985
|
+
displayName: "List<Generic>",
|
|
986
|
+
size: ListElementSize.VOID
|
|
987
|
+
};
|
|
988
|
+
constructor(segment, byteOffset, depthLimit) {
|
|
989
|
+
super(segment, byteOffset, depthLimit);
|
|
990
|
+
return new Proxy(this, _List.#proxyHandler);
|
|
991
|
+
}
|
|
992
|
+
static #proxyHandler = {
|
|
993
|
+
get(target, prop, receiver) {
|
|
994
|
+
const val = Reflect.get(target, prop, receiver);
|
|
995
|
+
if (val !== void 0) {
|
|
996
|
+
return val;
|
|
997
|
+
}
|
|
998
|
+
if (typeof prop === "string") {
|
|
999
|
+
return target.get(+prop);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
get length() {
|
|
1004
|
+
return getTargetListLength(this);
|
|
1005
|
+
}
|
|
1006
|
+
toArray() {
|
|
1007
|
+
const { length } = this;
|
|
1008
|
+
const res = Array.from({ length });
|
|
1009
|
+
for (let i = 0; i < length; i++) {
|
|
1010
|
+
res[i] = this.at(i);
|
|
1011
|
+
}
|
|
1012
|
+
return res;
|
|
1013
|
+
}
|
|
1014
|
+
get(_index) {
|
|
1015
|
+
throw new TypeError("Cannot get from a generic list.");
|
|
1016
|
+
}
|
|
1017
|
+
set(_index, _value) {
|
|
1018
|
+
throw new TypeError("Cannot set on a generic list.");
|
|
1019
|
+
}
|
|
1020
|
+
at(index) {
|
|
1021
|
+
return this.get(index < 0 ? this.length + index : index);
|
|
1022
|
+
}
|
|
1023
|
+
concat(other) {
|
|
1024
|
+
const { length } = this;
|
|
1025
|
+
const otherLength = other.length;
|
|
1026
|
+
const res = Array.from({ length: length + otherLength });
|
|
1027
|
+
for (let i = 0; i < length; i++) res[i] = this.at(i);
|
|
1028
|
+
for (let i = 0; i < otherLength; i++) res[i + length] = other.at(i);
|
|
1029
|
+
return res;
|
|
1030
|
+
}
|
|
1031
|
+
some(cb, _this) {
|
|
1032
|
+
for (let i = 0; i < this.length; i++) {
|
|
1033
|
+
if (cb.call(_this, this.at(i), i, this)) {
|
|
1034
|
+
return true;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
filter(cb, _this) {
|
|
1040
|
+
const res = [];
|
|
1041
|
+
for (let i = 0; i < this.length; i++) {
|
|
1042
|
+
const value = this.at(i);
|
|
1043
|
+
if (cb.call(_this, value, i, this)) {
|
|
1044
|
+
res.push(value);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return res;
|
|
1048
|
+
}
|
|
1049
|
+
find(cb, _this) {
|
|
1050
|
+
for (let i = 0; i < this.length; i++) {
|
|
1051
|
+
const value = this.at(i);
|
|
1052
|
+
if (cb.call(_this, value, i, this)) {
|
|
1053
|
+
return value;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return void 0;
|
|
1057
|
+
}
|
|
1058
|
+
findIndex(cb, _this) {
|
|
1059
|
+
for (let i = 0; i < this.length; i++) {
|
|
1060
|
+
const value = this.at(i);
|
|
1061
|
+
if (cb.call(_this, value, i, this)) {
|
|
1062
|
+
return i;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return -1;
|
|
1066
|
+
}
|
|
1067
|
+
forEach(cb, _this) {
|
|
1068
|
+
for (let i = 0; i < this.length; i++) {
|
|
1069
|
+
cb.call(_this, this.at(i), i, this);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
map(cb, _this) {
|
|
1073
|
+
const { length } = this;
|
|
1074
|
+
const res = Array.from({ length });
|
|
1075
|
+
for (let i = 0; i < length; i++) {
|
|
1076
|
+
res[i] = cb.call(_this, this.at(i), i, this);
|
|
1077
|
+
}
|
|
1078
|
+
return res;
|
|
1079
|
+
}
|
|
1080
|
+
flatMap(cb, _this) {
|
|
1081
|
+
const res = [];
|
|
1082
|
+
for (let i = 0; i < this.length; i++) {
|
|
1083
|
+
const r = cb.call(_this, this.at(i), i, this);
|
|
1084
|
+
res.push(...Array.isArray(r) ? r : [r]);
|
|
1085
|
+
}
|
|
1086
|
+
return res;
|
|
1087
|
+
}
|
|
1088
|
+
every(cb, _this) {
|
|
1089
|
+
for (let i = 0; i < this.length; i++) {
|
|
1090
|
+
if (!cb.call(_this, this.at(i), i, this)) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1096
|
+
reduce(cb, initialValue) {
|
|
1097
|
+
let i = 0;
|
|
1098
|
+
let res;
|
|
1099
|
+
if (initialValue === void 0) {
|
|
1100
|
+
res = this.at(0);
|
|
1101
|
+
i++;
|
|
1102
|
+
} else {
|
|
1103
|
+
res = initialValue;
|
|
1104
|
+
}
|
|
1105
|
+
for (; i < this.length; i++) {
|
|
1106
|
+
res = cb(res, this.at(i), i, this);
|
|
1107
|
+
}
|
|
1108
|
+
return res;
|
|
1109
|
+
}
|
|
1110
|
+
reduceRight(cb, initialValue) {
|
|
1111
|
+
let i = this.length - 1;
|
|
1112
|
+
let res;
|
|
1113
|
+
if (initialValue === void 0) {
|
|
1114
|
+
res = this.at(i);
|
|
1115
|
+
i--;
|
|
1116
|
+
} else {
|
|
1117
|
+
res = initialValue;
|
|
1118
|
+
}
|
|
1119
|
+
for (; i >= 0; i--) {
|
|
1120
|
+
res = cb(res, this.at(i), i, this);
|
|
1121
|
+
}
|
|
1122
|
+
return res;
|
|
1123
|
+
}
|
|
1124
|
+
slice(start = 0, end) {
|
|
1125
|
+
const length = end ? Math.min(this.length, end) : this.length;
|
|
1126
|
+
const res = Array.from({ length: length - start });
|
|
1127
|
+
for (let i = start; i < length; i++) {
|
|
1128
|
+
res[i] = this.at(i);
|
|
1129
|
+
}
|
|
1130
|
+
return res;
|
|
1131
|
+
}
|
|
1132
|
+
join(separator) {
|
|
1133
|
+
return this.toArray().join(separator);
|
|
1134
|
+
}
|
|
1135
|
+
toReversed() {
|
|
1136
|
+
return this.toArray().reverse();
|
|
1137
|
+
}
|
|
1138
|
+
toSorted(compareFn) {
|
|
1139
|
+
return this.toArray().sort(compareFn);
|
|
1140
|
+
}
|
|
1141
|
+
toSpliced(start, deleteCount, ...items) {
|
|
1142
|
+
return this.toArray().splice(start, deleteCount, ...items);
|
|
1143
|
+
}
|
|
1144
|
+
fill(value, start, end) {
|
|
1145
|
+
const { length } = this;
|
|
1146
|
+
const s = Math.max(start ?? 0, 0);
|
|
1147
|
+
const e = Math.min(end ?? length, length);
|
|
1148
|
+
for (let i = s; i < e; i++) {
|
|
1149
|
+
this.set(i, value);
|
|
1150
|
+
}
|
|
1151
|
+
return this;
|
|
1152
|
+
}
|
|
1153
|
+
copyWithin(target, start, end) {
|
|
1154
|
+
const { length } = this;
|
|
1155
|
+
const e = end ?? length;
|
|
1156
|
+
const s = start < 0 ? Math.max(length + start, 0) : start;
|
|
1157
|
+
const t = target < 0 ? Math.max(length + target, 0) : target;
|
|
1158
|
+
const len = Math.min(e - s, length - t);
|
|
1159
|
+
for (let i = 0; i < len; i++) {
|
|
1160
|
+
this.set(t + i, this.at(s + i));
|
|
1161
|
+
}
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
keys() {
|
|
1165
|
+
return Array.from({ length: this.length }, (_, i) => i)[Symbol.iterator]();
|
|
1166
|
+
}
|
|
1167
|
+
values() {
|
|
1168
|
+
return this.toArray().values();
|
|
1169
|
+
}
|
|
1170
|
+
entries() {
|
|
1171
|
+
return this.toArray().entries();
|
|
1172
|
+
}
|
|
1173
|
+
flat(depth) {
|
|
1174
|
+
return this.toArray().flat(depth);
|
|
1175
|
+
}
|
|
1176
|
+
with(index, value) {
|
|
1177
|
+
return this.toArray().with(index, value);
|
|
1178
|
+
}
|
|
1179
|
+
includes(_searchElement, _fromIndex) {
|
|
1180
|
+
throw new Error(LIST_NO_SEARCH);
|
|
1181
|
+
}
|
|
1182
|
+
findLast(_cb, _thisArg) {
|
|
1183
|
+
throw new Error(LIST_NO_SEARCH);
|
|
1184
|
+
}
|
|
1185
|
+
findLastIndex(_cb, _t) {
|
|
1186
|
+
throw new Error(LIST_NO_SEARCH);
|
|
1187
|
+
}
|
|
1188
|
+
indexOf(_searchElement, _fromIndex) {
|
|
1189
|
+
throw new Error(LIST_NO_SEARCH);
|
|
1190
|
+
}
|
|
1191
|
+
lastIndexOf(_searchElement, _fromIndex) {
|
|
1192
|
+
throw new Error(LIST_NO_SEARCH);
|
|
1193
|
+
}
|
|
1194
|
+
pop() {
|
|
1195
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1196
|
+
}
|
|
1197
|
+
push(..._items) {
|
|
1198
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1199
|
+
}
|
|
1200
|
+
reverse() {
|
|
1201
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1202
|
+
}
|
|
1203
|
+
shift() {
|
|
1204
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1205
|
+
}
|
|
1206
|
+
unshift(..._items) {
|
|
1207
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1208
|
+
}
|
|
1209
|
+
splice(_start, _deleteCount, ..._rest) {
|
|
1210
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1211
|
+
}
|
|
1212
|
+
sort(_fn) {
|
|
1213
|
+
throw new Error(LIST_NO_MUTABLE);
|
|
1214
|
+
}
|
|
1215
|
+
get [Symbol.unscopables]() {
|
|
1216
|
+
return Array.prototype[Symbol.unscopables];
|
|
1217
|
+
}
|
|
1218
|
+
[Symbol.iterator]() {
|
|
1219
|
+
return this.values();
|
|
1220
|
+
}
|
|
1221
|
+
toJSON() {
|
|
1222
|
+
return this.toArray();
|
|
1223
|
+
}
|
|
1224
|
+
toString() {
|
|
1225
|
+
return this.join(",");
|
|
1226
|
+
}
|
|
1227
|
+
toLocaleString(_locales, _options) {
|
|
1228
|
+
return this.toString();
|
|
1229
|
+
}
|
|
1230
|
+
[Symbol.toStringTag]() {
|
|
1231
|
+
return "[object Array]";
|
|
1232
|
+
}
|
|
1233
|
+
static [Symbol.toStringTag]() {
|
|
1234
|
+
return this._capnp.displayName;
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
function initList$1(elementSize, length, list, compositeSize) {
|
|
1238
|
+
let c;
|
|
1239
|
+
switch (elementSize) {
|
|
1240
|
+
case ListElementSize.BIT: {
|
|
1241
|
+
c = list.segment.allocate(Math.ceil(length / 8));
|
|
1242
|
+
break;
|
|
1243
|
+
}
|
|
1244
|
+
case ListElementSize.BYTE:
|
|
1245
|
+
case ListElementSize.BYTE_2:
|
|
1246
|
+
case ListElementSize.BYTE_4:
|
|
1247
|
+
case ListElementSize.BYTE_8:
|
|
1248
|
+
case ListElementSize.POINTER: {
|
|
1249
|
+
c = list.segment.allocate(length * getListElementByteLength(elementSize));
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
case ListElementSize.COMPOSITE: {
|
|
1253
|
+
if (compositeSize === void 0) {
|
|
1254
|
+
throw new Error(format(PTR_COMPOSITE_SIZE_UNDEFINED));
|
|
1255
|
+
}
|
|
1256
|
+
compositeSize = padToWord(compositeSize);
|
|
1257
|
+
const byteLength = getByteLength(compositeSize) * length;
|
|
1258
|
+
c = list.segment.allocate(byteLength + 8);
|
|
1259
|
+
setStructPointer(length, compositeSize, c);
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
case ListElementSize.VOID: {
|
|
1263
|
+
setListPointer(0, elementSize, length, list);
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
default: {
|
|
1267
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
const res = initPointer(c.segment, c.byteOffset, list);
|
|
1271
|
+
setListPointer(
|
|
1272
|
+
res.offsetWords,
|
|
1273
|
+
elementSize,
|
|
1274
|
+
length,
|
|
1275
|
+
res.pointer,
|
|
1276
|
+
compositeSize
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
__name(initList$1, "initList$1");
|
|
1280
|
+
var Data = class extends List {
|
|
1281
|
+
static {
|
|
1282
|
+
__name(this, "Data");
|
|
1283
|
+
}
|
|
1284
|
+
static fromPointer(pointer) {
|
|
1285
|
+
validate(PointerType.LIST, pointer, ListElementSize.BYTE);
|
|
1286
|
+
return this._fromPointerUnchecked(pointer);
|
|
1287
|
+
}
|
|
1288
|
+
static _fromPointerUnchecked(pointer) {
|
|
1289
|
+
return new this(
|
|
1290
|
+
pointer.segment,
|
|
1291
|
+
pointer.byteOffset,
|
|
1292
|
+
pointer._capnp.depthLimit
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the
|
|
1297
|
+
* remaining bytes will be zeroed out. Extra bytes in `src` are ignored.
|
|
1298
|
+
*
|
|
1299
|
+
* @param src The source buffer.
|
|
1300
|
+
*/
|
|
1301
|
+
// TODO: Would be nice to have a way to zero-copy a buffer by allocating a new segment into the message with that
|
|
1302
|
+
// buffer data.
|
|
1303
|
+
copyBuffer(src) {
|
|
1304
|
+
const c = getContent(this);
|
|
1305
|
+
const dstLength = this.length;
|
|
1306
|
+
const srcLength = src.byteLength;
|
|
1307
|
+
const i = src instanceof ArrayBuffer ? new Uint8Array(src) : new Uint8Array(
|
|
1308
|
+
src.buffer,
|
|
1309
|
+
src.byteOffset,
|
|
1310
|
+
Math.min(dstLength, srcLength)
|
|
1311
|
+
);
|
|
1312
|
+
const o = new Uint8Array(c.segment.buffer, c.byteOffset, this.length);
|
|
1313
|
+
o.set(i);
|
|
1314
|
+
if (dstLength > srcLength) {
|
|
1315
|
+
o.fill(0, srcLength, dstLength);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Read a byte from the specified offset.
|
|
1320
|
+
*
|
|
1321
|
+
* @param byteOffset The byte offset to read.
|
|
1322
|
+
* @returns The byte value.
|
|
1323
|
+
*/
|
|
1324
|
+
get(byteOffset) {
|
|
1325
|
+
const c = getContent(this);
|
|
1326
|
+
return c.segment.getUint8(c.byteOffset + byteOffset);
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Write a byte at the specified offset.
|
|
1330
|
+
*
|
|
1331
|
+
* @param byteOffset The byte offset to set.
|
|
1332
|
+
* @param value The byte value to set.
|
|
1333
|
+
*/
|
|
1334
|
+
set(byteOffset, value) {
|
|
1335
|
+
const c = getContent(this);
|
|
1336
|
+
c.segment.setUint8(c.byteOffset + byteOffset, value);
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer.
|
|
1340
|
+
*
|
|
1341
|
+
* To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`.
|
|
1342
|
+
*
|
|
1343
|
+
* @returns A copy of this data buffer.
|
|
1344
|
+
*/
|
|
1345
|
+
toArrayBuffer() {
|
|
1346
|
+
const c = getContent(this);
|
|
1347
|
+
return c.segment.buffer.slice(c.byteOffset, c.byteOffset + this.length);
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Convert this Data pointer to a DataView representing the pointer's contents.
|
|
1351
|
+
*
|
|
1352
|
+
* WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the
|
|
1353
|
+
* DataView or else BAD THINGS.
|
|
1354
|
+
*
|
|
1355
|
+
* @returns A live reference to the underlying buffer.
|
|
1356
|
+
*/
|
|
1357
|
+
toDataView() {
|
|
1358
|
+
const c = getContent(this);
|
|
1359
|
+
return new DataView(c.segment.buffer, c.byteOffset, this.length);
|
|
1360
|
+
}
|
|
1361
|
+
[Symbol.toStringTag]() {
|
|
1362
|
+
return `Data_${super.toString()}`;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Convert this Data pointer to a Uint8Array representing the pointer's contents.
|
|
1366
|
+
*
|
|
1367
|
+
* WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the
|
|
1368
|
+
* Uint8Array or else BAD THINGS.
|
|
1369
|
+
*
|
|
1370
|
+
* @returns A live reference to the underlying buffer.
|
|
1371
|
+
*/
|
|
1372
|
+
toUint8Array() {
|
|
1373
|
+
const c = getContent(this);
|
|
1374
|
+
return new Uint8Array(c.segment.buffer, c.byteOffset, this.length);
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
var textEncoder = new TextEncoder();
|
|
1378
|
+
var textDecoder = new TextDecoder();
|
|
1379
|
+
var Text = class extends List {
|
|
1380
|
+
static {
|
|
1381
|
+
__name(this, "Text");
|
|
1382
|
+
}
|
|
1383
|
+
static fromPointer(pointer) {
|
|
1384
|
+
validate(PointerType.LIST, pointer, ListElementSize.BYTE);
|
|
1385
|
+
return textFromPointerUnchecked(pointer);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Read a utf-8 encoded string value from this pointer.
|
|
1389
|
+
*
|
|
1390
|
+
* @param index The index at which to start reading; defaults to zero.
|
|
1391
|
+
* @returns The string value.
|
|
1392
|
+
*/
|
|
1393
|
+
get(index = 0) {
|
|
1394
|
+
if (isNull(this)) {
|
|
1395
|
+
return "";
|
|
1396
|
+
}
|
|
1397
|
+
const c = getContent(this);
|
|
1398
|
+
return textDecoder.decode(
|
|
1399
|
+
new Uint8Array(
|
|
1400
|
+
c.segment.buffer,
|
|
1401
|
+
c.byteOffset + index,
|
|
1402
|
+
this.length - index
|
|
1403
|
+
)
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte.
|
|
1408
|
+
*
|
|
1409
|
+
* @returns The number of bytes allocated for the text.
|
|
1410
|
+
*/
|
|
1411
|
+
get length() {
|
|
1412
|
+
return super.length - 1;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Write a utf-8 encoded string value starting at the specified index.
|
|
1416
|
+
*
|
|
1417
|
+
* @param index The index at which to start copying the string. Note that if this is not zero the bytes
|
|
1418
|
+
* before `index` will be left as-is. All bytes after `index` will be overwritten.
|
|
1419
|
+
* @param value The string value to set.
|
|
1420
|
+
*/
|
|
1421
|
+
set(index, value) {
|
|
1422
|
+
const src = textEncoder.encode(value);
|
|
1423
|
+
const dstLength = src.byteLength + index;
|
|
1424
|
+
let c;
|
|
1425
|
+
let original;
|
|
1426
|
+
if (!isNull(this)) {
|
|
1427
|
+
c = getContent(this);
|
|
1428
|
+
const originalLength = Math.min(this.length, index);
|
|
1429
|
+
original = new Uint8Array(
|
|
1430
|
+
c.segment.buffer.slice(c.byteOffset, c.byteOffset + originalLength)
|
|
1431
|
+
);
|
|
1432
|
+
erase(this);
|
|
1433
|
+
}
|
|
1434
|
+
initList$1(ListElementSize.BYTE, dstLength + 1, this);
|
|
1435
|
+
c = getContent(this);
|
|
1436
|
+
const dst = new Uint8Array(c.segment.buffer, c.byteOffset, dstLength);
|
|
1437
|
+
if (original) {
|
|
1438
|
+
dst.set(original);
|
|
1439
|
+
}
|
|
1440
|
+
dst.set(src, index);
|
|
1441
|
+
}
|
|
1442
|
+
toString() {
|
|
1443
|
+
return this.get();
|
|
1444
|
+
}
|
|
1445
|
+
toJSON() {
|
|
1446
|
+
return this.get();
|
|
1447
|
+
}
|
|
1448
|
+
[Symbol.toPrimitive]() {
|
|
1449
|
+
return this.get();
|
|
1450
|
+
}
|
|
1451
|
+
[Symbol.toStringTag]() {
|
|
1452
|
+
return `Text_${super.toString()}`;
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
function textFromPointerUnchecked(pointer) {
|
|
1456
|
+
return new Text(
|
|
1457
|
+
pointer.segment,
|
|
1458
|
+
pointer.byteOffset,
|
|
1459
|
+
pointer._capnp.depthLimit
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
__name(textFromPointerUnchecked, "textFromPointerUnchecked");
|
|
1463
|
+
var Struct = class extends Pointer {
|
|
1464
|
+
static {
|
|
1465
|
+
__name(this, "Struct");
|
|
1466
|
+
}
|
|
1467
|
+
static _capnp = {
|
|
1468
|
+
displayName: "Struct"
|
|
1469
|
+
};
|
|
1470
|
+
/**
|
|
1471
|
+
* Create a new pointer to a struct.
|
|
1472
|
+
*
|
|
1473
|
+
* @param segment The segment the pointer resides in.
|
|
1474
|
+
* @param byteOffset The offset from the beginning of the segment to the beginning of the pointer data.
|
|
1475
|
+
* @param depthLimit The nesting depth limit for this object.
|
|
1476
|
+
* @param compositeIndex If set, then this pointer is actually a reference to a composite list
|
|
1477
|
+
* (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within
|
|
1478
|
+
* the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when
|
|
1479
|
+
* the list pointer is initialized.
|
|
1480
|
+
*/
|
|
1481
|
+
constructor(segment, byteOffset, depthLimit = MAX_DEPTH, compositeIndex) {
|
|
1482
|
+
super(segment, byteOffset, depthLimit);
|
|
1483
|
+
this._capnp.compositeIndex = compositeIndex;
|
|
1484
|
+
this._capnp.compositeList = compositeIndex !== void 0;
|
|
1485
|
+
}
|
|
1486
|
+
static [Symbol.toStringTag]() {
|
|
1487
|
+
return this._capnp.displayName;
|
|
1488
|
+
}
|
|
1489
|
+
[Symbol.toStringTag]() {
|
|
1490
|
+
return `Struct_${super.toString()}${this._capnp.compositeIndex === void 0 ? "" : `,ci:${this._capnp.compositeIndex}`} > ${getContent(this).toString()}`;
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
var AnyStruct = class extends Struct {
|
|
1494
|
+
static {
|
|
1495
|
+
__name(this, "AnyStruct");
|
|
1496
|
+
}
|
|
1497
|
+
static _capnp = {
|
|
1498
|
+
displayName: "AnyStruct",
|
|
1499
|
+
id: "0",
|
|
1500
|
+
size: new ObjectSize(0, 0)
|
|
1501
|
+
};
|
|
1502
|
+
};
|
|
1503
|
+
var FixedAnswer = class {
|
|
1504
|
+
static {
|
|
1505
|
+
__name(this, "FixedAnswer");
|
|
1506
|
+
}
|
|
1507
|
+
struct() {
|
|
1508
|
+
return Promise.resolve(this.structSync());
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
var ErrorAnswer = class extends FixedAnswer {
|
|
1512
|
+
static {
|
|
1513
|
+
__name(this, "ErrorAnswer");
|
|
1514
|
+
}
|
|
1515
|
+
constructor(err) {
|
|
1516
|
+
super();
|
|
1517
|
+
this.err = err;
|
|
1518
|
+
}
|
|
1519
|
+
structSync() {
|
|
1520
|
+
throw this.err;
|
|
1521
|
+
}
|
|
1522
|
+
pipelineCall(_transform, _call) {
|
|
1523
|
+
return this;
|
|
1524
|
+
}
|
|
1525
|
+
pipelineClose(_transform) {
|
|
1526
|
+
throw this.err;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
var ErrorClient = class {
|
|
1530
|
+
static {
|
|
1531
|
+
__name(this, "ErrorClient");
|
|
1532
|
+
}
|
|
1533
|
+
constructor(err) {
|
|
1534
|
+
this.err = err;
|
|
1535
|
+
}
|
|
1536
|
+
call(_call) {
|
|
1537
|
+
return new ErrorAnswer(this.err);
|
|
1538
|
+
}
|
|
1539
|
+
close() {
|
|
1540
|
+
throw this.err;
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
function clientOrNull(client) {
|
|
1544
|
+
return client ?? new ErrorClient(new Error(RPC_NULL_CLIENT));
|
|
1545
|
+
}
|
|
1546
|
+
__name(clientOrNull, "clientOrNull");
|
|
1547
|
+
var TMP_WORD = new DataView(new ArrayBuffer(8));
|
|
1548
|
+
function initStruct(size, s) {
|
|
1549
|
+
if (s._capnp.compositeIndex !== void 0) {
|
|
1550
|
+
throw new Error(format(PTR_INIT_COMPOSITE_STRUCT, s));
|
|
1551
|
+
}
|
|
1552
|
+
erase(s);
|
|
1553
|
+
const c = s.segment.allocate(getByteLength(size));
|
|
1554
|
+
const res = initPointer(c.segment, c.byteOffset, s);
|
|
1555
|
+
setStructPointer(res.offsetWords, size, res.pointer);
|
|
1556
|
+
}
|
|
1557
|
+
__name(initStruct, "initStruct");
|
|
1558
|
+
function initStructAt(index, StructClass, p) {
|
|
1559
|
+
const s = getPointerAs(index, StructClass, p);
|
|
1560
|
+
initStruct(StructClass._capnp.size, s);
|
|
1561
|
+
return s;
|
|
1562
|
+
}
|
|
1563
|
+
__name(initStructAt, "initStructAt");
|
|
1564
|
+
function checkPointerBounds(index, s) {
|
|
1565
|
+
const { pointerLength } = getSize(s);
|
|
1566
|
+
if (index < 0 || index >= pointerLength) {
|
|
1567
|
+
throw new Error(
|
|
1568
|
+
format(PTR_STRUCT_POINTER_OUT_OF_BOUNDS, s, index, pointerLength)
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
__name(checkPointerBounds, "checkPointerBounds");
|
|
1573
|
+
function getInterfaceClientOrNullAt(index, s) {
|
|
1574
|
+
return getInterfaceClientOrNull(getPointer(index, s));
|
|
1575
|
+
}
|
|
1576
|
+
__name(getInterfaceClientOrNullAt, "getInterfaceClientOrNullAt");
|
|
1577
|
+
function getInterfaceClientOrNull(p) {
|
|
1578
|
+
let client = null;
|
|
1579
|
+
const capId = getInterfacePointer(p);
|
|
1580
|
+
const { capTable } = p.segment.message._capnp;
|
|
1581
|
+
if (capTable && capId >= 0 && capId < capTable.length) {
|
|
1582
|
+
client = capTable[capId];
|
|
1583
|
+
}
|
|
1584
|
+
return clientOrNull(client);
|
|
1585
|
+
}
|
|
1586
|
+
__name(getInterfaceClientOrNull, "getInterfaceClientOrNull");
|
|
1587
|
+
function resize(dstSize, s) {
|
|
1588
|
+
const srcSize = getSize(s);
|
|
1589
|
+
const srcContent = getContent(s);
|
|
1590
|
+
const dstContent = s.segment.allocate(getByteLength(dstSize));
|
|
1591
|
+
dstContent.segment.copyWords(
|
|
1592
|
+
dstContent.byteOffset,
|
|
1593
|
+
srcContent.segment,
|
|
1594
|
+
srcContent.byteOffset,
|
|
1595
|
+
Math.min(getDataWordLength(srcSize), getDataWordLength(dstSize))
|
|
1596
|
+
);
|
|
1597
|
+
const res = initPointer(dstContent.segment, dstContent.byteOffset, s);
|
|
1598
|
+
setStructPointer(res.offsetWords, dstSize, res.pointer);
|
|
1599
|
+
for (let i = 0; i < Math.min(srcSize.pointerLength, dstSize.pointerLength); i++) {
|
|
1600
|
+
const srcPtr = new Pointer(
|
|
1601
|
+
srcContent.segment,
|
|
1602
|
+
srcContent.byteOffset + srcSize.dataByteLength + i * 8
|
|
1603
|
+
);
|
|
1604
|
+
if (isNull(srcPtr)) {
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
const srcPtrTarget = followFars(srcPtr);
|
|
1608
|
+
const srcPtrContent = getContent(srcPtr);
|
|
1609
|
+
const dstPtr = new Pointer(
|
|
1610
|
+
dstContent.segment,
|
|
1611
|
+
dstContent.byteOffset + dstSize.dataByteLength + i * 8
|
|
1612
|
+
);
|
|
1613
|
+
if (getTargetPointerType(srcPtr) === PointerType.LIST && getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE) {
|
|
1614
|
+
srcPtrContent.byteOffset -= 8;
|
|
1615
|
+
}
|
|
1616
|
+
const r = initPointer(
|
|
1617
|
+
srcPtrContent.segment,
|
|
1618
|
+
srcPtrContent.byteOffset,
|
|
1619
|
+
dstPtr
|
|
1620
|
+
);
|
|
1621
|
+
const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 3;
|
|
1622
|
+
const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4);
|
|
1623
|
+
r.pointer.segment.setUint32(r.pointer.byteOffset, a | r.offsetWords << 2);
|
|
1624
|
+
r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b);
|
|
1625
|
+
}
|
|
1626
|
+
srcContent.segment.fillZeroWords(
|
|
1627
|
+
srcContent.byteOffset,
|
|
1628
|
+
getWordLength(srcSize)
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
__name(resize, "resize");
|
|
1632
|
+
function getAs(StructClass, s) {
|
|
1633
|
+
return new StructClass(
|
|
1634
|
+
s.segment,
|
|
1635
|
+
s.byteOffset,
|
|
1636
|
+
s._capnp.depthLimit,
|
|
1637
|
+
s._capnp.compositeIndex
|
|
1638
|
+
);
|
|
1639
|
+
}
|
|
1640
|
+
__name(getAs, "getAs");
|
|
1641
|
+
function getBit(bitOffset, s, defaultMask) {
|
|
1642
|
+
const byteOffset = Math.floor(bitOffset / 8);
|
|
1643
|
+
const bitMask = 1 << bitOffset % 8;
|
|
1644
|
+
checkDataBounds(byteOffset, 1, s);
|
|
1645
|
+
const ds = getDataSection(s);
|
|
1646
|
+
const v = ds.segment.getUint8(ds.byteOffset + byteOffset);
|
|
1647
|
+
if (defaultMask === void 0) {
|
|
1648
|
+
return (v & bitMask) !== 0;
|
|
1649
|
+
}
|
|
1650
|
+
const defaultValue = defaultMask.getUint8(0);
|
|
1651
|
+
return ((v ^ defaultValue) & bitMask) !== 0;
|
|
1652
|
+
}
|
|
1653
|
+
__name(getBit, "getBit");
|
|
1654
|
+
function getData(index, s, defaultValue) {
|
|
1655
|
+
checkPointerBounds(index, s);
|
|
1656
|
+
const ps = getPointerSection(s);
|
|
1657
|
+
ps.byteOffset += index * 8;
|
|
1658
|
+
const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1659
|
+
if (isNull(l)) {
|
|
1660
|
+
if (defaultValue) {
|
|
1661
|
+
copyFrom(defaultValue, l);
|
|
1662
|
+
} else {
|
|
1663
|
+
initList$1(ListElementSize.BYTE, 0, l);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return l;
|
|
1667
|
+
}
|
|
1668
|
+
__name(getData, "getData");
|
|
1669
|
+
function getDataSection(s) {
|
|
1670
|
+
return getContent(s);
|
|
1671
|
+
}
|
|
1672
|
+
__name(getDataSection, "getDataSection");
|
|
1673
|
+
function getFloat32(byteOffset, s, defaultMask) {
|
|
1674
|
+
checkDataBounds(byteOffset, 4, s);
|
|
1675
|
+
const ds = getDataSection(s);
|
|
1676
|
+
if (defaultMask === void 0) {
|
|
1677
|
+
return ds.segment.getFloat32(ds.byteOffset + byteOffset);
|
|
1678
|
+
}
|
|
1679
|
+
const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
|
|
1680
|
+
TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN);
|
|
1681
|
+
return TMP_WORD.getFloat32(0, NATIVE_LITTLE_ENDIAN);
|
|
1682
|
+
}
|
|
1683
|
+
__name(getFloat32, "getFloat32");
|
|
1684
|
+
function getFloat64(byteOffset, s, defaultMask) {
|
|
1685
|
+
checkDataBounds(byteOffset, 8, s);
|
|
1686
|
+
const ds = getDataSection(s);
|
|
1687
|
+
if (defaultMask !== void 0) {
|
|
1688
|
+
const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
|
|
1689
|
+
const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
|
|
1690
|
+
TMP_WORD.setUint32(0, lo, NATIVE_LITTLE_ENDIAN);
|
|
1691
|
+
TMP_WORD.setUint32(4, hi, NATIVE_LITTLE_ENDIAN);
|
|
1692
|
+
return TMP_WORD.getFloat64(0, NATIVE_LITTLE_ENDIAN);
|
|
1693
|
+
}
|
|
1694
|
+
return ds.segment.getFloat64(ds.byteOffset + byteOffset);
|
|
1695
|
+
}
|
|
1696
|
+
__name(getFloat64, "getFloat64");
|
|
1697
|
+
function getInt16(byteOffset, s, defaultMask) {
|
|
1698
|
+
checkDataBounds(byteOffset, 2, s);
|
|
1699
|
+
const ds = getDataSection(s);
|
|
1700
|
+
if (defaultMask === void 0) {
|
|
1701
|
+
return ds.segment.getInt16(ds.byteOffset + byteOffset);
|
|
1702
|
+
}
|
|
1703
|
+
const v = ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
|
|
1704
|
+
TMP_WORD.setUint16(0, v, NATIVE_LITTLE_ENDIAN);
|
|
1705
|
+
return TMP_WORD.getInt16(0, NATIVE_LITTLE_ENDIAN);
|
|
1706
|
+
}
|
|
1707
|
+
__name(getInt16, "getInt16");
|
|
1708
|
+
function getInt32(byteOffset, s, defaultMask) {
|
|
1709
|
+
checkDataBounds(byteOffset, 4, s);
|
|
1710
|
+
const ds = getDataSection(s);
|
|
1711
|
+
if (defaultMask === void 0) {
|
|
1712
|
+
return ds.segment.getInt32(ds.byteOffset + byteOffset);
|
|
1713
|
+
}
|
|
1714
|
+
const v = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
|
|
1715
|
+
TMP_WORD.setUint32(0, v, NATIVE_LITTLE_ENDIAN);
|
|
1716
|
+
return TMP_WORD.getInt32(0, NATIVE_LITTLE_ENDIAN);
|
|
1717
|
+
}
|
|
1718
|
+
__name(getInt32, "getInt32");
|
|
1719
|
+
function getInt64(byteOffset, s, defaultMask) {
|
|
1720
|
+
checkDataBounds(byteOffset, 8, s);
|
|
1721
|
+
const ds = getDataSection(s);
|
|
1722
|
+
if (defaultMask !== void 0) {
|
|
1723
|
+
const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
|
|
1724
|
+
const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
|
|
1725
|
+
TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, lo, NATIVE_LITTLE_ENDIAN);
|
|
1726
|
+
TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, hi, NATIVE_LITTLE_ENDIAN);
|
|
1727
|
+
return TMP_WORD.getBigInt64(0, NATIVE_LITTLE_ENDIAN);
|
|
1728
|
+
}
|
|
1729
|
+
return ds.segment.getInt64(ds.byteOffset + byteOffset);
|
|
1730
|
+
}
|
|
1731
|
+
__name(getInt64, "getInt64");
|
|
1732
|
+
function getInt8(byteOffset, s, defaultMask) {
|
|
1733
|
+
checkDataBounds(byteOffset, 1, s);
|
|
1734
|
+
const ds = getDataSection(s);
|
|
1735
|
+
if (defaultMask === void 0) {
|
|
1736
|
+
return ds.segment.getInt8(ds.byteOffset + byteOffset);
|
|
1737
|
+
}
|
|
1738
|
+
const v = ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0);
|
|
1739
|
+
TMP_WORD.setUint8(0, v);
|
|
1740
|
+
return TMP_WORD.getInt8(0);
|
|
1741
|
+
}
|
|
1742
|
+
__name(getInt8, "getInt8");
|
|
1743
|
+
function getList(index, ListClass, s, defaultValue) {
|
|
1744
|
+
checkPointerBounds(index, s);
|
|
1745
|
+
const ps = getPointerSection(s);
|
|
1746
|
+
ps.byteOffset += index * 8;
|
|
1747
|
+
const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1748
|
+
if (isNull(l)) {
|
|
1749
|
+
if (defaultValue) {
|
|
1750
|
+
copyFrom(defaultValue, l);
|
|
1751
|
+
} else {
|
|
1752
|
+
initList$1(ListClass._capnp.size, 0, l, ListClass._capnp.compositeSize);
|
|
1753
|
+
}
|
|
1754
|
+
} else if (ListClass._capnp.compositeSize !== void 0) {
|
|
1755
|
+
const srcSize = getTargetCompositeListSize(l);
|
|
1756
|
+
const dstSize = ListClass._capnp.compositeSize;
|
|
1757
|
+
if (dstSize.dataByteLength > srcSize.dataByteLength || dstSize.pointerLength > srcSize.pointerLength) {
|
|
1758
|
+
const srcContent = getContent(l);
|
|
1759
|
+
const srcLength = getTargetListLength(l);
|
|
1760
|
+
const dstContent = l.segment.allocate(
|
|
1761
|
+
getByteLength(dstSize) * srcLength + 8
|
|
1762
|
+
);
|
|
1763
|
+
const res = initPointer(dstContent.segment, dstContent.byteOffset, l);
|
|
1764
|
+
setListPointer(
|
|
1765
|
+
res.offsetWords,
|
|
1766
|
+
ListClass._capnp.size,
|
|
1767
|
+
srcLength,
|
|
1768
|
+
res.pointer,
|
|
1769
|
+
dstSize
|
|
1770
|
+
);
|
|
1771
|
+
setStructPointer(srcLength, dstSize, dstContent);
|
|
1772
|
+
dstContent.byteOffset += 8;
|
|
1773
|
+
for (let i = 0; i < srcLength; i++) {
|
|
1774
|
+
const srcElementOffset = srcContent.byteOffset + i * getByteLength(srcSize);
|
|
1775
|
+
const dstElementOffset = dstContent.byteOffset + i * getByteLength(dstSize);
|
|
1776
|
+
dstContent.segment.copyWords(
|
|
1777
|
+
dstElementOffset,
|
|
1778
|
+
srcContent.segment,
|
|
1779
|
+
srcElementOffset,
|
|
1780
|
+
getWordLength(srcSize)
|
|
1781
|
+
);
|
|
1782
|
+
for (let j = 0; j < srcSize.pointerLength; j++) {
|
|
1783
|
+
const srcPtr = new Pointer(
|
|
1784
|
+
srcContent.segment,
|
|
1785
|
+
srcElementOffset + srcSize.dataByteLength + j * 8
|
|
1786
|
+
);
|
|
1787
|
+
const dstPtr = new Pointer(
|
|
1788
|
+
dstContent.segment,
|
|
1789
|
+
dstElementOffset + dstSize.dataByteLength + j * 8
|
|
1790
|
+
);
|
|
1791
|
+
const srcPtrTarget = followFars(srcPtr);
|
|
1792
|
+
const srcPtrContent = getContent(srcPtr);
|
|
1793
|
+
if (getTargetPointerType(srcPtr) === PointerType.LIST && getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE) {
|
|
1794
|
+
srcPtrContent.byteOffset -= 8;
|
|
1795
|
+
}
|
|
1796
|
+
const r = initPointer(
|
|
1797
|
+
srcPtrContent.segment,
|
|
1798
|
+
srcPtrContent.byteOffset,
|
|
1799
|
+
dstPtr
|
|
1800
|
+
);
|
|
1801
|
+
const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 3;
|
|
1802
|
+
const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4);
|
|
1803
|
+
r.pointer.segment.setUint32(
|
|
1804
|
+
r.pointer.byteOffset,
|
|
1805
|
+
a | r.offsetWords << 2
|
|
1806
|
+
);
|
|
1807
|
+
r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
srcContent.segment.fillZeroWords(
|
|
1811
|
+
srcContent.byteOffset,
|
|
1812
|
+
getWordLength(srcSize) * srcLength
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return l;
|
|
1817
|
+
}
|
|
1818
|
+
__name(getList, "getList");
|
|
1819
|
+
function getPointer(index, s) {
|
|
1820
|
+
checkPointerBounds(index, s);
|
|
1821
|
+
const ps = getPointerSection(s);
|
|
1822
|
+
ps.byteOffset += index * 8;
|
|
1823
|
+
return new Pointer(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1824
|
+
}
|
|
1825
|
+
__name(getPointer, "getPointer");
|
|
1826
|
+
function getPointerAs(index, PointerClass, s) {
|
|
1827
|
+
checkPointerBounds(index, s);
|
|
1828
|
+
const ps = getPointerSection(s);
|
|
1829
|
+
ps.byteOffset += index * 8;
|
|
1830
|
+
return new PointerClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1831
|
+
}
|
|
1832
|
+
__name(getPointerAs, "getPointerAs");
|
|
1833
|
+
function getPointerSection(s) {
|
|
1834
|
+
const ps = getContent(s);
|
|
1835
|
+
ps.byteOffset += padToWord$1(getSize(s).dataByteLength);
|
|
1836
|
+
return ps;
|
|
1837
|
+
}
|
|
1838
|
+
__name(getPointerSection, "getPointerSection");
|
|
1839
|
+
function getSize(s) {
|
|
1840
|
+
if (s._capnp.compositeIndex !== void 0) {
|
|
1841
|
+
const c = getContent(s, true);
|
|
1842
|
+
c.byteOffset -= 8;
|
|
1843
|
+
return getStructSize(c);
|
|
1844
|
+
}
|
|
1845
|
+
return getTargetStructSize(s);
|
|
1846
|
+
}
|
|
1847
|
+
__name(getSize, "getSize");
|
|
1848
|
+
function getStruct(index, StructClass, s, defaultValue) {
|
|
1849
|
+
const t = getPointerAs(index, StructClass, s);
|
|
1850
|
+
if (isNull(t)) {
|
|
1851
|
+
if (defaultValue) {
|
|
1852
|
+
copyFrom(defaultValue, t);
|
|
1853
|
+
} else {
|
|
1854
|
+
initStruct(StructClass._capnp.size, t);
|
|
1855
|
+
}
|
|
1856
|
+
} else {
|
|
1857
|
+
validate(PointerType.STRUCT, t);
|
|
1858
|
+
const ts = getTargetStructSize(t);
|
|
1859
|
+
if (ts.dataByteLength < StructClass._capnp.size.dataByteLength || ts.pointerLength < StructClass._capnp.size.pointerLength) {
|
|
1860
|
+
resize(StructClass._capnp.size, t);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return t;
|
|
1864
|
+
}
|
|
1865
|
+
__name(getStruct, "getStruct");
|
|
1866
|
+
function getText(index, s, defaultValue) {
|
|
1867
|
+
const t = Text.fromPointer(getPointer(index, s));
|
|
1868
|
+
if (isNull(t) && defaultValue) {
|
|
1869
|
+
t.set(0, defaultValue);
|
|
1870
|
+
}
|
|
1871
|
+
return t.get(0);
|
|
1872
|
+
}
|
|
1873
|
+
__name(getText, "getText");
|
|
1874
|
+
function getUint16(byteOffset, s, defaultMask) {
|
|
1875
|
+
checkDataBounds(byteOffset, 2, s);
|
|
1876
|
+
const ds = getDataSection(s);
|
|
1877
|
+
if (defaultMask === void 0) {
|
|
1878
|
+
return ds.segment.getUint16(ds.byteOffset + byteOffset);
|
|
1879
|
+
}
|
|
1880
|
+
return ds.segment.getUint16(ds.byteOffset + byteOffset) ^ defaultMask.getUint16(0, true);
|
|
1881
|
+
}
|
|
1882
|
+
__name(getUint16, "getUint16");
|
|
1883
|
+
function getUint32(byteOffset, s, defaultMask) {
|
|
1884
|
+
checkDataBounds(byteOffset, 4, s);
|
|
1885
|
+
const ds = getDataSection(s);
|
|
1886
|
+
if (defaultMask === void 0) {
|
|
1887
|
+
return ds.segment.getUint32(ds.byteOffset + byteOffset);
|
|
1888
|
+
}
|
|
1889
|
+
return ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
|
|
1890
|
+
}
|
|
1891
|
+
__name(getUint32, "getUint32");
|
|
1892
|
+
function getUint64(byteOffset, s, defaultMask) {
|
|
1893
|
+
checkDataBounds(byteOffset, 8, s);
|
|
1894
|
+
const ds = getDataSection(s);
|
|
1895
|
+
if (defaultMask !== void 0) {
|
|
1896
|
+
const lo = ds.segment.getUint32(ds.byteOffset + byteOffset) ^ defaultMask.getUint32(0, true);
|
|
1897
|
+
const hi = ds.segment.getUint32(ds.byteOffset + byteOffset + 4) ^ defaultMask.getUint32(4, true);
|
|
1898
|
+
TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, lo, NATIVE_LITTLE_ENDIAN);
|
|
1899
|
+
TMP_WORD.setUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, hi, NATIVE_LITTLE_ENDIAN);
|
|
1900
|
+
return TMP_WORD.getBigUint64(0, NATIVE_LITTLE_ENDIAN);
|
|
1901
|
+
}
|
|
1902
|
+
return ds.segment.getUint64(ds.byteOffset + byteOffset);
|
|
1903
|
+
}
|
|
1904
|
+
__name(getUint64, "getUint64");
|
|
1905
|
+
function getUint8(byteOffset, s, defaultMask) {
|
|
1906
|
+
checkDataBounds(byteOffset, 1, s);
|
|
1907
|
+
const ds = getDataSection(s);
|
|
1908
|
+
if (defaultMask === void 0) {
|
|
1909
|
+
return ds.segment.getUint8(ds.byteOffset + byteOffset);
|
|
1910
|
+
}
|
|
1911
|
+
return ds.segment.getUint8(ds.byteOffset + byteOffset) ^ defaultMask.getUint8(0);
|
|
1912
|
+
}
|
|
1913
|
+
__name(getUint8, "getUint8");
|
|
1914
|
+
function initData(index, length, s) {
|
|
1915
|
+
checkPointerBounds(index, s);
|
|
1916
|
+
const ps = getPointerSection(s);
|
|
1917
|
+
ps.byteOffset += index * 8;
|
|
1918
|
+
const l = new Data(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1919
|
+
erase(l);
|
|
1920
|
+
initList$1(ListElementSize.BYTE, length, l);
|
|
1921
|
+
return l;
|
|
1922
|
+
}
|
|
1923
|
+
__name(initData, "initData");
|
|
1924
|
+
function initList(index, ListClass, length, s) {
|
|
1925
|
+
checkPointerBounds(index, s);
|
|
1926
|
+
const ps = getPointerSection(s);
|
|
1927
|
+
ps.byteOffset += index * 8;
|
|
1928
|
+
const l = new ListClass(ps.segment, ps.byteOffset, s._capnp.depthLimit - 1);
|
|
1929
|
+
erase(l);
|
|
1930
|
+
initList$1(ListClass._capnp.size, length, l, ListClass._capnp.compositeSize);
|
|
1931
|
+
return l;
|
|
1932
|
+
}
|
|
1933
|
+
__name(initList, "initList");
|
|
1934
|
+
function setBit(bitOffset, value, s, defaultMask) {
|
|
1935
|
+
const byteOffset = Math.floor(bitOffset / 8);
|
|
1936
|
+
const bitMask = 1 << bitOffset % 8;
|
|
1937
|
+
checkDataBounds(byteOffset, 1, s);
|
|
1938
|
+
const ds = getDataSection(s);
|
|
1939
|
+
const b = ds.segment.getUint8(ds.byteOffset + byteOffset);
|
|
1940
|
+
if (defaultMask !== void 0) {
|
|
1941
|
+
value = (defaultMask.getUint8(0) & bitMask) === 0 ? value : !value;
|
|
1942
|
+
}
|
|
1943
|
+
ds.segment.setUint8(
|
|
1944
|
+
ds.byteOffset + byteOffset,
|
|
1945
|
+
value ? b | bitMask : b & ~bitMask
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
__name(setBit, "setBit");
|
|
1949
|
+
function setFloat32(byteOffset, value, s, defaultMask) {
|
|
1950
|
+
checkDataBounds(byteOffset, 4, s);
|
|
1951
|
+
const ds = getDataSection(s);
|
|
1952
|
+
if (defaultMask !== void 0) {
|
|
1953
|
+
TMP_WORD.setFloat32(0, value, NATIVE_LITTLE_ENDIAN);
|
|
1954
|
+
const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
|
|
1955
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, v);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
ds.segment.setFloat32(ds.byteOffset + byteOffset, value);
|
|
1959
|
+
}
|
|
1960
|
+
__name(setFloat32, "setFloat32");
|
|
1961
|
+
function setFloat64(byteOffset, value, s, defaultMask) {
|
|
1962
|
+
checkDataBounds(byteOffset, 8, s);
|
|
1963
|
+
const ds = getDataSection(s);
|
|
1964
|
+
if (defaultMask !== void 0) {
|
|
1965
|
+
TMP_WORD.setFloat64(0, value, NATIVE_LITTLE_ENDIAN);
|
|
1966
|
+
const lo = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
|
|
1967
|
+
const hi = TMP_WORD.getUint32(4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
|
|
1968
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
|
|
1969
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
ds.segment.setFloat64(ds.byteOffset + byteOffset, value);
|
|
1973
|
+
}
|
|
1974
|
+
__name(setFloat64, "setFloat64");
|
|
1975
|
+
function setInt16(byteOffset, value, s, defaultMask) {
|
|
1976
|
+
checkDataBounds(byteOffset, 2, s);
|
|
1977
|
+
const ds = getDataSection(s);
|
|
1978
|
+
if (defaultMask !== void 0) {
|
|
1979
|
+
TMP_WORD.setInt16(0, value, NATIVE_LITTLE_ENDIAN);
|
|
1980
|
+
const v = TMP_WORD.getUint16(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint16(0, true);
|
|
1981
|
+
ds.segment.setUint16(ds.byteOffset + byteOffset, v);
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
ds.segment.setInt16(ds.byteOffset + byteOffset, value);
|
|
1985
|
+
}
|
|
1986
|
+
__name(setInt16, "setInt16");
|
|
1987
|
+
function setInt32(byteOffset, value, s, defaultMask) {
|
|
1988
|
+
checkDataBounds(byteOffset, 4, s);
|
|
1989
|
+
const ds = getDataSection(s);
|
|
1990
|
+
if (defaultMask !== void 0) {
|
|
1991
|
+
TMP_WORD.setInt32(0, value, NATIVE_LITTLE_ENDIAN);
|
|
1992
|
+
const v = TMP_WORD.getUint32(0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
|
|
1993
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, v);
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
ds.segment.setInt32(ds.byteOffset + byteOffset, value);
|
|
1997
|
+
}
|
|
1998
|
+
__name(setInt32, "setInt32");
|
|
1999
|
+
function setInt64(byteOffset, value, s, defaultMask) {
|
|
2000
|
+
checkDataBounds(byteOffset, 8, s);
|
|
2001
|
+
const ds = getDataSection(s);
|
|
2002
|
+
if (defaultMask !== void 0) {
|
|
2003
|
+
TMP_WORD.setBigInt64(0, value, NATIVE_LITTLE_ENDIAN);
|
|
2004
|
+
const lo = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
|
|
2005
|
+
const hi = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
|
|
2006
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
|
|
2007
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
ds.segment.setInt64(ds.byteOffset + byteOffset, value);
|
|
2011
|
+
}
|
|
2012
|
+
__name(setInt64, "setInt64");
|
|
2013
|
+
function setInt8(byteOffset, value, s, defaultMask) {
|
|
2014
|
+
checkDataBounds(byteOffset, 1, s);
|
|
2015
|
+
const ds = getDataSection(s);
|
|
2016
|
+
if (defaultMask !== void 0) {
|
|
2017
|
+
TMP_WORD.setInt8(0, value);
|
|
2018
|
+
const v = TMP_WORD.getUint8(0) ^ defaultMask.getUint8(0);
|
|
2019
|
+
ds.segment.setUint8(ds.byteOffset + byteOffset, v);
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
ds.segment.setInt8(ds.byteOffset + byteOffset, value);
|
|
2023
|
+
}
|
|
2024
|
+
__name(setInt8, "setInt8");
|
|
2025
|
+
function setText(index, value, s) {
|
|
2026
|
+
Text.fromPointer(getPointer(index, s)).set(0, value);
|
|
2027
|
+
}
|
|
2028
|
+
__name(setText, "setText");
|
|
2029
|
+
function setUint16(byteOffset, value, s, defaultMask) {
|
|
2030
|
+
checkDataBounds(byteOffset, 2, s);
|
|
2031
|
+
const ds = getDataSection(s);
|
|
2032
|
+
if (defaultMask !== void 0) {
|
|
2033
|
+
value ^= defaultMask.getUint16(0, true);
|
|
2034
|
+
}
|
|
2035
|
+
ds.segment.setUint16(ds.byteOffset + byteOffset, value);
|
|
2036
|
+
}
|
|
2037
|
+
__name(setUint16, "setUint16");
|
|
2038
|
+
function setUint32(byteOffset, value, s, defaultMask) {
|
|
2039
|
+
checkDataBounds(byteOffset, 4, s);
|
|
2040
|
+
const ds = getDataSection(s);
|
|
2041
|
+
if (defaultMask !== void 0) {
|
|
2042
|
+
value ^= defaultMask.getUint32(0, true);
|
|
2043
|
+
}
|
|
2044
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, value);
|
|
2045
|
+
}
|
|
2046
|
+
__name(setUint32, "setUint32");
|
|
2047
|
+
function setUint64(byteOffset, value, s, defaultMask) {
|
|
2048
|
+
checkDataBounds(byteOffset, 8, s);
|
|
2049
|
+
const ds = getDataSection(s);
|
|
2050
|
+
if (defaultMask !== void 0) {
|
|
2051
|
+
TMP_WORD.setBigUint64(0, value, NATIVE_LITTLE_ENDIAN);
|
|
2052
|
+
const lo = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 0 : 4, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(0, true);
|
|
2053
|
+
const hi = TMP_WORD.getUint32(NATIVE_LITTLE_ENDIAN ? 4 : 0, NATIVE_LITTLE_ENDIAN) ^ defaultMask.getUint32(4, true);
|
|
2054
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset, lo);
|
|
2055
|
+
ds.segment.setUint32(ds.byteOffset + byteOffset + 4, hi);
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
ds.segment.setUint64(ds.byteOffset + byteOffset, value);
|
|
2059
|
+
}
|
|
2060
|
+
__name(setUint64, "setUint64");
|
|
2061
|
+
function setUint8(byteOffset, value, s, defaultMask) {
|
|
2062
|
+
checkDataBounds(byteOffset, 1, s);
|
|
2063
|
+
const ds = getDataSection(s);
|
|
2064
|
+
if (defaultMask !== void 0) {
|
|
2065
|
+
value ^= defaultMask.getUint8(0);
|
|
2066
|
+
}
|
|
2067
|
+
ds.segment.setUint8(ds.byteOffset + byteOffset, value);
|
|
2068
|
+
}
|
|
2069
|
+
__name(setUint8, "setUint8");
|
|
2070
|
+
function testWhich(name, found, wanted, s) {
|
|
2071
|
+
if (found !== wanted) {
|
|
2072
|
+
throw new Error(format(PTR_INVALID_UNION_ACCESS, s, name, found, wanted));
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
__name(testWhich, "testWhich");
|
|
2076
|
+
function checkDataBounds(byteOffset, byteLength, s) {
|
|
2077
|
+
const { dataByteLength } = getSize(s);
|
|
2078
|
+
if (byteOffset < 0 || byteLength < 0 || byteOffset + byteLength > dataByteLength) {
|
|
2079
|
+
throw new Error(
|
|
2080
|
+
format(
|
|
2081
|
+
PTR_STRUCT_DATA_OUT_OF_BOUNDS,
|
|
2082
|
+
s,
|
|
2083
|
+
byteLength,
|
|
2084
|
+
byteOffset,
|
|
2085
|
+
dataByteLength
|
|
2086
|
+
)
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
__name(checkDataBounds, "checkDataBounds");
|
|
2091
|
+
|
|
2092
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/shared/capnp-es.BvfUH5E6.mjs
|
|
2093
|
+
function CompositeList(CompositeClass) {
|
|
2094
|
+
return class extends List {
|
|
2095
|
+
static _capnp = {
|
|
2096
|
+
compositeSize: CompositeClass._capnp.size,
|
|
2097
|
+
displayName: `List<${CompositeClass._capnp.displayName}>`,
|
|
2098
|
+
size: ListElementSize.COMPOSITE
|
|
2099
|
+
};
|
|
2100
|
+
get(index) {
|
|
2101
|
+
return new CompositeClass(
|
|
2102
|
+
this.segment,
|
|
2103
|
+
this.byteOffset,
|
|
2104
|
+
this._capnp.depthLimit - 1,
|
|
2105
|
+
index
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
set(index, value) {
|
|
2109
|
+
copyFrom(value, this.get(index));
|
|
2110
|
+
}
|
|
2111
|
+
[Symbol.toStringTag]() {
|
|
2112
|
+
return `Composite_${super.toString()},cls:${CompositeClass.toString()}`;
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
__name(CompositeList, "CompositeList");
|
|
2117
|
+
function _makePrimitiveMaskFn(byteLength, setter) {
|
|
2118
|
+
return (x) => {
|
|
2119
|
+
const dv = new DataView(new ArrayBuffer(byteLength));
|
|
2120
|
+
setter.call(dv, 0, x, true);
|
|
2121
|
+
return dv;
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
__name(_makePrimitiveMaskFn, "_makePrimitiveMaskFn");
|
|
2125
|
+
var getFloat32Mask = _makePrimitiveMaskFn(
|
|
2126
|
+
4,
|
|
2127
|
+
DataView.prototype.setFloat32
|
|
2128
|
+
);
|
|
2129
|
+
var getFloat64Mask = _makePrimitiveMaskFn(
|
|
2130
|
+
8,
|
|
2131
|
+
DataView.prototype.setFloat64
|
|
2132
|
+
);
|
|
2133
|
+
var getInt16Mask = _makePrimitiveMaskFn(
|
|
2134
|
+
2,
|
|
2135
|
+
DataView.prototype.setInt16
|
|
2136
|
+
);
|
|
2137
|
+
var getInt32Mask = _makePrimitiveMaskFn(
|
|
2138
|
+
4,
|
|
2139
|
+
DataView.prototype.setInt32
|
|
2140
|
+
);
|
|
2141
|
+
var getInt64Mask = _makePrimitiveMaskFn(
|
|
2142
|
+
8,
|
|
2143
|
+
DataView.prototype.setBigInt64
|
|
2144
|
+
);
|
|
2145
|
+
var getInt8Mask = _makePrimitiveMaskFn(1, DataView.prototype.setInt8);
|
|
2146
|
+
var getUint16Mask = _makePrimitiveMaskFn(
|
|
2147
|
+
2,
|
|
2148
|
+
DataView.prototype.setUint16
|
|
2149
|
+
);
|
|
2150
|
+
var getUint32Mask = _makePrimitiveMaskFn(
|
|
2151
|
+
4,
|
|
2152
|
+
DataView.prototype.setUint32
|
|
2153
|
+
);
|
|
2154
|
+
var getUint64Mask = _makePrimitiveMaskFn(
|
|
2155
|
+
8,
|
|
2156
|
+
DataView.prototype.setBigUint64
|
|
2157
|
+
);
|
|
2158
|
+
var getUint8Mask = _makePrimitiveMaskFn(
|
|
2159
|
+
1,
|
|
2160
|
+
DataView.prototype.setUint8
|
|
2161
|
+
);
|
|
2162
|
+
function getBitMask(value, bitOffset) {
|
|
2163
|
+
const dv = new DataView(new ArrayBuffer(1));
|
|
2164
|
+
if (!value) {
|
|
2165
|
+
return dv;
|
|
2166
|
+
}
|
|
2167
|
+
dv.setUint8(0, 1 << bitOffset % 8);
|
|
2168
|
+
return dv;
|
|
2169
|
+
}
|
|
2170
|
+
__name(getBitMask, "getBitMask");
|
|
2171
|
+
|
|
2172
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/shared/capnp-es.GpvEvMIK.mjs
|
|
2173
|
+
var ArenaKind = /* @__PURE__ */ ((ArenaKind2) => {
|
|
2174
|
+
ArenaKind2[ArenaKind2["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT";
|
|
2175
|
+
ArenaKind2[ArenaKind2["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT";
|
|
2176
|
+
return ArenaKind2;
|
|
2177
|
+
})(ArenaKind || {});
|
|
2178
|
+
var ArenaAllocationResult = class {
|
|
2179
|
+
static {
|
|
2180
|
+
__name(this, "ArenaAllocationResult");
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* The newly allocated buffer. This buffer might be a copy of an existing segment's buffer with free space appended.
|
|
2184
|
+
*/
|
|
2185
|
+
buffer;
|
|
2186
|
+
/**
|
|
2187
|
+
* The id of the newly-allocated segment.
|
|
2188
|
+
*/
|
|
2189
|
+
id;
|
|
2190
|
+
constructor(id, buffer) {
|
|
2191
|
+
this.id = id;
|
|
2192
|
+
this.buffer = buffer;
|
|
2193
|
+
}
|
|
2194
|
+
};
|
|
2195
|
+
var MultiSegmentArena = class {
|
|
2196
|
+
static {
|
|
2197
|
+
__name(this, "MultiSegmentArena");
|
|
2198
|
+
}
|
|
2199
|
+
constructor(buffers = [new ArrayBuffer(DEFAULT_BUFFER_SIZE)]) {
|
|
2200
|
+
this.buffers = buffers;
|
|
2201
|
+
let i = buffers.length;
|
|
2202
|
+
while (--i >= 0) {
|
|
2203
|
+
if ((buffers[i].byteLength & 7) !== 0) {
|
|
2204
|
+
throw new Error(format(SEG_NOT_WORD_ALIGNED, buffers[i].byteLength));
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
static allocate = allocate$2;
|
|
2209
|
+
static getBuffer = getBuffer$2;
|
|
2210
|
+
static getNumSegments = getNumSegments$2;
|
|
2211
|
+
kind = ArenaKind.MULTI_SEGMENT;
|
|
2212
|
+
toString() {
|
|
2213
|
+
return format("MultiSegmentArena_segments:%d", getNumSegments$2(this));
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
function allocate$2(minSize, m) {
|
|
2217
|
+
const b = new ArrayBuffer(padToWord$1(Math.max(minSize, DEFAULT_BUFFER_SIZE)));
|
|
2218
|
+
m.buffers.push(b);
|
|
2219
|
+
return new ArenaAllocationResult(m.buffers.length - 1, b);
|
|
2220
|
+
}
|
|
2221
|
+
__name(allocate$2, "allocate$2");
|
|
2222
|
+
function getBuffer$2(id, m) {
|
|
2223
|
+
if (id < 0 || id >= m.buffers.length) {
|
|
2224
|
+
throw new Error(format(SEG_ID_OUT_OF_BOUNDS, id));
|
|
2225
|
+
}
|
|
2226
|
+
return m.buffers[id];
|
|
2227
|
+
}
|
|
2228
|
+
__name(getBuffer$2, "getBuffer$2");
|
|
2229
|
+
function getNumSegments$2(m) {
|
|
2230
|
+
return m.buffers.length;
|
|
2231
|
+
}
|
|
2232
|
+
__name(getNumSegments$2, "getNumSegments$2");
|
|
2233
|
+
var SingleSegmentArena = class {
|
|
2234
|
+
static {
|
|
2235
|
+
__name(this, "SingleSegmentArena");
|
|
2236
|
+
}
|
|
2237
|
+
static allocate = allocate$1;
|
|
2238
|
+
static getBuffer = getBuffer$1;
|
|
2239
|
+
static getNumSegments = getNumSegments$1;
|
|
2240
|
+
buffer;
|
|
2241
|
+
kind = ArenaKind.SINGLE_SEGMENT;
|
|
2242
|
+
constructor(buffer = new ArrayBuffer(DEFAULT_BUFFER_SIZE)) {
|
|
2243
|
+
if ((buffer.byteLength & 7) !== 0) {
|
|
2244
|
+
throw new Error(format(SEG_NOT_WORD_ALIGNED, buffer.byteLength));
|
|
2245
|
+
}
|
|
2246
|
+
this.buffer = buffer;
|
|
2247
|
+
}
|
|
2248
|
+
toString() {
|
|
2249
|
+
return format("SingleSegmentArena_len:%x", this.buffer.byteLength);
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
function allocate$1(minSize, segments, s) {
|
|
2253
|
+
const srcBuffer = segments.length > 0 ? segments[0].buffer : s.buffer;
|
|
2254
|
+
minSize = minSize < MIN_SINGLE_SEGMENT_GROWTH ? MIN_SINGLE_SEGMENT_GROWTH : padToWord$1(minSize);
|
|
2255
|
+
s.buffer = new ArrayBuffer(srcBuffer.byteLength + minSize);
|
|
2256
|
+
new Float64Array(s.buffer).set(new Float64Array(srcBuffer));
|
|
2257
|
+
return new ArenaAllocationResult(0, s.buffer);
|
|
2258
|
+
}
|
|
2259
|
+
__name(allocate$1, "allocate$1");
|
|
2260
|
+
function getBuffer$1(id, s) {
|
|
2261
|
+
if (id !== 0) throw new Error(format(SEG_GET_NON_ZERO_SINGLE, id));
|
|
2262
|
+
return s.buffer;
|
|
2263
|
+
}
|
|
2264
|
+
__name(getBuffer$1, "getBuffer$1");
|
|
2265
|
+
function getNumSegments$1() {
|
|
2266
|
+
return 1;
|
|
2267
|
+
}
|
|
2268
|
+
__name(getNumSegments$1, "getNumSegments$1");
|
|
2269
|
+
var Arena = class {
|
|
2270
|
+
static {
|
|
2271
|
+
__name(this, "Arena");
|
|
2272
|
+
}
|
|
2273
|
+
static allocate = allocate;
|
|
2274
|
+
static copy = copy$1;
|
|
2275
|
+
static getBuffer = getBuffer;
|
|
2276
|
+
static getNumSegments = getNumSegments;
|
|
2277
|
+
};
|
|
2278
|
+
function allocate(minSize, segments, a) {
|
|
2279
|
+
switch (a.kind) {
|
|
2280
|
+
case ArenaKind.MULTI_SEGMENT: {
|
|
2281
|
+
return MultiSegmentArena.allocate(minSize, a);
|
|
2282
|
+
}
|
|
2283
|
+
case ArenaKind.SINGLE_SEGMENT: {
|
|
2284
|
+
return SingleSegmentArena.allocate(minSize, segments, a);
|
|
2285
|
+
}
|
|
2286
|
+
default: {
|
|
2287
|
+
return assertNever(a);
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
__name(allocate, "allocate");
|
|
2292
|
+
function copy$1(a) {
|
|
2293
|
+
switch (a.kind) {
|
|
2294
|
+
case ArenaKind.MULTI_SEGMENT: {
|
|
2295
|
+
let i = a.buffers.length;
|
|
2296
|
+
const buffers = Array.from({ length: i });
|
|
2297
|
+
while (--i >= 0) {
|
|
2298
|
+
buffers[i] = a.buffers[i].slice(0);
|
|
2299
|
+
}
|
|
2300
|
+
return new MultiSegmentArena(buffers);
|
|
2301
|
+
}
|
|
2302
|
+
case ArenaKind.SINGLE_SEGMENT: {
|
|
2303
|
+
return new SingleSegmentArena(a.buffer.slice(0));
|
|
2304
|
+
}
|
|
2305
|
+
default: {
|
|
2306
|
+
return assertNever(a);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
__name(copy$1, "copy$1");
|
|
2311
|
+
function getBuffer(id, a) {
|
|
2312
|
+
switch (a.kind) {
|
|
2313
|
+
case ArenaKind.MULTI_SEGMENT: {
|
|
2314
|
+
return MultiSegmentArena.getBuffer(id, a);
|
|
2315
|
+
}
|
|
2316
|
+
case ArenaKind.SINGLE_SEGMENT: {
|
|
2317
|
+
return SingleSegmentArena.getBuffer(id, a);
|
|
2318
|
+
}
|
|
2319
|
+
default: {
|
|
2320
|
+
return assertNever(a);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
__name(getBuffer, "getBuffer");
|
|
2325
|
+
function getNumSegments(a) {
|
|
2326
|
+
switch (a.kind) {
|
|
2327
|
+
case ArenaKind.MULTI_SEGMENT: {
|
|
2328
|
+
return MultiSegmentArena.getNumSegments(a);
|
|
2329
|
+
}
|
|
2330
|
+
case ArenaKind.SINGLE_SEGMENT: {
|
|
2331
|
+
return SingleSegmentArena.getNumSegments();
|
|
2332
|
+
}
|
|
2333
|
+
default: {
|
|
2334
|
+
return assertNever(a);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
__name(getNumSegments, "getNumSegments");
|
|
2339
|
+
function getHammingWeight(x) {
|
|
2340
|
+
let w = x - (x >> 1 & 1431655765);
|
|
2341
|
+
w = (w & 858993459) + (w >> 2 & 858993459);
|
|
2342
|
+
return (w + (w >> 4) & 252645135) * 16843009 >> 24;
|
|
2343
|
+
}
|
|
2344
|
+
__name(getHammingWeight, "getHammingWeight");
|
|
2345
|
+
function getTagByte(a, b, c, d, e, f, g, h) {
|
|
2346
|
+
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);
|
|
2347
|
+
}
|
|
2348
|
+
__name(getTagByte, "getTagByte");
|
|
2349
|
+
function getUnpackedByteLength(packed) {
|
|
2350
|
+
const p = new Uint8Array(packed);
|
|
2351
|
+
let wordCount = 0;
|
|
2352
|
+
let lastTag = 119;
|
|
2353
|
+
for (let i = 0; i < p.byteLength; ) {
|
|
2354
|
+
const tag = p[i];
|
|
2355
|
+
if (lastTag === 0) {
|
|
2356
|
+
wordCount += tag;
|
|
2357
|
+
i++;
|
|
2358
|
+
lastTag = 119;
|
|
2359
|
+
} else if (lastTag === 255) {
|
|
2360
|
+
wordCount += tag;
|
|
2361
|
+
i += tag * 8 + 1;
|
|
2362
|
+
lastTag = 119;
|
|
2363
|
+
} else {
|
|
2364
|
+
wordCount++;
|
|
2365
|
+
i += getHammingWeight(tag) + 1;
|
|
2366
|
+
lastTag = tag;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
return wordCount * 8;
|
|
2370
|
+
}
|
|
2371
|
+
__name(getUnpackedByteLength, "getUnpackedByteLength");
|
|
2372
|
+
function getZeroByteCount(a, b, c, d, e, f, g, h) {
|
|
2373
|
+
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);
|
|
2374
|
+
}
|
|
2375
|
+
__name(getZeroByteCount, "getZeroByteCount");
|
|
2376
|
+
function pack(unpacked, byteOffset = 0, byteLength) {
|
|
2377
|
+
if (unpacked.byteLength % 8 !== 0) {
|
|
2378
|
+
throw new Error(MSG_PACK_NOT_WORD_ALIGNED);
|
|
2379
|
+
}
|
|
2380
|
+
const src = new Uint8Array(unpacked, byteOffset, byteLength);
|
|
2381
|
+
const dst = [];
|
|
2382
|
+
let lastTag = 119;
|
|
2383
|
+
let spanWordCountOffset = 0;
|
|
2384
|
+
let rangeWordCount = 0;
|
|
2385
|
+
for (let srcByteOffset = 0; srcByteOffset < src.byteLength; srcByteOffset += 8) {
|
|
2386
|
+
const a = src[srcByteOffset];
|
|
2387
|
+
const b = src[srcByteOffset + 1];
|
|
2388
|
+
const c = src[srcByteOffset + 2];
|
|
2389
|
+
const d = src[srcByteOffset + 3];
|
|
2390
|
+
const e = src[srcByteOffset + 4];
|
|
2391
|
+
const f = src[srcByteOffset + 5];
|
|
2392
|
+
const g = src[srcByteOffset + 6];
|
|
2393
|
+
const h = src[srcByteOffset + 7];
|
|
2394
|
+
const tag = getTagByte(a, b, c, d, e, f, g, h);
|
|
2395
|
+
let skipWriteWord = true;
|
|
2396
|
+
switch (lastTag) {
|
|
2397
|
+
case 0: {
|
|
2398
|
+
if (tag !== 0 || rangeWordCount >= 255) {
|
|
2399
|
+
dst.push(rangeWordCount);
|
|
2400
|
+
rangeWordCount = 0;
|
|
2401
|
+
skipWriteWord = false;
|
|
2402
|
+
} else {
|
|
2403
|
+
rangeWordCount++;
|
|
2404
|
+
}
|
|
2405
|
+
break;
|
|
2406
|
+
}
|
|
2407
|
+
case 255: {
|
|
2408
|
+
const zeroCount = getZeroByteCount(a, b, c, d, e, f, g, h);
|
|
2409
|
+
if (zeroCount >= PACK_SPAN_THRESHOLD || rangeWordCount >= 255) {
|
|
2410
|
+
dst[spanWordCountOffset] = rangeWordCount;
|
|
2411
|
+
rangeWordCount = 0;
|
|
2412
|
+
skipWriteWord = false;
|
|
2413
|
+
} else {
|
|
2414
|
+
dst.push(a, b, c, d, e, f, g, h);
|
|
2415
|
+
rangeWordCount++;
|
|
2416
|
+
}
|
|
2417
|
+
break;
|
|
2418
|
+
}
|
|
2419
|
+
default: {
|
|
2420
|
+
skipWriteWord = false;
|
|
2421
|
+
break;
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
if (skipWriteWord) {
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
dst.push(tag);
|
|
2428
|
+
lastTag = tag;
|
|
2429
|
+
if (a !== 0) dst.push(a);
|
|
2430
|
+
if (b !== 0) dst.push(b);
|
|
2431
|
+
if (c !== 0) dst.push(c);
|
|
2432
|
+
if (d !== 0) dst.push(d);
|
|
2433
|
+
if (e !== 0) dst.push(e);
|
|
2434
|
+
if (f !== 0) dst.push(f);
|
|
2435
|
+
if (g !== 0) dst.push(g);
|
|
2436
|
+
if (h !== 0) dst.push(h);
|
|
2437
|
+
if (tag === 255) {
|
|
2438
|
+
spanWordCountOffset = dst.length;
|
|
2439
|
+
dst.push(0);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
if (lastTag === 0) {
|
|
2443
|
+
dst.push(rangeWordCount);
|
|
2444
|
+
} else if (lastTag === 255) {
|
|
2445
|
+
dst[spanWordCountOffset] = rangeWordCount;
|
|
2446
|
+
}
|
|
2447
|
+
return new Uint8Array(dst).buffer;
|
|
2448
|
+
}
|
|
2449
|
+
__name(pack, "pack");
|
|
2450
|
+
function unpack(packed) {
|
|
2451
|
+
const src = new Uint8Array(packed);
|
|
2452
|
+
const dst = new Uint8Array(new ArrayBuffer(getUnpackedByteLength(packed)));
|
|
2453
|
+
let lastTag = 119;
|
|
2454
|
+
for (let srcByteOffset = 0, dstByteOffset = 0; srcByteOffset < src.byteLength; ) {
|
|
2455
|
+
const tag = src[srcByteOffset];
|
|
2456
|
+
if (lastTag === 0) {
|
|
2457
|
+
dstByteOffset += tag * 8;
|
|
2458
|
+
srcByteOffset++;
|
|
2459
|
+
lastTag = 119;
|
|
2460
|
+
} else if (lastTag === 255) {
|
|
2461
|
+
const spanByteLength = tag * 8;
|
|
2462
|
+
dst.set(
|
|
2463
|
+
src.subarray(srcByteOffset + 1, srcByteOffset + 1 + spanByteLength),
|
|
2464
|
+
dstByteOffset
|
|
2465
|
+
);
|
|
2466
|
+
dstByteOffset += spanByteLength;
|
|
2467
|
+
srcByteOffset += 1 + spanByteLength;
|
|
2468
|
+
lastTag = 119;
|
|
2469
|
+
} else {
|
|
2470
|
+
srcByteOffset++;
|
|
2471
|
+
for (let i = 1; i <= 128; i <<= 1) {
|
|
2472
|
+
if ((tag & i) !== 0) {
|
|
2473
|
+
dst[dstByteOffset] = src[srcByteOffset++];
|
|
2474
|
+
}
|
|
2475
|
+
dstByteOffset++;
|
|
2476
|
+
}
|
|
2477
|
+
lastTag = tag;
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return dst.buffer;
|
|
2481
|
+
}
|
|
2482
|
+
__name(unpack, "unpack");
|
|
2483
|
+
var Segment = class {
|
|
2484
|
+
static {
|
|
2485
|
+
__name(this, "Segment");
|
|
2486
|
+
}
|
|
2487
|
+
constructor(id, message, buffer, byteLength = 0) {
|
|
2488
|
+
this.id = id;
|
|
2489
|
+
this.message = message;
|
|
2490
|
+
this.message = message;
|
|
2491
|
+
this.buffer = buffer;
|
|
2492
|
+
this._dv = new DataView(buffer);
|
|
2493
|
+
this.byteOffset = 0;
|
|
2494
|
+
this.byteLength = byteLength;
|
|
2495
|
+
}
|
|
2496
|
+
buffer;
|
|
2497
|
+
/** The number of bytes currently allocated in the segment. */
|
|
2498
|
+
byteLength;
|
|
2499
|
+
/**
|
|
2500
|
+
* This value should always be zero. It's only here to satisfy the DataView interface.
|
|
2501
|
+
*
|
|
2502
|
+
* In the future the Segment implementation (or a child class) may allow accessing the buffer from a nonzero offset,
|
|
2503
|
+
* but that adds a lot of extra arithmetic.
|
|
2504
|
+
*/
|
|
2505
|
+
byteOffset;
|
|
2506
|
+
[Symbol.toStringTag] = "Segment";
|
|
2507
|
+
_dv;
|
|
2508
|
+
/**
|
|
2509
|
+
* Attempt to allocate the requested number of bytes in this segment. If this segment is full this method will return
|
|
2510
|
+
* a pointer to freshly allocated space in another segment from the same message.
|
|
2511
|
+
*
|
|
2512
|
+
* @param byteLength The number of bytes to allocate, will be rounded up to the nearest word.
|
|
2513
|
+
* @returns A pointer to the newly allocated space.
|
|
2514
|
+
*/
|
|
2515
|
+
allocate(byteLength) {
|
|
2516
|
+
let segment = this;
|
|
2517
|
+
byteLength = padToWord$1(byteLength);
|
|
2518
|
+
if (byteLength > MAX_SEGMENT_LENGTH - 8) {
|
|
2519
|
+
throw new Error(format(SEG_SIZE_OVERFLOW, byteLength));
|
|
2520
|
+
}
|
|
2521
|
+
if (!segment.hasCapacity(byteLength)) {
|
|
2522
|
+
segment = segment.message.allocateSegment(byteLength);
|
|
2523
|
+
}
|
|
2524
|
+
const byteOffset = segment.byteLength;
|
|
2525
|
+
segment.byteLength += byteLength;
|
|
2526
|
+
return new Pointer(segment, byteOffset);
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Quickly copy a word (8 bytes) from `srcSegment` into this one at the given offset.
|
|
2530
|
+
*
|
|
2531
|
+
* @param byteOffset The offset to write the word to.
|
|
2532
|
+
* @param srcSegment The segment to copy the word from.
|
|
2533
|
+
* @param srcByteOffset The offset from the start of `srcSegment` to copy from.
|
|
2534
|
+
*/
|
|
2535
|
+
copyWord(byteOffset, srcSegment, srcByteOffset) {
|
|
2536
|
+
const value = srcSegment._dv.getFloat64(
|
|
2537
|
+
srcByteOffset,
|
|
2538
|
+
NATIVE_LITTLE_ENDIAN
|
|
2539
|
+
);
|
|
2540
|
+
this._dv.setFloat64(byteOffset, value, NATIVE_LITTLE_ENDIAN);
|
|
2541
|
+
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Quickly copy words from `srcSegment` into this one.
|
|
2544
|
+
*
|
|
2545
|
+
* @param byteOffset The offset to start copying into.
|
|
2546
|
+
* @param srcSegment The segment to copy from.
|
|
2547
|
+
* @param srcByteOffset The start offset to copy from.
|
|
2548
|
+
* @param wordLength The number of words to copy.
|
|
2549
|
+
*/
|
|
2550
|
+
copyWords(byteOffset, srcSegment, srcByteOffset, wordLength) {
|
|
2551
|
+
const dst = new Float64Array(this.buffer, byteOffset, wordLength);
|
|
2552
|
+
const src = new Float64Array(srcSegment.buffer, srcByteOffset, wordLength);
|
|
2553
|
+
dst.set(src);
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Quickly fill a number of words in the buffer with zeroes.
|
|
2557
|
+
*
|
|
2558
|
+
* @param byteOffset The first byte to set to zero.
|
|
2559
|
+
* @param wordLength The number of words (not bytes!) to zero out.
|
|
2560
|
+
*/
|
|
2561
|
+
fillZeroWords(byteOffset, wordLength) {
|
|
2562
|
+
new Float64Array(this.buffer, byteOffset, wordLength).fill(0);
|
|
2563
|
+
}
|
|
2564
|
+
getBigInt64(byteOffset, littleEndian) {
|
|
2565
|
+
return this._dv.getBigInt64(byteOffset, littleEndian);
|
|
2566
|
+
}
|
|
2567
|
+
getBigUint64(byteOffset, littleEndian) {
|
|
2568
|
+
return this._dv.getBigUint64(byteOffset, littleEndian);
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* Get the total number of bytes available in this segment (the size of its underlying buffer).
|
|
2572
|
+
*
|
|
2573
|
+
* @returns The total number of bytes this segment can hold.
|
|
2574
|
+
*/
|
|
2575
|
+
getCapacity() {
|
|
2576
|
+
return this.buffer.byteLength;
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Read a float32 value out of this segment.
|
|
2580
|
+
*
|
|
2581
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2582
|
+
* @returns The value.
|
|
2583
|
+
*/
|
|
2584
|
+
getFloat32(byteOffset) {
|
|
2585
|
+
return this._dv.getFloat32(byteOffset, true);
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* Read a float64 value out of this segment.
|
|
2589
|
+
*
|
|
2590
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2591
|
+
* @returns The value.
|
|
2592
|
+
*/
|
|
2593
|
+
getFloat64(byteOffset) {
|
|
2594
|
+
return this._dv.getFloat64(byteOffset, true);
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* Read an int16 value out of this segment.
|
|
2598
|
+
*
|
|
2599
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2600
|
+
* @returns The value.
|
|
2601
|
+
*/
|
|
2602
|
+
getInt16(byteOffset) {
|
|
2603
|
+
return this._dv.getInt16(byteOffset, true);
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* Read an int32 value out of this segment.
|
|
2607
|
+
*
|
|
2608
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2609
|
+
* @returns The value.
|
|
2610
|
+
*/
|
|
2611
|
+
getInt32(byteOffset) {
|
|
2612
|
+
return this._dv.getInt32(byteOffset, true);
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Read an int64 value out of this segment.
|
|
2616
|
+
*
|
|
2617
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2618
|
+
* @returns The value.
|
|
2619
|
+
*/
|
|
2620
|
+
getInt64(byteOffset) {
|
|
2621
|
+
return this._dv.getBigInt64(byteOffset, true);
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Read an int8 value out of this segment.
|
|
2625
|
+
*
|
|
2626
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2627
|
+
* @returns The value.
|
|
2628
|
+
*/
|
|
2629
|
+
getInt8(byteOffset) {
|
|
2630
|
+
return this._dv.getInt8(byteOffset);
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Read a uint16 value out of this segment.
|
|
2634
|
+
*
|
|
2635
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2636
|
+
* @returns The value.
|
|
2637
|
+
*/
|
|
2638
|
+
getUint16(byteOffset) {
|
|
2639
|
+
return this._dv.getUint16(byteOffset, true);
|
|
2640
|
+
}
|
|
2641
|
+
/**
|
|
2642
|
+
* Read a uint32 value out of this segment.
|
|
2643
|
+
*
|
|
2644
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2645
|
+
* @returns The value.
|
|
2646
|
+
*/
|
|
2647
|
+
getUint32(byteOffset) {
|
|
2648
|
+
return this._dv.getUint32(byteOffset, true);
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Read a uint64 value (as a bigint) out of this segment.
|
|
2652
|
+
* NOTE: this does not copy the memory region, so updates to the underlying buffer will affect the returned value!
|
|
2653
|
+
*
|
|
2654
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2655
|
+
* @returns The value.
|
|
2656
|
+
*/
|
|
2657
|
+
getUint64(byteOffset) {
|
|
2658
|
+
return this._dv.getBigUint64(byteOffset, true);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Read a uint8 value out of this segment.
|
|
2662
|
+
*
|
|
2663
|
+
* @param byteOffset The offset in bytes to the value.
|
|
2664
|
+
* @returns The value.
|
|
2665
|
+
*/
|
|
2666
|
+
getUint8(byteOffset) {
|
|
2667
|
+
return this._dv.getUint8(byteOffset);
|
|
2668
|
+
}
|
|
2669
|
+
hasCapacity(byteLength) {
|
|
2670
|
+
return this.buffer.byteLength - this.byteLength >= byteLength;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* Quickly check the word at the given offset to see if it is equal to zero.
|
|
2674
|
+
*
|
|
2675
|
+
* PERF_V8: Fastest way to do this is by reading the whole word as a `number` (float64) in the _native_ endian format
|
|
2676
|
+
* and see if it's zero.
|
|
2677
|
+
*
|
|
2678
|
+
* Benchmark: http://jsben.ch/#/Pjooc
|
|
2679
|
+
*
|
|
2680
|
+
* @param byteOffset The offset to the word.
|
|
2681
|
+
* @returns `true` if the word is zero.
|
|
2682
|
+
*/
|
|
2683
|
+
isWordZero(byteOffset) {
|
|
2684
|
+
return this._dv.getFloat64(byteOffset, NATIVE_LITTLE_ENDIAN) === 0;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Swap out this segment's underlying buffer with a new one. It's assumed that the new buffer has the same content but
|
|
2688
|
+
* more free space, otherwise all existing pointers to this segment will be hilariously broken.
|
|
2689
|
+
*
|
|
2690
|
+
* @param buffer The new buffer to use.
|
|
2691
|
+
*/
|
|
2692
|
+
replaceBuffer(buffer) {
|
|
2693
|
+
if (this.buffer === buffer) {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2696
|
+
if (buffer.byteLength < this.byteLength) {
|
|
2697
|
+
throw new Error(SEG_REPLACEMENT_BUFFER_TOO_SMALL);
|
|
2698
|
+
}
|
|
2699
|
+
this._dv = new DataView(buffer);
|
|
2700
|
+
this.buffer = buffer;
|
|
2701
|
+
}
|
|
2702
|
+
setBigInt64(byteOffset, value, littleEndian) {
|
|
2703
|
+
this._dv.setBigInt64(byteOffset, value, littleEndian);
|
|
2704
|
+
}
|
|
2705
|
+
/** WARNING: This function is not yet implemented. */
|
|
2706
|
+
setBigUint64(byteOffset, value, littleEndian) {
|
|
2707
|
+
this._dv.setBigUint64(byteOffset, value, littleEndian);
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* Write a float32 value to the specified offset.
|
|
2711
|
+
*
|
|
2712
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2713
|
+
* @param val The value to store.
|
|
2714
|
+
*/
|
|
2715
|
+
setFloat32(byteOffset, val) {
|
|
2716
|
+
this._dv.setFloat32(byteOffset, val, true);
|
|
2717
|
+
}
|
|
2718
|
+
/**
|
|
2719
|
+
* Write an float64 value to the specified offset.
|
|
2720
|
+
*
|
|
2721
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2722
|
+
* @param val The value to store.
|
|
2723
|
+
*/
|
|
2724
|
+
setFloat64(byteOffset, val) {
|
|
2725
|
+
this._dv.setFloat64(byteOffset, val, true);
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2728
|
+
* Write an int16 value to the specified offset.
|
|
2729
|
+
*
|
|
2730
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2731
|
+
* @param val The value to store.
|
|
2732
|
+
*/
|
|
2733
|
+
setInt16(byteOffset, val) {
|
|
2734
|
+
this._dv.setInt16(byteOffset, val, true);
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Write an int32 value to the specified offset.
|
|
2738
|
+
*
|
|
2739
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2740
|
+
* @param val The value to store.
|
|
2741
|
+
*/
|
|
2742
|
+
setInt32(byteOffset, val) {
|
|
2743
|
+
this._dv.setInt32(byteOffset, val, true);
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* Write an int8 value to the specified offset.
|
|
2747
|
+
*
|
|
2748
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2749
|
+
* @param val The value to store.
|
|
2750
|
+
*/
|
|
2751
|
+
setInt8(byteOffset, val) {
|
|
2752
|
+
this._dv.setInt8(byteOffset, val);
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Write an int64 value to the specified offset.
|
|
2756
|
+
*
|
|
2757
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2758
|
+
* @param val The value to store.
|
|
2759
|
+
*/
|
|
2760
|
+
setInt64(byteOffset, val) {
|
|
2761
|
+
this._dv.setBigInt64(byteOffset, val, true);
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Write a uint16 value to the specified offset.
|
|
2765
|
+
*
|
|
2766
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2767
|
+
* @param val The value to store.
|
|
2768
|
+
*/
|
|
2769
|
+
setUint16(byteOffset, val) {
|
|
2770
|
+
this._dv.setUint16(byteOffset, val, true);
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Write a uint32 value to the specified offset.
|
|
2774
|
+
*
|
|
2775
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2776
|
+
* @param val The value to store.
|
|
2777
|
+
*/
|
|
2778
|
+
setUint32(byteOffset, val) {
|
|
2779
|
+
this._dv.setUint32(byteOffset, val, true);
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* Write a uint64 value to the specified offset.
|
|
2783
|
+
*
|
|
2784
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2785
|
+
* @param val The value to store.
|
|
2786
|
+
*/
|
|
2787
|
+
setUint64(byteOffset, val) {
|
|
2788
|
+
this._dv.setBigUint64(byteOffset, val, true);
|
|
2789
|
+
}
|
|
2790
|
+
/**
|
|
2791
|
+
* Write a uint8 (byte) value to the specified offset.
|
|
2792
|
+
*
|
|
2793
|
+
* @param byteOffset The offset from the beginning of the buffer.
|
|
2794
|
+
* @param val The value to store.
|
|
2795
|
+
*/
|
|
2796
|
+
setUint8(byteOffset, val) {
|
|
2797
|
+
this._dv.setUint8(byteOffset, val);
|
|
2798
|
+
}
|
|
2799
|
+
/**
|
|
2800
|
+
* Write a zero word (8 bytes) to the specified offset. This is slightly faster than calling `setUint64` or
|
|
2801
|
+
* `setFloat64` with a zero value.
|
|
2802
|
+
*
|
|
2803
|
+
* Benchmark: http://jsben.ch/#/dUdPI
|
|
2804
|
+
*
|
|
2805
|
+
* @param byteOffset The offset of the word to set to zero.
|
|
2806
|
+
*/
|
|
2807
|
+
setWordZero(byteOffset) {
|
|
2808
|
+
this._dv.setFloat64(byteOffset, 0, NATIVE_LITTLE_ENDIAN);
|
|
2809
|
+
}
|
|
2810
|
+
toString() {
|
|
2811
|
+
return format(
|
|
2812
|
+
"Segment_id:%d,off:%a,len:%a,cap:%a",
|
|
2813
|
+
this.id,
|
|
2814
|
+
this.byteLength,
|
|
2815
|
+
this.byteOffset,
|
|
2816
|
+
this.buffer.byteLength
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2819
|
+
};
|
|
2820
|
+
var Message = class {
|
|
2821
|
+
static {
|
|
2822
|
+
__name(this, "Message");
|
|
2823
|
+
}
|
|
2824
|
+
static allocateSegment = allocateSegment;
|
|
2825
|
+
static dump = dump2;
|
|
2826
|
+
static getRoot = getRoot;
|
|
2827
|
+
static getSegment = getSegment;
|
|
2828
|
+
static initRoot = initRoot;
|
|
2829
|
+
static readRawPointer = readRawPointer;
|
|
2830
|
+
static toArrayBuffer = toArrayBuffer;
|
|
2831
|
+
static toPackedArrayBuffer = toPackedArrayBuffer;
|
|
2832
|
+
_capnp;
|
|
2833
|
+
/**
|
|
2834
|
+
* A Cap'n Proto message.
|
|
2835
|
+
*
|
|
2836
|
+
* SECURITY WARNING: In Node.js do not pass a Buffer's internal array buffer into this constructor. Pass the buffer
|
|
2837
|
+
* directly and everything will be fine. If not, your message will potentially be initialized with random memory
|
|
2838
|
+
* contents!
|
|
2839
|
+
*
|
|
2840
|
+
* The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer
|
|
2841
|
+
* to read from.
|
|
2842
|
+
*
|
|
2843
|
+
* @param src The source for the message.
|
|
2844
|
+
* A value of `undefined` will cause the message to initialize with a single segment arena only big enough for the
|
|
2845
|
+
* root pointer; it will expand as you go. This is a reasonable choice for most messages.
|
|
2846
|
+
*
|
|
2847
|
+
* Passing an arena will cause the message to use that arena for its segment allocation. Contents will be accepted
|
|
2848
|
+
* as-is.
|
|
2849
|
+
*
|
|
2850
|
+
* Passing an array buffer view (like `DataView`, `Uint8Array` or `Buffer`) will create a **copy** of the source
|
|
2851
|
+
* buffer; beware of the potential performance cost!
|
|
2852
|
+
*
|
|
2853
|
+
* @param packed Whether or not the message is packed. If `true` (the default), the message will be
|
|
2854
|
+
* unpacked.
|
|
2855
|
+
*
|
|
2856
|
+
* @param singleSegment If true, `src` will be treated as a message consisting of a single segment without
|
|
2857
|
+
* a framing header.
|
|
2858
|
+
*
|
|
2859
|
+
*/
|
|
2860
|
+
constructor(src, packed = true, singleSegment = false) {
|
|
2861
|
+
this._capnp = initMessage(src, packed, singleSegment);
|
|
2862
|
+
if (src) {
|
|
2863
|
+
preallocateSegments(this);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
allocateSegment(byteLength) {
|
|
2867
|
+
return allocateSegment(byteLength, this);
|
|
2868
|
+
}
|
|
2869
|
+
/**
|
|
2870
|
+
* Copies the contents of this message into an identical message with its own ArrayBuffers.
|
|
2871
|
+
*
|
|
2872
|
+
* @returns A copy of this message.
|
|
2873
|
+
*/
|
|
2874
|
+
copy() {
|
|
2875
|
+
return copy(this);
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Create a pretty-printed string dump of this message; incredibly useful for debugging.
|
|
2879
|
+
*
|
|
2880
|
+
* WARNING: Do not call this method on large messages!
|
|
2881
|
+
*
|
|
2882
|
+
* @returns A big steaming pile of pretty hex digits.
|
|
2883
|
+
*/
|
|
2884
|
+
dump() {
|
|
2885
|
+
return dump2(this);
|
|
2886
|
+
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not
|
|
2889
|
+
* overwrite existing data.
|
|
2890
|
+
*
|
|
2891
|
+
* @param RootStruct The struct type to use as the root.
|
|
2892
|
+
* @returns A struct representing the root of the message.
|
|
2893
|
+
*/
|
|
2894
|
+
getRoot(RootStruct) {
|
|
2895
|
+
return getRoot(RootStruct, this);
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Get a segment by its id.
|
|
2899
|
+
*
|
|
2900
|
+
* This will lazily allocate the first segment if it doesn't already exist.
|
|
2901
|
+
*
|
|
2902
|
+
* @param id The segment id.
|
|
2903
|
+
* @returns The requested segment.
|
|
2904
|
+
*/
|
|
2905
|
+
getSegment(id) {
|
|
2906
|
+
return getSegment(id, this);
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Initialize a new message using the provided struct type as the root.
|
|
2910
|
+
*
|
|
2911
|
+
* @param RootStruct The struct type to use as the root.
|
|
2912
|
+
* @returns An initialized struct pointing to the root of the message.
|
|
2913
|
+
*/
|
|
2914
|
+
initRoot(RootStruct) {
|
|
2915
|
+
return initRoot(RootStruct, this);
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* Set the root of the message to a copy of the given pointer. Used internally
|
|
2919
|
+
* to make copies of pointers for default values.
|
|
2920
|
+
*
|
|
2921
|
+
* @param src The source pointer to copy.
|
|
2922
|
+
*/
|
|
2923
|
+
setRoot(src) {
|
|
2924
|
+
setRoot(src, this);
|
|
2925
|
+
}
|
|
2926
|
+
/**
|
|
2927
|
+
* Combine the contents of this message's segments into a single array buffer and prepend a stream framing header
|
|
2928
|
+
* containing information about the following segment data.
|
|
2929
|
+
*
|
|
2930
|
+
* @returns An ArrayBuffer with the contents of this message.
|
|
2931
|
+
*/
|
|
2932
|
+
toArrayBuffer() {
|
|
2933
|
+
return toArrayBuffer(this);
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Like `toArrayBuffer()`, but also applies the packing algorithm to the output. This is typically what you want to
|
|
2937
|
+
* use if you're sending the message over a network link or other slow I/O interface where size matters.
|
|
2938
|
+
*
|
|
2939
|
+
* @returns A packed message.
|
|
2940
|
+
*/
|
|
2941
|
+
toPackedArrayBuffer() {
|
|
2942
|
+
return toPackedArrayBuffer(this);
|
|
2943
|
+
}
|
|
2944
|
+
addCap(client) {
|
|
2945
|
+
if (!this._capnp.capTable) {
|
|
2946
|
+
this._capnp.capTable = [];
|
|
2947
|
+
}
|
|
2948
|
+
const id = this._capnp.capTable.length;
|
|
2949
|
+
this._capnp.capTable.push(client);
|
|
2950
|
+
return id;
|
|
2951
|
+
}
|
|
2952
|
+
toString() {
|
|
2953
|
+
return `Message_arena:${this._capnp.arena}`;
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
function initMessage(src, packed = true, singleSegment = false) {
|
|
2957
|
+
if (src === void 0) {
|
|
2958
|
+
return {
|
|
2959
|
+
arena: new SingleSegmentArena(),
|
|
2960
|
+
segments: [],
|
|
2961
|
+
traversalLimit: DEFAULT_TRAVERSE_LIMIT
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
if (isAnyArena(src)) {
|
|
2965
|
+
return { arena: src, segments: [], traversalLimit: DEFAULT_TRAVERSE_LIMIT };
|
|
2966
|
+
}
|
|
2967
|
+
let buf = src;
|
|
2968
|
+
if (isArrayBufferView(buf)) {
|
|
2969
|
+
buf = buf.buffer.slice(
|
|
2970
|
+
buf.byteOffset,
|
|
2971
|
+
buf.byteOffset + buf.byteLength
|
|
2972
|
+
);
|
|
2973
|
+
}
|
|
2974
|
+
if (packed) {
|
|
2975
|
+
buf = unpack(buf);
|
|
2976
|
+
}
|
|
2977
|
+
if (singleSegment) {
|
|
2978
|
+
return {
|
|
2979
|
+
arena: new SingleSegmentArena(buf),
|
|
2980
|
+
segments: [],
|
|
2981
|
+
traversalLimit: DEFAULT_TRAVERSE_LIMIT
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
return {
|
|
2985
|
+
arena: new MultiSegmentArena(getFramedSegments(buf)),
|
|
2986
|
+
segments: [],
|
|
2987
|
+
traversalLimit: DEFAULT_TRAVERSE_LIMIT
|
|
2988
|
+
};
|
|
2989
|
+
}
|
|
2990
|
+
__name(initMessage, "initMessage");
|
|
2991
|
+
function getFramedSegments(message) {
|
|
2992
|
+
const dv = new DataView(message);
|
|
2993
|
+
const segmentCount = dv.getUint32(0, true) + 1;
|
|
2994
|
+
const segments = Array.from({ length: segmentCount });
|
|
2995
|
+
let byteOffset = 4 + segmentCount * 4;
|
|
2996
|
+
byteOffset += byteOffset % 8;
|
|
2997
|
+
if (byteOffset + segmentCount * 4 > message.byteLength) {
|
|
2998
|
+
throw new Error(MSG_INVALID_FRAME_HEADER);
|
|
2999
|
+
}
|
|
3000
|
+
for (let i = 0; i < segmentCount; i++) {
|
|
3001
|
+
const byteLength = dv.getUint32(4 + i * 4, true) * 8;
|
|
3002
|
+
if (byteOffset + byteLength > message.byteLength) {
|
|
3003
|
+
throw new Error(MSG_INVALID_FRAME_HEADER);
|
|
3004
|
+
}
|
|
3005
|
+
segments[i] = message.slice(byteOffset, byteOffset + byteLength);
|
|
3006
|
+
byteOffset += byteLength;
|
|
3007
|
+
}
|
|
3008
|
+
return segments;
|
|
3009
|
+
}
|
|
3010
|
+
__name(getFramedSegments, "getFramedSegments");
|
|
3011
|
+
function preallocateSegments(m) {
|
|
3012
|
+
const numSegments = Arena.getNumSegments(m._capnp.arena);
|
|
3013
|
+
m._capnp.segments = Array.from({ length: numSegments });
|
|
3014
|
+
for (let i = 0; i < numSegments; i++) {
|
|
3015
|
+
if (i === 0 && Arena.getBuffer(i, m._capnp.arena).byteLength < 8) {
|
|
3016
|
+
throw new Error(MSG_SEGMENT_TOO_SMALL);
|
|
3017
|
+
}
|
|
3018
|
+
const buffer = Arena.getBuffer(i, m._capnp.arena);
|
|
3019
|
+
const segment = new Segment(i, m, buffer, buffer.byteLength);
|
|
3020
|
+
m._capnp.segments[i] = segment;
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
__name(preallocateSegments, "preallocateSegments");
|
|
3024
|
+
function isArrayBufferView(src) {
|
|
3025
|
+
return src.byteOffset !== void 0;
|
|
3026
|
+
}
|
|
3027
|
+
__name(isArrayBufferView, "isArrayBufferView");
|
|
3028
|
+
function isAnyArena(o) {
|
|
3029
|
+
return o.kind !== void 0;
|
|
3030
|
+
}
|
|
3031
|
+
__name(isAnyArena, "isAnyArena");
|
|
3032
|
+
function allocateSegment(byteLength, m) {
|
|
3033
|
+
const res = Arena.allocate(byteLength, m._capnp.segments, m._capnp.arena);
|
|
3034
|
+
let s;
|
|
3035
|
+
if (res.id === m._capnp.segments.length) {
|
|
3036
|
+
s = new Segment(res.id, m, res.buffer);
|
|
3037
|
+
m._capnp.segments.push(s);
|
|
3038
|
+
} else if (res.id < 0 || res.id > m._capnp.segments.length) {
|
|
3039
|
+
throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, res.id, m));
|
|
3040
|
+
} else {
|
|
3041
|
+
s = m._capnp.segments[res.id];
|
|
3042
|
+
s.replaceBuffer(res.buffer);
|
|
3043
|
+
}
|
|
3044
|
+
return s;
|
|
3045
|
+
}
|
|
3046
|
+
__name(allocateSegment, "allocateSegment");
|
|
3047
|
+
function dump2(m) {
|
|
3048
|
+
let r = "";
|
|
3049
|
+
if (m._capnp.segments.length === 0) {
|
|
3050
|
+
return "================\nNo Segments\n================\n";
|
|
3051
|
+
}
|
|
3052
|
+
for (let i = 0; i < m._capnp.segments.length; i++) {
|
|
3053
|
+
r += `================
|
|
3054
|
+
Segment #${i}
|
|
3055
|
+
================
|
|
3056
|
+
`;
|
|
3057
|
+
const { buffer, byteLength } = m._capnp.segments[i];
|
|
3058
|
+
const b = new Uint8Array(buffer, 0, byteLength);
|
|
3059
|
+
r += dumpBuffer(b);
|
|
3060
|
+
}
|
|
3061
|
+
return r;
|
|
3062
|
+
}
|
|
3063
|
+
__name(dump2, "dump");
|
|
3064
|
+
function getRoot(RootStruct, m) {
|
|
3065
|
+
const root = new RootStruct(m.getSegment(0), 0);
|
|
3066
|
+
validate(PointerType.STRUCT, root);
|
|
3067
|
+
const ts = getTargetStructSize(root);
|
|
3068
|
+
if (ts.dataByteLength < RootStruct._capnp.size.dataByteLength || ts.pointerLength < RootStruct._capnp.size.pointerLength) {
|
|
3069
|
+
resize(RootStruct._capnp.size, root);
|
|
3070
|
+
}
|
|
3071
|
+
return root;
|
|
3072
|
+
}
|
|
3073
|
+
__name(getRoot, "getRoot");
|
|
3074
|
+
function getSegment(id, m) {
|
|
3075
|
+
const segmentLength = m._capnp.segments.length;
|
|
3076
|
+
if (id === 0 && segmentLength === 0) {
|
|
3077
|
+
const arenaSegments = Arena.getNumSegments(m._capnp.arena);
|
|
3078
|
+
if (arenaSegments === 0) {
|
|
3079
|
+
allocateSegment(DEFAULT_BUFFER_SIZE, m);
|
|
3080
|
+
} else {
|
|
3081
|
+
m._capnp.segments[0] = new Segment(
|
|
3082
|
+
0,
|
|
3083
|
+
m,
|
|
3084
|
+
Arena.getBuffer(0, m._capnp.arena)
|
|
3085
|
+
);
|
|
3086
|
+
}
|
|
3087
|
+
if (!m._capnp.segments[0].hasCapacity(8)) {
|
|
3088
|
+
throw new Error(MSG_SEGMENT_TOO_SMALL);
|
|
3089
|
+
}
|
|
3090
|
+
m._capnp.segments[0].allocate(8);
|
|
3091
|
+
return m._capnp.segments[0];
|
|
3092
|
+
}
|
|
3093
|
+
if (id < 0 || id >= segmentLength) {
|
|
3094
|
+
throw new Error(format(MSG_SEGMENT_OUT_OF_BOUNDS, id, m));
|
|
3095
|
+
}
|
|
3096
|
+
return m._capnp.segments[id];
|
|
3097
|
+
}
|
|
3098
|
+
__name(getSegment, "getSegment");
|
|
3099
|
+
function initRoot(RootStruct, m) {
|
|
3100
|
+
const root = new RootStruct(m.getSegment(0), 0);
|
|
3101
|
+
initStruct(RootStruct._capnp.size, root);
|
|
3102
|
+
return root;
|
|
3103
|
+
}
|
|
3104
|
+
__name(initRoot, "initRoot");
|
|
3105
|
+
function readRawPointer(data) {
|
|
3106
|
+
return new Pointer(new Message(data).getSegment(0), 0);
|
|
3107
|
+
}
|
|
3108
|
+
__name(readRawPointer, "readRawPointer");
|
|
3109
|
+
function setRoot(src, m) {
|
|
3110
|
+
copyFrom(src, new Pointer(m.getSegment(0), 0));
|
|
3111
|
+
}
|
|
3112
|
+
__name(setRoot, "setRoot");
|
|
3113
|
+
function toArrayBuffer(m) {
|
|
3114
|
+
const streamFrame = getStreamFrame(m);
|
|
3115
|
+
if (m._capnp.segments.length === 0) {
|
|
3116
|
+
getSegment(0, m);
|
|
3117
|
+
}
|
|
3118
|
+
const { segments } = m._capnp;
|
|
3119
|
+
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + padToWord$1(s.byteLength), 0);
|
|
3120
|
+
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
|
3121
|
+
let o = streamFrame.byteLength;
|
|
3122
|
+
out.set(new Uint8Array(streamFrame));
|
|
3123
|
+
for (const s of segments) {
|
|
3124
|
+
const segmentLength = padToWord$1(s.byteLength);
|
|
3125
|
+
out.set(new Uint8Array(s.buffer, 0, segmentLength), o);
|
|
3126
|
+
o += segmentLength;
|
|
3127
|
+
}
|
|
3128
|
+
return out.buffer;
|
|
3129
|
+
}
|
|
3130
|
+
__name(toArrayBuffer, "toArrayBuffer");
|
|
3131
|
+
function toPackedArrayBuffer(m) {
|
|
3132
|
+
const streamFrame = pack(getStreamFrame(m));
|
|
3133
|
+
if (m._capnp.segments.length === 0) {
|
|
3134
|
+
m.getSegment(0);
|
|
3135
|
+
}
|
|
3136
|
+
const segments = m._capnp.segments.map(
|
|
3137
|
+
(s) => pack(s.buffer, 0, padToWord$1(s.byteLength))
|
|
3138
|
+
);
|
|
3139
|
+
const totalLength = streamFrame.byteLength + segments.reduce((l, s) => l + s.byteLength, 0);
|
|
3140
|
+
const out = new Uint8Array(new ArrayBuffer(totalLength));
|
|
3141
|
+
let o = streamFrame.byteLength;
|
|
3142
|
+
out.set(new Uint8Array(streamFrame));
|
|
3143
|
+
for (const s of segments) {
|
|
3144
|
+
out.set(new Uint8Array(s), o);
|
|
3145
|
+
o += s.byteLength;
|
|
3146
|
+
}
|
|
3147
|
+
return out.buffer;
|
|
3148
|
+
}
|
|
3149
|
+
__name(toPackedArrayBuffer, "toPackedArrayBuffer");
|
|
3150
|
+
function getStreamFrame(m) {
|
|
3151
|
+
const { length } = m._capnp.segments;
|
|
3152
|
+
if (length === 0) {
|
|
3153
|
+
return new Float64Array(1).buffer;
|
|
3154
|
+
}
|
|
3155
|
+
const frameLength = 4 + length * 4 + (1 - length % 2) * 4;
|
|
3156
|
+
const out = new DataView(new ArrayBuffer(frameLength));
|
|
3157
|
+
out.setUint32(0, length - 1, true);
|
|
3158
|
+
for (const [i, s] of m._capnp.segments.entries()) {
|
|
3159
|
+
out.setUint32(i * 4 + 4, s.byteLength / 8, true);
|
|
3160
|
+
}
|
|
3161
|
+
return out.buffer;
|
|
3162
|
+
}
|
|
3163
|
+
__name(getStreamFrame, "getStreamFrame");
|
|
3164
|
+
function copy(m) {
|
|
3165
|
+
return new Message(Arena.copy(m._capnp.arena));
|
|
3166
|
+
}
|
|
3167
|
+
__name(copy, "copy");
|
|
3168
|
+
|
|
3169
|
+
export {
|
|
3170
|
+
ListElementSize,
|
|
3171
|
+
MAX_DEPTH,
|
|
3172
|
+
INVARIANT_UNREACHABLE_CODE,
|
|
3173
|
+
NOT_IMPLEMENTED,
|
|
3174
|
+
RPC_NULL_CLIENT,
|
|
3175
|
+
RPC_CALL_QUEUE_FULL,
|
|
3176
|
+
RPC_QUEUE_CALL_CANCEL,
|
|
3177
|
+
RPC_ZERO_REF,
|
|
3178
|
+
RPC_IMPORT_CLOSED,
|
|
3179
|
+
RPC_METHOD_NOT_IMPLEMENTED,
|
|
3180
|
+
RPC_BAD_TARGET,
|
|
3181
|
+
RPC_RETURN_FOR_UNKNOWN_QUESTION,
|
|
3182
|
+
RPC_QUESTION_ID_REUSED,
|
|
3183
|
+
RPC_UNKNOWN_EXPORT_ID,
|
|
3184
|
+
RPC_UNKNOWN_ANSWER_ID,
|
|
3185
|
+
RPC_UNKNOWN_CAP_DESCRIPTOR,
|
|
3186
|
+
RPC_METHOD_ERROR,
|
|
3187
|
+
RPC_ERROR,
|
|
3188
|
+
RPC_NO_MAIN_INTERFACE,
|
|
3189
|
+
RPC_FINISH_UNKNOWN_ANSWER,
|
|
3190
|
+
RPC_FULFILL_ALREADY_CALLED,
|
|
3191
|
+
format,
|
|
3192
|
+
pad,
|
|
3193
|
+
ObjectSize,
|
|
3194
|
+
Orphan,
|
|
3195
|
+
adopt,
|
|
3196
|
+
disown,
|
|
3197
|
+
dump,
|
|
3198
|
+
getListByteLength,
|
|
3199
|
+
getListElementByteLength,
|
|
3200
|
+
add,
|
|
3201
|
+
copyFrom,
|
|
3202
|
+
erase,
|
|
3203
|
+
erasePointer,
|
|
3204
|
+
followFar,
|
|
3205
|
+
followFars,
|
|
3206
|
+
getCapabilityId,
|
|
3207
|
+
getContent,
|
|
3208
|
+
getFarSegmentId,
|
|
3209
|
+
getListElementSize,
|
|
3210
|
+
getListLength,
|
|
3211
|
+
getOffsetWords,
|
|
3212
|
+
getPointerType,
|
|
3213
|
+
getStructDataWords,
|
|
3214
|
+
getStructPointerLength,
|
|
3215
|
+
getStructSize,
|
|
3216
|
+
getTargetCompositeListTag,
|
|
3217
|
+
getTargetCompositeListSize,
|
|
3218
|
+
getTargetListElementSize,
|
|
3219
|
+
getTargetListLength,
|
|
3220
|
+
getTargetPointerType,
|
|
3221
|
+
getTargetStructSize,
|
|
3222
|
+
initPointer,
|
|
3223
|
+
isDoubleFar,
|
|
3224
|
+
isNull,
|
|
3225
|
+
relocateTo,
|
|
3226
|
+
setFarPointer,
|
|
3227
|
+
setInterfacePointer,
|
|
3228
|
+
getInterfacePointer,
|
|
3229
|
+
setListPointer,
|
|
3230
|
+
setStructPointer,
|
|
3231
|
+
validate,
|
|
3232
|
+
copyFromInterface,
|
|
3233
|
+
copyFromList,
|
|
3234
|
+
copyFromStruct,
|
|
3235
|
+
trackPointerAllocation,
|
|
3236
|
+
PointerAllocationResult,
|
|
3237
|
+
PointerType,
|
|
3238
|
+
Pointer,
|
|
3239
|
+
List,
|
|
3240
|
+
Data,
|
|
3241
|
+
Text,
|
|
3242
|
+
Struct,
|
|
3243
|
+
AnyStruct,
|
|
3244
|
+
FixedAnswer,
|
|
3245
|
+
ErrorAnswer,
|
|
3246
|
+
ErrorClient,
|
|
3247
|
+
clientOrNull,
|
|
3248
|
+
initStruct,
|
|
3249
|
+
initStructAt,
|
|
3250
|
+
checkPointerBounds,
|
|
3251
|
+
getInterfaceClientOrNullAt,
|
|
3252
|
+
getInterfaceClientOrNull,
|
|
3253
|
+
resize,
|
|
3254
|
+
getAs,
|
|
3255
|
+
getBit,
|
|
3256
|
+
getData,
|
|
3257
|
+
getDataSection,
|
|
3258
|
+
getFloat32,
|
|
3259
|
+
getFloat64,
|
|
3260
|
+
getInt16,
|
|
3261
|
+
getInt32,
|
|
3262
|
+
getInt64,
|
|
3263
|
+
getInt8,
|
|
3264
|
+
getList,
|
|
3265
|
+
getPointer,
|
|
3266
|
+
getPointerAs,
|
|
3267
|
+
getPointerSection,
|
|
3268
|
+
getSize,
|
|
3269
|
+
getStruct,
|
|
3270
|
+
getText,
|
|
3271
|
+
getUint16,
|
|
3272
|
+
getUint32,
|
|
3273
|
+
getUint64,
|
|
3274
|
+
getUint8,
|
|
3275
|
+
initData,
|
|
3276
|
+
initList,
|
|
3277
|
+
setBit,
|
|
3278
|
+
setFloat32,
|
|
3279
|
+
setFloat64,
|
|
3280
|
+
setInt16,
|
|
3281
|
+
setInt32,
|
|
3282
|
+
setInt64,
|
|
3283
|
+
setInt8,
|
|
3284
|
+
setText,
|
|
3285
|
+
setUint16,
|
|
3286
|
+
setUint32,
|
|
3287
|
+
setUint64,
|
|
3288
|
+
setUint8,
|
|
3289
|
+
testWhich,
|
|
3290
|
+
checkDataBounds,
|
|
3291
|
+
CompositeList,
|
|
3292
|
+
getFloat32Mask,
|
|
3293
|
+
getFloat64Mask,
|
|
3294
|
+
getInt16Mask,
|
|
3295
|
+
getInt32Mask,
|
|
3296
|
+
getInt64Mask,
|
|
3297
|
+
getInt8Mask,
|
|
3298
|
+
getUint16Mask,
|
|
3299
|
+
getUint32Mask,
|
|
3300
|
+
getUint64Mask,
|
|
3301
|
+
getUint8Mask,
|
|
3302
|
+
getBitMask,
|
|
3303
|
+
Message,
|
|
3304
|
+
readRawPointer
|
|
3305
|
+
};
|