@stryke/capnp
Version:
A package to assist in running the Cap'n Proto compiler and creating Cap'n Proto serialization protocol schemas.
1 lines • 219 kB
Source Map (JSON)
{"version":3,"file":"src-B97sIXSw.mjs","names":["dump","#proxyHandler","padToWord","dump"],"sources":["../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs","../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/shared/capnp-es.BvfUH5E6.mjs","../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/shared/capnp-es.GpvEvMIK.mjs","../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/shared/capnp-es.UAt3nLGq.mjs","../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/index.mjs"],"sourcesContent":["var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {\n ListElementSize2[ListElementSize2[\"VOID\"] = 0] = \"VOID\";\n ListElementSize2[ListElementSize2[\"BIT\"] = 1] = \"BIT\";\n ListElementSize2[ListElementSize2[\"BYTE\"] = 2] = \"BYTE\";\n ListElementSize2[ListElementSize2[\"BYTE_2\"] = 3] = \"BYTE_2\";\n ListElementSize2[ListElementSize2[\"BYTE_4\"] = 4] = \"BYTE_4\";\n ListElementSize2[ListElementSize2[\"BYTE_8\"] = 5] = \"BYTE_8\";\n ListElementSize2[ListElementSize2[\"POINTER\"] = 6] = \"POINTER\";\n ListElementSize2[ListElementSize2[\"COMPOSITE\"] = 7] = \"COMPOSITE\";\n return ListElementSize2;\n})(ListElementSize || {});\n\nconst tmpWord = new DataView(new ArrayBuffer(8));\nnew Uint16Array(tmpWord.buffer)[0] = 258;\nconst DEFAULT_BUFFER_SIZE = 4096;\nconst DEFAULT_TRAVERSE_LIMIT = 64 << 20;\nconst LIST_SIZE_MASK = 7;\nconst MAX_BUFFER_DUMP_BYTES = 8192;\nconst MAX_INT32 = 2147483647;\nconst MAX_UINT32 = 4294967295;\nconst MIN_SINGLE_SEGMENT_GROWTH = 4096;\nconst NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;\nconst PACK_SPAN_THRESHOLD = 2;\nconst POINTER_DOUBLE_FAR_MASK = 4;\nconst POINTER_TYPE_MASK = 3;\nconst MAX_DEPTH = MAX_INT32;\nconst MAX_SEGMENT_LENGTH = MAX_UINT32;\n\nconst INVARIANT_UNREACHABLE_CODE = \"CAPNP-TS000 Unreachable code detected.\";\nfunction assertNever(n) {\n throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);\n}\nconst MSG_INVALID_FRAME_HEADER = \"CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?\";\nconst MSG_PACK_NOT_WORD_ALIGNED = \"CAPNP-TS003 Attempted to pack a message that was not word-aligned.\";\nconst MSG_SEGMENT_OUT_OF_BOUNDS = \"CAPNP-TS004 Segment ID %X is out of bounds for message %s.\";\nconst MSG_SEGMENT_TOO_SMALL = \"CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).\";\nconst NOT_IMPLEMENTED = \"CAPNP-TS006 %s is not implemented.\";\nconst PTR_ADOPT_WRONG_MESSAGE = \"CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.\";\nconst PTR_ALREADY_ADOPTED = \"CAPNP-TS009 Attempted to adopt %s more than once.\";\nconst PTR_COMPOSITE_SIZE_UNDEFINED = \"CAPNP-TS010 Attempted to set a composite list without providing a composite element size.\";\nconst PTR_DEPTH_LIMIT_EXCEEDED = \"CAPNP-TS011 Nesting depth limit exceeded for %s.\";\nconst PTR_INIT_COMPOSITE_STRUCT = \"CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).\";\nconst PTR_INVALID_FAR_TARGET = \"CAPNP-TS015 Target of a far pointer (%s) is another far pointer.\";\nconst PTR_INVALID_LIST_SIZE = \"CAPNP-TS016 Invalid list element size: %x.\";\nconst PTR_INVALID_POINTER_TYPE = \"CAPNP-TS017 Invalid pointer type: %x.\";\nconst 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).\";\nconst PTR_OFFSET_OUT_OF_BOUNDS = \"CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.\";\nconst 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).\";\nconst PTR_STRUCT_POINTER_OUT_OF_BOUNDS = \"CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).\";\nconst PTR_TRAVERSAL_LIMIT_EXCEEDED = \"CAPNP-TS022 Traversal limit exceeded! Slow down! %s\";\nconst PTR_WRONG_LIST_TYPE = \"CAPNP-TS023 Cannot convert %s to a %s list.\";\nconst PTR_WRONG_POINTER_TYPE = \"CAPNP-TS024 Attempted to convert pointer %s to a %s type.\";\nconst SEG_GET_NON_ZERO_SINGLE = \"CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.\";\nconst SEG_ID_OUT_OF_BOUNDS = \"CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).\";\nconst SEG_NOT_WORD_ALIGNED = \"CAPNP-TS037 Segment buffer length %d is not a multiple of 8.\";\nconst SEG_REPLACEMENT_BUFFER_TOO_SMALL = \"CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.\";\nconst SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;\nconst TYPE_COMPOSITE_SIZE_UNDEFINED = \"CAPNP-TS040 Must provide a composite element size for composite list pointers.\";\nconst LIST_NO_MUTABLE = \"CAPNP-TS045: Cannot call mutative methods on an immutable list.\";\nconst LIST_NO_SEARCH = \"CAPNP-TS046: Search is not supported for list.\";\nconst RPC_NULL_CLIENT = \"CAPNP-TS100 Call on null client.\";\nconst RPC_CALL_QUEUE_FULL = \"CAPNP-TS101 Promised answer call queue full.\";\nconst RPC_QUEUE_CALL_CANCEL = \"CAPNP-TS102 Queue call canceled.\";\nconst RPC_ZERO_REF = \"CAPNP-TS105 Ref() called on zeroed refcount.\";\nconst RPC_IMPORT_CLOSED = \"CAPNP-TS106 Call on closed import.\";\nconst RPC_METHOD_NOT_IMPLEMENTED = \"CAPNP-TS107 Method not implemented.\";\nconst RPC_BAD_TARGET = \"CAPNP-TS109 Target not found.\";\nconst RPC_RETURN_FOR_UNKNOWN_QUESTION = \"CAPNP-TS111 Received return for unknown question (id=%s).\";\nconst RPC_QUESTION_ID_REUSED = \"CAPNP-TS112 Attempted to re-use question id (%s).\";\nconst RPC_UNKNOWN_EXPORT_ID = \"CAPNP-TS113 Capability table references unknown export ID (%s).\";\nconst RPC_UNKNOWN_ANSWER_ID = \"CAPNP-TS114 Capability table references unknown answer ID (%s).\";\nconst RPC_UNKNOWN_CAP_DESCRIPTOR = \"CAPNP-TS115 Unknown cap descriptor type (which: %s).\";\nconst RPC_METHOD_ERROR = \"CAPNP-TS116 RPC method failed at %s.%s(): %s\";\nconst RPC_ERROR = \"CAPNP-TS117 RPC call failed, reason: %s\";\nconst RPC_NO_MAIN_INTERFACE = \"CAPNP-TS118 Received bootstrap message without main interface set.\";\nconst RPC_FINISH_UNKNOWN_ANSWER = \"CAPNP-TS119 Received finish message for unknown answer ID (%s).\";\nconst RPC_FULFILL_ALREADY_CALLED = \"CAPNP-TS120 Fulfill called more than once for question (%s).\";\n\nfunction bufferToHex(buffer) {\n const a = new Uint8Array(buffer);\n const h = [];\n for (let i = 0; i < a.byteLength; i++) {\n h.push(pad(a[i].toString(16), 2));\n }\n return `[${h.join(\" \")}]`;\n}\nfunction dumpBuffer(buffer) {\n const b = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n const byteLength = Math.min(b.byteLength, MAX_BUFFER_DUMP_BYTES);\n let r = format(\"\\n=== buffer[%d] ===\", byteLength);\n for (let j = 0; j < byteLength; j += 16) {\n r += `\n${pad(j.toString(16), 8)}: `;\n let s = \"\";\n let k;\n for (k = 0; k < 16 && j + k < b.byteLength; k++) {\n const v = b[j + k];\n r += `${pad(v.toString(16), 2)} `;\n s += v > 31 && v < 255 ? String.fromCharCode(v) : \"\\xB7\";\n if (k === 7) {\n r += \" \";\n }\n }\n r += `${\" \".repeat((17 - k) * 3)}${s}`;\n }\n r += \"\\n\";\n if (byteLength !== b.byteLength) {\n r += format(\"=== (truncated %d bytes) ===\\n\", b.byteLength - byteLength);\n }\n return r;\n}\nfunction format(s, ...args) {\n const n = s.length;\n let arg;\n let argIndex = 0;\n let c;\n let escaped = false;\n let i = 0;\n let leadingZero = false;\n let precision;\n let result = \"\";\n function nextArg() {\n return args[argIndex++];\n }\n function slurpNumber() {\n let digits = \"\";\n while (/\\d/.test(s[i])) {\n digits += s[i++];\n c = s[i];\n }\n return digits.length > 0 ? Number.parseInt(digits, 10) : null;\n }\n for (; i < n; ++i) {\n c = s[i];\n if (escaped) {\n escaped = false;\n if (c === \".\") {\n leadingZero = false;\n c = s[++i];\n } else if (c === \"0\" && s[i + 1] === \".\") {\n leadingZero = true;\n i += 2;\n c = s[i];\n } else {\n leadingZero = true;\n }\n precision = slurpNumber();\n switch (c) {\n case \"a\": {\n result += \"0x\" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);\n break;\n }\n case \"b\": {\n result += Number.parseInt(String(nextArg()), 10).toString(2);\n break;\n }\n case \"c\": {\n arg = nextArg();\n result += typeof arg === \"string\" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));\n break;\n }\n case \"d\": {\n result += Number.parseInt(String(nextArg()), 10);\n break;\n }\n case \"f\": {\n const tmp = Number.parseFloat(String(nextArg())).toFixed(\n precision || 6\n );\n result += leadingZero ? tmp : tmp.replace(/^0/, \"\");\n break;\n }\n case \"j\": {\n result += JSON.stringify(nextArg());\n break;\n }\n case \"o\": {\n result += \"0\" + Number.parseInt(String(nextArg()), 10).toString(8);\n break;\n }\n case \"s\": {\n result += nextArg();\n break;\n }\n case \"x\": {\n result += \"0x\" + Number.parseInt(String(nextArg()), 10).toString(16);\n break;\n }\n case \"X\": {\n result += \"0x\" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();\n break;\n }\n default: {\n result += c;\n break;\n }\n }\n } else if (c === \"%\") {\n escaped = true;\n } else {\n result += c;\n }\n }\n return result;\n}\nfunction pad(v, width, pad2 = \"0\") {\n return v.length >= width ? v : Array.from({ length: width - v.length + 1 }).join(pad2) + v;\n}\nfunction padToWord$1(size) {\n return size + 7 & -8;\n}\n\nclass ObjectSize {\n /**\n * Creates a new ObjectSize instance.\n *\n * @param dataByteLength - The number of bytes in the data section of the struct\n * @param pointerLength - The number of pointers in the pointer section of the struct\n */\n constructor(dataByteLength, pointerLength) {\n this.dataByteLength = dataByteLength;\n this.pointerLength = pointerLength;\n }\n toString() {\n return format(\n \"ObjectSize_dw:%d,pc:%d\",\n getDataWordLength(this),\n this.pointerLength\n );\n }\n}\nfunction getByteLength(o) {\n return o.dataByteLength + o.pointerLength * 8;\n}\nfunction getDataWordLength(o) {\n return o.dataByteLength / 8;\n}\nfunction getWordLength(o) {\n return o.dataByteLength / 8 + o.pointerLength;\n}\nfunction padToWord(o) {\n return new ObjectSize(padToWord$1(o.dataByteLength), o.pointerLength);\n}\n\nclass Orphan {\n /** If this member is not present then the orphan has already been adopted, or something went very wrong. */\n _capnp;\n byteOffset;\n segment;\n constructor(src) {\n const c = getContent(src);\n this.segment = c.segment;\n this.byteOffset = c.byteOffset;\n this._capnp = {};\n this._capnp.type = getTargetPointerType(src);\n switch (this._capnp.type) {\n case PointerType.STRUCT: {\n this._capnp.size = getTargetStructSize(src);\n break;\n }\n case PointerType.LIST: {\n this._capnp.length = getTargetListLength(src);\n this._capnp.elementSize = getTargetListElementSize(src);\n if (this._capnp.elementSize === ListElementSize.COMPOSITE) {\n this._capnp.size = getTargetCompositeListSize(src);\n }\n break;\n }\n case PointerType.OTHER: {\n this._capnp.capId = getCapabilityId(src);\n break;\n }\n default: {\n throw new Error(PTR_INVALID_POINTER_TYPE);\n }\n }\n erasePointer(src);\n }\n /**\n * Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed.\n *\n * @param dst The destination pointer.\n */\n _moveTo(dst) {\n if (this._capnp === undefined) {\n throw new Error(format(PTR_ALREADY_ADOPTED, this));\n }\n if (this.segment.message !== dst.segment.message) {\n throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst));\n }\n erase(dst);\n const res = initPointer(this.segment, this.byteOffset, dst);\n switch (this._capnp.type) {\n case PointerType.STRUCT: {\n setStructPointer(res.offsetWords, this._capnp.size, res.pointer);\n break;\n }\n case PointerType.LIST: {\n let { offsetWords } = res;\n if (this._capnp.elementSize === ListElementSize.COMPOSITE) {\n offsetWords--;\n }\n setListPointer(\n offsetWords,\n this._capnp.elementSize,\n this._capnp.length,\n res.pointer,\n this._capnp.size\n );\n break;\n }\n case PointerType.OTHER: {\n setInterfacePointer(this._capnp.capId, res.pointer);\n break;\n }\n /* istanbul ignore next */\n default: {\n throw new Error(PTR_INVALID_POINTER_TYPE);\n }\n }\n this._capnp = undefined;\n }\n dispose() {\n if (this._capnp === undefined) {\n return;\n }\n switch (this._capnp.type) {\n case PointerType.STRUCT: {\n this.segment.fillZeroWords(\n this.byteOffset,\n getWordLength(this._capnp.size)\n );\n break;\n }\n case PointerType.LIST: {\n const byteLength = getListByteLength(\n this._capnp.elementSize,\n this._capnp.length,\n this._capnp.size\n );\n this.segment.fillZeroWords(this.byteOffset, byteLength);\n break;\n }\n }\n this._capnp = undefined;\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return format(\n \"Orphan_%d@%a,type:%s\",\n this.segment.id,\n this.byteOffset,\n this._capnp && this._capnp.type\n );\n }\n}\n\nfunction adopt(src, p) {\n src._moveTo(p);\n}\nfunction disown(p) {\n return new Orphan(p);\n}\nfunction dump(p) {\n return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8));\n}\nfunction getListByteLength(elementSize, length, compositeSize) {\n switch (elementSize) {\n case ListElementSize.BIT: {\n return padToWord$1(length + 7 >>> 3);\n }\n case ListElementSize.BYTE:\n case ListElementSize.BYTE_2:\n case ListElementSize.BYTE_4:\n case ListElementSize.BYTE_8:\n case ListElementSize.POINTER:\n case ListElementSize.VOID: {\n return padToWord$1(getListElementByteLength(elementSize) * length);\n }\n /* istanbul ignore next */\n case ListElementSize.COMPOSITE: {\n if (compositeSize === undefined) {\n throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));\n }\n return length * padToWord$1(getByteLength(compositeSize));\n }\n /* istanbul ignore next */\n default: {\n throw new Error(PTR_INVALID_LIST_SIZE);\n }\n }\n}\nfunction getListElementByteLength(elementSize) {\n switch (elementSize) {\n /* istanbul ignore next */\n case ListElementSize.BIT: {\n return Number.NaN;\n }\n case ListElementSize.BYTE: {\n return 1;\n }\n case ListElementSize.BYTE_2: {\n return 2;\n }\n case ListElementSize.BYTE_4: {\n return 4;\n }\n case ListElementSize.BYTE_8:\n case ListElementSize.POINTER: {\n return 8;\n }\n /* istanbul ignore next */\n case ListElementSize.COMPOSITE: {\n return Number.NaN;\n }\n /* istanbul ignore next */\n case ListElementSize.VOID: {\n return 0;\n }\n /* istanbul ignore next */\n default: {\n throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));\n }\n }\n}\nfunction add(offset, p) {\n return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit);\n}\nfunction copyFrom(src, p) {\n if (p.segment === src.segment && p.byteOffset === src.byteOffset) {\n return;\n }\n erase(p);\n if (isNull(src)) return;\n switch (getTargetPointerType(src)) {\n case PointerType.STRUCT: {\n copyFromStruct(src, p);\n break;\n }\n case PointerType.LIST: {\n copyFromList(src, p);\n break;\n }\n case PointerType.OTHER: {\n copyFromInterface(src, p);\n break;\n }\n /* istanbul ignore next */\n default: {\n throw new Error(\n format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))\n );\n }\n }\n}\nfunction erase(p) {\n if (isNull(p)) return;\n let c;\n switch (getTargetPointerType(p)) {\n case PointerType.STRUCT: {\n const size = getTargetStructSize(p);\n c = getContent(p);\n c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);\n for (let i = 0; i < size.pointerLength; i++) {\n erase(add(i * 8, c));\n }\n break;\n }\n case PointerType.LIST: {\n const elementSize = getTargetListElementSize(p);\n const length = getTargetListLength(p);\n let contentWords = padToWord$1(\n length * getListElementByteLength(elementSize)\n );\n c = getContent(p);\n if (elementSize === ListElementSize.POINTER) {\n for (let i = 0; i < length; i++) {\n erase(\n new Pointer(\n c.segment,\n c.byteOffset + i * 8,\n p._capnp.depthLimit - 1\n )\n );\n }\n break;\n } else if (elementSize === ListElementSize.COMPOSITE) {\n const tag = add(-8, c);\n const compositeSize = getStructSize(tag);\n const compositeByteLength = getByteLength(compositeSize);\n contentWords = getOffsetWords(tag);\n c.segment.setWordZero(c.byteOffset - 8);\n for (let i = 0; i < length; i++) {\n for (let j = 0; j < compositeSize.pointerLength; j++) {\n erase(\n new Pointer(\n c.segment,\n c.byteOffset + i * compositeByteLength + j * 8,\n p._capnp.depthLimit - 1\n )\n );\n }\n }\n }\n c.segment.fillZeroWords(c.byteOffset, contentWords);\n break;\n }\n case PointerType.OTHER: {\n break;\n }\n default: {\n throw new Error(\n format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))\n );\n }\n }\n erasePointer(p);\n}\nfunction erasePointer(p) {\n if (getPointerType(p) === PointerType.FAR) {\n const landingPad = followFar(p);\n if (isDoubleFar(p)) {\n landingPad.segment.setWordZero(landingPad.byteOffset + 8);\n }\n landingPad.segment.setWordZero(landingPad.byteOffset);\n }\n p.segment.setWordZero(p.byteOffset);\n}\nfunction followFar(p) {\n const targetSegment = p.segment.message.getSegment(\n p.segment.getUint32(p.byteOffset + 4)\n );\n const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;\n return new Pointer(\n targetSegment,\n targetWordOffset * 8,\n p._capnp.depthLimit - 1\n );\n}\nfunction followFars(p) {\n if (getPointerType(p) === PointerType.FAR) {\n const landingPad = followFar(p);\n if (isDoubleFar(p)) {\n landingPad.byteOffset += 8;\n }\n return landingPad;\n }\n return p;\n}\nfunction getCapabilityId(p) {\n return p.segment.getUint32(p.byteOffset + 4);\n}\nfunction isCompositeList(p) {\n return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;\n}\nfunction getContent(p, ignoreCompositeIndex) {\n let c;\n if (isDoubleFar(p)) {\n const landingPad = followFar(p);\n c = new Pointer(\n p.segment.message.getSegment(getFarSegmentId(landingPad)),\n getOffsetWords(landingPad) * 8\n );\n } else {\n const target = followFars(p);\n c = new Pointer(\n target.segment,\n target.byteOffset + 8 + getOffsetWords(target) * 8\n );\n }\n if (isCompositeList(p)) {\n c.byteOffset += 8;\n }\n if (!ignoreCompositeIndex && p._capnp.compositeIndex !== undefined) {\n c.byteOffset -= 8;\n c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));\n }\n return c;\n}\nfunction getFarSegmentId(p) {\n return p.segment.getUint32(p.byteOffset + 4);\n}\nfunction getListElementSize(p) {\n return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;\n}\nfunction getListLength(p) {\n return p.segment.getUint32(p.byteOffset + 4) >>> 3;\n}\nfunction getOffsetWords(p) {\n const o = p.segment.getInt32(p.byteOffset);\n return o & 2 ? o >> 3 : o >> 2;\n}\nfunction getPointerType(p) {\n return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;\n}\nfunction getStructDataWords(p) {\n return p.segment.getUint16(p.byteOffset + 4);\n}\nfunction getStructPointerLength(p) {\n return p.segment.getUint16(p.byteOffset + 6);\n}\nfunction getStructSize(p) {\n return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));\n}\nfunction getTargetCompositeListTag(p) {\n const c = getContent(p);\n c.byteOffset -= 8;\n return c;\n}\nfunction getTargetCompositeListSize(p) {\n return getStructSize(getTargetCompositeListTag(p));\n}\nfunction getTargetListElementSize(p) {\n return getListElementSize(followFars(p));\n}\nfunction getTargetListLength(p) {\n const t = followFars(p);\n if (getListElementSize(t) === ListElementSize.COMPOSITE) {\n return getOffsetWords(getTargetCompositeListTag(p));\n }\n return getListLength(t);\n}\nfunction getTargetPointerType(p) {\n const t = getPointerType(followFars(p));\n if (t === PointerType.FAR) {\n throw new Error(format(PTR_INVALID_FAR_TARGET, p));\n }\n return t;\n}\nfunction getTargetStructSize(p) {\n return getStructSize(followFars(p));\n}\nfunction initPointer(contentSegment, contentOffset, p) {\n if (p.segment !== contentSegment) {\n if (!contentSegment.hasCapacity(8)) {\n const landingPad2 = p.segment.allocate(16);\n setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);\n setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);\n landingPad2.byteOffset += 8;\n return new PointerAllocationResult(landingPad2, 0);\n }\n const landingPad = contentSegment.allocate(8);\n if (landingPad.segment.id !== contentSegment.id) {\n throw new Error(INVARIANT_UNREACHABLE_CODE);\n }\n setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);\n return new PointerAllocationResult(\n landingPad,\n (contentOffset - landingPad.byteOffset - 8) / 8\n );\n }\n return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);\n}\nfunction isDoubleFar(p) {\n return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;\n}\nfunction isNull(p) {\n return p.segment.isWordZero(p.byteOffset);\n}\nfunction relocateTo(dst, src) {\n const t = followFars(src);\n const lo = t.segment.getUint8(t.byteOffset) & 3;\n const hi = t.segment.getUint32(t.byteOffset + 4);\n erase(dst);\n const res = initPointer(\n t.segment,\n t.byteOffset + 8 + getOffsetWords(t) * 8,\n dst\n );\n res.pointer.segment.setUint32(\n res.pointer.byteOffset,\n lo | res.offsetWords << 2\n );\n res.pointer.segment.setUint32(res.pointer.byteOffset + 4, hi);\n erasePointer(src);\n}\nfunction setFarPointer(doubleFar, offsetWords, segmentId, p) {\n const A = PointerType.FAR;\n const B = doubleFar ? 1 : 0;\n const C = offsetWords;\n const D = segmentId;\n p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);\n p.segment.setUint32(p.byteOffset + 4, D);\n}\nfunction setInterfacePointer(capId, p) {\n p.segment.setUint32(p.byteOffset, PointerType.OTHER);\n p.segment.setUint32(p.byteOffset + 4, capId);\n}\nfunction getInterfacePointer(p) {\n return p.segment.getUint32(p.byteOffset + 4);\n}\nfunction setListPointer(offsetWords, size, length, p, compositeSize) {\n const A = PointerType.LIST;\n const B = offsetWords;\n const C = size;\n let D = length;\n if (size === ListElementSize.COMPOSITE) {\n if (compositeSize === undefined) {\n throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);\n }\n D *= getWordLength(compositeSize);\n }\n p.segment.setUint32(p.byteOffset, A | B << 2);\n p.segment.setUint32(p.byteOffset + 4, C | D << 3);\n}\nfunction setStructPointer(offsetWords, size, p) {\n const A = PointerType.STRUCT;\n const B = offsetWords;\n const C = getDataWordLength(size);\n const D = size.pointerLength;\n p.segment.setUint32(p.byteOffset, A | B << 2);\n p.segment.setUint16(p.byteOffset + 4, C);\n p.segment.setUint16(p.byteOffset + 6, D);\n}\nfunction validate(pointerType, p, elementSize) {\n if (isNull(p)) {\n return;\n }\n const t = followFars(p);\n const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;\n if (A !== pointerType) {\n throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));\n }\n if (elementSize !== undefined) {\n const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;\n if (C !== elementSize) {\n throw new Error(\n format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])\n );\n }\n }\n}\nfunction copyFromInterface(src, dst) {\n const srcCapId = getInterfacePointer(src);\n if (srcCapId < 0) {\n return;\n }\n const srcCapTable = src.segment.message._capnp.capTable;\n if (!srcCapTable) {\n return;\n }\n const client = srcCapTable[srcCapId];\n if (!client) {\n return;\n }\n const dstCapId = dst.segment.message.addCap(client);\n setInterfacePointer(dstCapId, dst);\n}\nfunction copyFromList(src, dst) {\n if (dst._capnp.depthLimit <= 0) {\n throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);\n }\n const srcContent = getContent(src);\n const srcElementSize = getTargetListElementSize(src);\n const srcLength = getTargetListLength(src);\n let srcCompositeSize;\n let srcStructByteLength;\n let dstContent;\n if (srcElementSize === ListElementSize.POINTER) {\n dstContent = dst.segment.allocate(srcLength << 3);\n for (let i = 0; i < srcLength; i++) {\n const srcPtr = new Pointer(\n srcContent.segment,\n srcContent.byteOffset + (i << 3),\n src._capnp.depthLimit - 1\n );\n const dstPtr = new Pointer(\n dstContent.segment,\n dstContent.byteOffset + (i << 3),\n dst._capnp.depthLimit - 1\n );\n copyFrom(srcPtr, dstPtr);\n }\n } else if (srcElementSize === ListElementSize.COMPOSITE) {\n srcCompositeSize = padToWord(getTargetCompositeListSize(src));\n srcStructByteLength = getByteLength(srcCompositeSize);\n dstContent = dst.segment.allocate(\n getByteLength(srcCompositeSize) * srcLength + 8\n );\n dstContent.segment.copyWord(\n dstContent.byteOffset,\n srcContent.segment,\n srcContent.byteOffset - 8\n );\n if (srcCompositeSize.dataByteLength > 0) {\n const wordLength = getWordLength(srcCompositeSize) * srcLength;\n dstContent.segment.copyWords(\n dstContent.byteOffset + 8,\n srcContent.segment,\n srcContent.byteOffset,\n wordLength\n );\n }\n for (let i = 0; i < srcLength; i++) {\n for (let j = 0; j < srcCompositeSize.pointerLength; j++) {\n const offset = i * srcStructByteLength + srcCompositeSize.dataByteLength + (j << 3);\n const srcPtr = new Pointer(\n srcContent.segment,\n srcContent.byteOffset + offset,\n src._capnp.depthLimit - 1\n );\n const dstPtr = new Pointer(\n dstContent.segment,\n dstContent.byteOffset + offset + 8,\n dst._capnp.depthLimit - 1\n );\n copyFrom(srcPtr, dstPtr);\n }\n }\n } else {\n const byteLength = padToWord$1(\n srcElementSize === ListElementSize.BIT ? srcLength + 7 >>> 3 : getListElementByteLength(srcElementSize) * srcLength\n );\n const wordLength = byteLength >>> 3;\n dstContent = dst.segment.allocate(byteLength);\n dstContent.segment.copyWords(\n dstContent.byteOffset,\n srcContent.segment,\n srcContent.byteOffset,\n wordLength\n );\n }\n const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);\n setListPointer(\n res.offsetWords,\n srcElementSize,\n srcLength,\n res.pointer,\n srcCompositeSize\n );\n}\nfunction copyFromStruct(src, dst) {\n if (dst._capnp.depthLimit <= 0) {\n throw new Error(PTR_DEPTH_LIMIT_EXCEEDED);\n }\n const srcContent = getContent(src);\n const srcSize = getTargetStructSize(src);\n const srcDataWordLength = getDataWordLength(srcSize);\n const dstContent = dst.segment.allocate(getByteLength(srcSize));\n dstContent.segment.copyWords(\n dstContent.byteOffset,\n srcContent.segment,\n srcContent.byteOffset,\n srcDataWordLength\n );\n for (let i = 0; i < srcSize.pointerLength; i++) {\n const offset = srcSize.dataByteLength + i * 8;\n const srcPtr = new Pointer(\n srcContent.segment,\n srcContent.byteOffset + offset,\n src._capnp.depthLimit - 1\n );\n const dstPtr = new Pointer(\n dstContent.segment,\n dstContent.byteOffset + offset,\n dst._capnp.depthLimit - 1\n );\n copyFrom(srcPtr, dstPtr);\n }\n if (dst._capnp.compositeList) {\n return;\n }\n const res = initPointer(dstContent.segment, dstContent.byteOffset, dst);\n setStructPointer(res.offsetWords, srcSize, res.pointer);\n}\nfunction trackPointerAllocation(message, p) {\n message._capnp.traversalLimit -= 8;\n if (message._capnp.traversalLimit <= 0) {\n throw new Error(format(PTR_TRAVERSAL_LIMIT_EXCEEDED, p));\n }\n}\nclass PointerAllocationResult {\n constructor(pointer, offsetWords) {\n this.pointer = pointer;\n this.offsetWords = offsetWords;\n }\n}\n\nvar PointerType = /* @__PURE__ */ ((PointerType2) => {\n PointerType2[PointerType2[\"STRUCT\"] = 0] = \"STRUCT\";\n PointerType2[PointerType2[\"LIST\"] = 1] = \"LIST\";\n PointerType2[PointerType2[\"FAR\"] = 2] = \"FAR\";\n PointerType2[PointerType2[\"OTHER\"] = 3] = \"OTHER\";\n return PointerType2;\n})(PointerType || {});\nclass Pointer {\n static _capnp = {\n displayName: \"Pointer\"\n };\n _capnp;\n /** Offset, in bytes, from the start of the segment to the beginning of this pointer. */\n byteOffset;\n /**\n * The starting segment for this pointer's data. In the case of a far pointer, the actual content this pointer is\n * referencing will be in another segment within the same message.\n */\n segment;\n constructor(segment, byteOffset, depthLimit = MAX_DEPTH) {\n this._capnp = { compositeList: false, depthLimit };\n this.segment = segment;\n this.byteOffset = byteOffset;\n if (depthLimit < 1) {\n throw new Error(format(PTR_DEPTH_LIMIT_EXCEEDED, this));\n }\n trackPointerAllocation(segment.message, this);\n if (byteOffset < 0 || byteOffset > segment.byteLength) {\n throw new Error(format(PTR_OFFSET_OUT_OF_BOUNDS, byteOffset));\n }\n }\n [Symbol.toStringTag]() {\n return format(\"Pointer_%d\", this.segment.id);\n }\n toString() {\n return format(\"->%d@%a%s\", this.segment.id, this.byteOffset, dump(this));\n }\n}\n\nclass List extends Pointer {\n static _capnp = {\n displayName: \"List<Generic>\",\n size: ListElementSize.VOID\n };\n constructor(segment, byteOffset, depthLimit) {\n super(segment, byteOffset, depthLimit);\n return new Proxy(this, List.#proxyHandler);\n }\n static #proxyHandler = {\n get(target, prop, receiver) {\n const val = Reflect.get(target, prop, receiver);\n if (val !== undefined) {\n return val;\n }\n if (typeof prop === \"string\") {\n return target.get(+prop);\n }\n }\n };\n get length() {\n return getTargetListLength(this);\n }\n toArray() {\n const { length } = this;\n const res = Array.from({ length });\n for (let i = 0; i < length; i++) {\n res[i] = this.at(i);\n }\n return res;\n }\n get(_index) {\n throw new TypeError(\"Cannot get from a generic list.\");\n }\n set(_index, _value) {\n throw new TypeError(\"Cannot set on a generic list.\");\n }\n at(index) {\n return this.get(index < 0 ? this.length + index : index);\n }\n concat(other) {\n const { length } = this;\n const otherLength = other.length;\n const res = Array.from({ length: length + otherLength });\n for (let i = 0; i < length; i++) res[i] = this.at(i);\n for (let i = 0; i < otherLength; i++) res[i + length] = other.at(i);\n return res;\n }\n some(cb, _this) {\n for (let i = 0; i < this.length; i++) {\n if (cb.call(_this, this.at(i), i, this)) {\n return true;\n }\n }\n return false;\n }\n filter(cb, _this) {\n const res = [];\n for (let i = 0; i < this.length; i++) {\n const value = this.at(i);\n if (cb.call(_this, value, i, this)) {\n res.push(value);\n }\n }\n return res;\n }\n find(cb, _this) {\n for (let i = 0; i < this.length; i++) {\n const value = this.at(i);\n if (cb.call(_this, value, i, this)) {\n return value;\n }\n }\n return undefined;\n }\n findIndex(cb, _this) {\n for (let i = 0; i < this.length; i++) {\n const value = this.at(i);\n if (cb.call(_this, value, i, this)) {\n return i;\n }\n }\n return -1;\n }\n forEach(cb, _this) {\n for (let i = 0; i < this.length; i++) {\n cb.call(_this, this.at(i), i, this);\n }\n }\n map(cb, _this) {\n const { length } = this;\n const res = Array.from({ length });\n for (let i = 0; i < length; i++) {\n res[i] = cb.call(_this, this.at(i), i, this);\n }\n return res;\n }\n flatMap(cb, _this) {\n const res = [];\n for (let i = 0; i < this.length; i++) {\n const r = cb.call(_this, this.at(i), i, this);\n res.push(...Array.isArray(r) ? r : [r]);\n }\n return res;\n }\n every(cb, _this) {\n for (let i = 0; i < this.length; i++) {\n if (!cb.call(_this, this.at(i), i, this)) {\n return false;\n }\n }\n return true;\n }\n reduce(cb, initialValue) {\n let i = 0;\n let res;\n if (initialValue === undefined) {\n res = this.at(0);\n i++;\n } else {\n res = initialValue;\n }\n for (; i < this.length; i++) {\n res = cb(res, this.at(i), i, this);\n }\n return res;\n }\n reduceRight(cb, initialValue) {\n let i = this.length - 1;\n let res;\n if (initialValue === undefined) {\n res = this.at(i);\n i--;\n } else {\n res = initialValue;\n }\n for (; i >= 0; i--) {\n res = cb(res, this.at(i), i, this);\n }\n return res;\n }\n slice(start = 0, end) {\n const length = end ? Math.min(this.length, end) : this.length;\n const res = Array.from({ length: length - start });\n for (let i = start; i < length; i++) {\n res[i] = this.at(i);\n }\n return res;\n }\n join(separator) {\n return this.toArray().join(separator);\n }\n toReversed() {\n return this.toArray().reverse();\n }\n toSorted(compareFn) {\n return this.toArray().sort(compareFn);\n }\n toSpliced(start, deleteCount, ...items) {\n return this.toArray().splice(start, deleteCount, ...items);\n }\n fill(value, start, end) {\n const { length } = this;\n const s = Math.max(start ?? 0, 0);\n const e = Math.min(end ?? length, length);\n for (let i = s; i < e; i++) {\n this.set(i, value);\n }\n return this;\n }\n copyWithin(target, start, end) {\n const { length } = this;\n const e = end ?? length;\n const s = start < 0 ? Math.max(length + start, 0) : start;\n const t = target < 0 ? Math.max(length + target, 0) : target;\n const len = Math.min(e - s, length - t);\n for (let i = 0; i < len; i++) {\n this.set(t + i, this.at(s + i));\n }\n return this;\n }\n keys() {\n return Array.from({ length: this.length }, (_, i) => i)[Symbol.iterator]();\n }\n values() {\n return this.toArray().values();\n }\n entries() {\n return this.toArray().entries();\n }\n flat(depth) {\n return this.toArray().flat(depth);\n }\n with(index, value) {\n return this.toArray().with(index, value);\n }\n includes(_searchElement, _fromIndex) {\n throw new Error(LIST_NO_SEARCH);\n }\n findLast(_cb, _thisArg) {\n throw new Error(LIST_NO_SEARCH);\n }\n findLastIndex(_cb, _t) {\n throw new Error(LIST_NO_SEARCH);\n }\n indexOf(_searchElement, _fromIndex) {\n throw new Error(LIST_NO_SEARCH);\n }\n lastIndexOf(_searchElement, _fromIndex) {\n throw new Error(LIST_NO_SEARCH);\n }\n pop() {\n throw new Error(LIST_NO_MUTABLE);\n }\n push(..._items) {\n throw new Error(LIST_NO_MUTABLE);\n }\n reverse() {\n throw new Error(LIST_NO_MUTABLE);\n }\n shift() {\n throw new Error(LIST_NO_MUTABLE);\n }\n unshift(..._items) {\n throw new Error(LIST_NO_MUTABLE);\n }\n splice(_start, _deleteCount, ..._rest) {\n throw new Error(LIST_NO_MUTABLE);\n }\n sort(_fn) {\n throw new Error(LIST_NO_MUTABLE);\n }\n get [Symbol.unscopables]() {\n return Array.prototype[Symbol.unscopables];\n }\n [Symbol.iterator]() {\n return this.values();\n }\n toJSON() {\n return this.toArray();\n }\n toString() {\n return this.join(\",\");\n }\n toLocaleString(_locales, _options) {\n return this.toString();\n }\n [Symbol.toStringTag]() {\n return \"[object Array]\";\n }\n static [Symbol.toStringTag]() {\n return this._capnp.displayName;\n }\n}\nfunction initList$1(elementSize, length, list, compositeSize) {\n let c;\n switch (elementSize) {\n case ListElementSize.BIT: {\n c = list.segment.allocate(Math.ceil(length / 8));\n break;\n }\n case ListElementSize.BYTE:\n case ListElementSize.BYTE_2:\n case ListElementSize.BYTE_4:\n case ListElementSize.BYTE_8:\n case ListElementSize.POINTER: {\n c = list.segment.allocate(length * getListElementByteLength(elementSize));\n break;\n }\n case ListElementSize.COMPOSITE: {\n if (compositeSize === undefined) {\n throw new Error(format(PTR_COMPOSITE_SIZE_UNDEFINED));\n }\n compositeSize = padToWord(compositeSize);\n const byteLength = getByteLength(compositeSize) * length;\n c = list.segment.allocate(byteLength + 8);\n setStructPointer(length, compositeSize, c);\n break;\n }\n case ListElementSize.VOID: {\n setListPointer(0, elementSize, length, list);\n return;\n }\n default: {\n throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));\n }\n }\n const res = initPointer(c.segment, c.byteOffset, list);\n setListPointer(\n res.offsetWords,\n elementSize,\n length,\n res.pointer,\n compositeSize\n );\n}\n\nclass Data extends List {\n static fromPointer(pointer) {\n validate(PointerType.LIST, pointer, ListElementSize.BYTE);\n return this._fromPointerUnchecked(pointer);\n }\n static _fromPointerUnchecked(pointer) {\n return new this(\n pointer.segment,\n pointer.byteOffset,\n pointer._capnp.depthLimit\n );\n }\n /**\n * Copy the contents of `src` into this Data pointer. If `src` is smaller than the length of this pointer then the\n * remaining bytes will be zeroed out. Extra bytes in `src` are ignored.\n *\n * @param src The source buffer.\n */\n // TODO: Would be nice to have a way to zero-copy a buffer by allocating a new segment into the message with that\n // buffer data.\n copyBuffer(src) {\n const c = getContent(this);\n const dstLength = this.length;\n const srcLength = src.byteLength;\n const i = src instanceof ArrayBuffer ? new Uint8Array(src) : new Uint8Array(\n src.buffer,\n src.byteOffset,\n Math.min(dstLength, srcLength)\n );\n const o = new Uint8Array(c.segment.buffer, c.byteOffset, this.length);\n o.set(i);\n if (dstLength > srcLength) {\n o.fill(0, srcLength, dstLength);\n }\n }\n /**\n * Read a byte from the specified offset.\n *\n * @param byteOffset The byte offset to read.\n * @returns The byte value.\n */\n get(byteOffset) {\n const c = getContent(this);\n return c.segment.getUint8(c.byteOffset + byteOffset);\n }\n /**\n * Write a byte at the specified offset.\n *\n * @param byteOffset The byte offset to set.\n * @param value The byte value to set.\n */\n set(byteOffset, value) {\n const c = getContent(this);\n c.segment.setUint8(c.byteOffset + byteOffset, value);\n }\n /**\n * Creates a **copy** of the underlying buffer data and returns it as an ArrayBuffer.\n *\n * To obtain a reference to the underlying buffer instead, use `toUint8Array()` or `toDataView()`.\n *\n * @returns A copy of this data buffer.\n */\n toArrayBuffer() {\n const c = getContent(this);\n return c.segment.buffer.slice(c.byteOffset, c.byteOffset + this.length);\n }\n /**\n * Convert this Data pointer to a DataView representing the pointer's contents.\n *\n * WARNING: The DataView references memory from a message segment, so do not venture outside the bounds of the\n * DataView or else BAD THINGS.\n *\n * @returns A live reference to the underlying buffer.\n */\n toDataView() {\n const c = getContent(this);\n return new DataView(c.segment.buffer, c.byteOffset, this.length);\n }\n [Symbol.toStringTag]() {\n return `Data_${super.toString()}`;\n }\n /**\n * Convert this Data pointer to a Uint8Array representing the pointer's contents.\n *\n * WARNING: The Uint8Array references memory from a message segment, so do not venture outside the bounds of the\n * Uint8Array or else BAD THINGS.\n *\n * @returns A live reference to the underlying buffer.\n */\n toUint8Array() {\n const c = getContent(this);\n return new Uint8Array(c.segment.buffer, c.byteOffset, this.length);\n }\n}\n\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\nclass Text extends List {\n static fromPointer(pointer) {\n validate(PointerType.LIST, pointer, ListElementSize.BYTE);\n return textFromPointerUnchecked(pointer);\n }\n /**\n * Read a utf-8 encoded string value from this pointer.\n *\n * @param index The index at which to start reading; defaults to zero.\n * @returns The string value.\n */\n get(index = 0) {\n if (isNull(this)) {\n return \"\";\n }\n const c = getContent(this);\n return textDecoder.decode(\n new Uint8Array(\n c.segment.buffer,\n c.byteOffset + index,\n this.length - index\n )\n );\n }\n /**\n * Get the number of utf-8 encoded bytes in this text. This does **not** include the NUL byte.\n *\n * @returns The number of bytes allocated for the text.\n */\n get length() {\n return super.length - 1;\n }\n /**\n * Write a utf-8 encoded string value starting at the specified index.\n *\n * @param index The index at which to start copying the string. Note that if this is not zero the bytes\n * before `index` will be left as-is. All bytes after `index` will be overwritten.\n * @param value The string value to set.\n */\n set(index, value) {\n const src = textEncoder.encode(value);\n const dstLength = src.byteLength + index;\n let c;\n let original;\n if (!isNull(this)) {\n c = getContent(this);\n const originalLength = Math.min(this.length, index);\n original = new Uint8Array(\n c.segment.buffer.slice(c.byteOffset, c.byteOffset + originalLength)\n );\n erase(this);\n }\n initList$1(ListElementSize.BYTE, dstLength + 1, this);\n c = getContent(this);\n const dst = new Uint8Array(c.segment.buffer, c.byteOffset, dstLength);\n if (original) {\n dst.set(original);\n }\n dst.set(src, index);\n }\n toString() {\n return this.get();\n }\n toJSON() {\n return this.get();\n }\n [Symbol.toPrimitive]() {\n return this.get();\n }\n [Symbol.toStringTag]() {\n return `Text_${super.toString()}`;\n }\n}\nfunction textFromPointerUnchecked(pointer) {\n return new Text(\n pointer.segment,\n pointer.byteOffset,\n pointer._capnp.depthLimit\n );\n}\n\nclass Struct extends Pointer {\n static _capnp = {\n displayName: \"Struct\"\n };\n /**\n * Create a new pointer to a struct.\n *\n * @param segment The segment the pointer resides in.\n * @param byteOffset The offset from the beginning of the segment to the beginning of the pointer data.\n * @param depthLimit The nesting depth limit for this object.\n * @param compositeIndex If set, then this pointer is actually a reference to a composite list\n * (`this._getPointerTargetType() === PointerType.LIST`), and this number is used as the index of the struct within\n * the list. It is not valid to call `initStruct()` on a composite struct – the struct contents are initialized when\n * the list pointer is initialized.\n */\n constructor(segment, byteOffset, depthLimit = MAX_DEPTH, compositeIndex) {\n super(segment, byteOffset, depthLimit);\n this._capnp.compositeIndex = compositeIndex;\n this._capnp.compositeList = compositeIndex !== undefined;\n }\n static [Symbol.toStringTag]() {\n return this._capnp.displayName;\n }\n [Symbol.toStringTag]() {\n return `Struct_${super.toString()}${this._capnp.compositeIndex === undefined ? \"\" : `,ci:${this._capnp.compositeIndex}`} > ${getContent(this).toString()}`;\n }\n}\nclass AnyStruct extends Struct {\n static _capnp = {\n displayName: \"AnyStruct\",\n id: \"0\",\n size: new ObjectSize(0, 0)\n };\n}\n\nclass FixedAnswer {\n struct() {\n return Promise.resolve(this.structSync());\n }\n}\n\nclass ErrorAnswer extends FixedAnswer {\n constructor(err) {\n super();\n this.err = err;\n }\n structSync() {\n throw this.err;\n }\n pipelineCall(_transform, _call) {\n return this;\n }\n pipelineClose(_transform) {\n throw this.err;\n }\n}\n\nclass ErrorClient {\n constructor(err) {\n this.err = err;\n }\n call(_call) {\n return new ErrorAnswer(this.err);\n }\n close() {\n throw this.err;\n }\n}\nfunction clientOrNull(client) {\n return client ?? new ErrorClient(new Error(RPC_NULL_CLIENT));\n}\n\nconst TMP_WORD = new DataView(new ArrayBuffer(8));\nfunction initStruct(size, s) {\n if (s._capnp.compositeIndex !== undefined) {\n throw new Error(format(PTR_INIT_COMPOSITE_STRUCT, s));\n }\n erase(s);\n const c = s.segment.allocate(getByteLength(size));\n const res = initPointer(c.segment, c.byteOffset, s);\n setStructPointer(res.offsetWords, size, res.pointer);\n}\nfunction initStructAt(index, StructClass, p) {\n const s = getPointerAs(index, StructClass, p);\n initStruct(StructClass._capnp.size, s);\n return s;\n}\nfunction checkPointerBounds(index, s) {\n const { pointerLength } = getSize(s);\n if (index < 0 || index >= pointerLength) {\n throw new Error(\n format(PTR_STRUCT_POINTER_OUT_OF_BOUNDS, s, index, pointerLength)\n );\n }\n}\nfunction getInterfaceClientOrNullAt(index, s) {\n return getInterfaceClientOrNull(getPointer(index, s));\n}\nfunction getInterfaceClientOrNull(p) {\n let client = null;\n const capId = getInterfacePointer(p);\n const { capTable } = p.segment.message._capnp;\n if (capTable && capId >= 0 && capId < capTable.length) {\n client = capTable[capId];\n }\n return clientOrNull(client);\n}\nfunction resize(dstSize, s) {\n const srcSize = getSize(s);\n const srcContent = getContent(s);\n const dstContent = s.segment.allocate(getByteLength(dstSize));\n dstContent.segment.copyWords(\n dstContent.byteOffset,\n srcContent.segment,\n srcContent.byteOffset,\n Math.min(getDataWordLength(srcSize), getDataWordLength(dstSize))\n );\n const res = initPointer(dstContent.segment, dstContent.byteOffset, s);\n setStructPointer(res.offsetWords, dstSize, res.pointer);\n for (let i = 0; i < Math.min(srcSize.pointerLength, dstSize.pointerLength); i++) {\n const srcPtr = new Pointer(\n srcContent.segment,\n srcContent.byteOffset + srcSize.dataByteLength + i * 8\n );\n if (isNull(srcPtr)) {\n continue;\n }\n const srcPtrTarget = followFars(srcPtr);\n const srcPtrContent = getContent(srcPtr);\n const dstPtr = new Pointer(\n dstContent.segment,\n dstContent.byteOffset + dstSize.dataByteLength + i * 8\n );\n if (getTargetPointerType(srcPtr) === PointerType.LIST && getTargetListElementSize(srcPtr) === ListElementSize.COMPOSITE) {\n srcPtrContent.byteOffset -= 8;\n }\n const r = initPointer(\n srcPtrContent.segment,\n srcPtrContent.byteOffset,\n dstPtr\n );\n const a = srcPtrTarget.segment.getUint8(srcPtrTarget.byteOffset) & 3;\n const b = srcPtrTarget.segment.getUint32(srcPtrTarget.byteOffset + 4);\n r.pointer.segment.setUint32(r.pointer.byteOffset, a | r.offsetWords << 2);\n r.pointer.segment.setUint32(r.pointer.byteOffset + 4, b);\n }\n srcContent.segment.fillZeroWords(\n srcContent.byteOffset,\n getWordLength(srcSize)\n );\n}\n