@stryke/capnp
Version:
A package to assist in running the Cap'n Proto compiler and creating Cap'n Proto serialization protocol schemas.
1 lines • 196 kB
Source Map (JSON)
{"version":3,"file":"dist-DQ7xmzRT.mjs","names":["Message","callQueueSize","Message","Message$1"],"sources":["../../../../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/capnp/rpc.mjs","../../../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@6.0.3/node_modules/capnp-es/dist/index.mjs"],"sourcesContent":["import { $ as Pointer, ac as MAX_DEPTH, N as format, ad as getTargetPointerType, a8 as PointerType, ab as initStruct, S as Struct, g as getPointer, ae as FixedAnswer, af as getInterfaceClientOrNull, ag as ErrorAnswer, ah as RPC_CALL_QUEUE_FULL, ai as INVARIANT_UNREACHABLE_CODE, aj as RPC_QUEUE_CALL_CANCEL, ak as RPC_NULL_CLIENT, c as copyFrom, w as getAs, al as RPC_METHOD_ERROR, am as RPC_METHOD_NOT_IMPLEMENTED } from './capnp-es.0-_cOx6D.mjs';\nimport { M as Message } from './capnp-es.GpvEvMIK.mjs';\n\nclass Interface extends Pointer {\n static _capnp = {\n displayName: \"Interface\"\n };\n static getCapID = getCapID;\n static getAsInterface = getAsInterface;\n static isInterface = isInterface;\n static getClient = getClient;\n constructor(segment, byteOffset, depthLimit = MAX_DEPTH) {\n super(segment, byteOffset, depthLimit);\n }\n static fromPointer(p) {\n return getAsInterface(p);\n }\n getCapId() {\n return getCapID(this);\n }\n getClient() {\n return getClient(this);\n }\n [Symbol.for(\"nodejs.util.inspect.custom\")]() {\n return format(\n \"Interface_%d@%a,%d,limit:%x\",\n this.segment.id,\n this.byteOffset,\n this.getCapId(),\n this._capnp.depthLimit\n );\n }\n}\nfunction getAsInterface(p) {\n if (getTargetPointerType(p) === PointerType.OTHER) {\n return new Interface(p.segment, p.byteOffset, p._capnp.depthLimit);\n }\n return null;\n}\nfunction isInterface(p) {\n return getTargetPointerType(p) === PointerType.OTHER;\n}\nfunction getCapID(i) {\n if (i.segment.getUint32(i.byteOffset) !== PointerType.OTHER) {\n return -1;\n }\n return i.segment.getUint32(i.byteOffset + 4);\n}\nfunction getClient(i) {\n const capID = getCapID(i);\n const { capTable } = i.segment.message._capnp;\n if (!capTable) {\n return null;\n }\n return capTable[capID];\n}\n\nfunction isFuncCall(call) {\n return !isDataCall(call);\n}\nfunction isDataCall(call) {\n return !!call.params;\n}\nfunction copyCall(call) {\n if (isDataCall(call)) {\n return call;\n }\n return {\n method: call.method,\n params: placeParams(call, undefined)\n };\n}\nfunction placeParams(call, contentPtr) {\n if (isDataCall(call)) {\n return call.params;\n }\n let p;\n if (contentPtr) {\n p = new call.method.ParamsClass(\n contentPtr.segment,\n contentPtr.byteOffset,\n contentPtr._capnp.depthLimit\n );\n } else {\n const msg = new Message();\n p = new call.method.ParamsClass(msg.getSegment(0), 0);\n }\n initStruct(call.method.ParamsClass._capnp.size, p);\n if (call.paramsFunc) {\n call.paramsFunc(p);\n }\n return p;\n}\n\nfunction pointerToStruct(p) {\n if (getTargetPointerType(p) === PointerType.STRUCT) {\n return new Struct(\n p.segment,\n p.byteOffset,\n p._capnp.depthLimit,\n p._capnp.compositeIndex\n );\n }\n return null;\n}\n\nfunction transformPtr(p, transform) {\n if (transform.length === 0) {\n return p;\n }\n let s = pointerToStruct(p);\n if (!s) {\n return p;\n }\n for (const op of transform) {\n s = getPointer(op.field, s);\n }\n return s;\n}\n\nclass Deferred {\n static fromPromise(p) {\n const d = new Deferred();\n p.then(d.resolve, d.reject);\n return d;\n }\n promise;\n reject;\n resolve;\n constructor() {\n this.promise = new Promise((a, b) => {\n this.resolve = a;\n this.reject = b;\n });\n }\n}\n\nclass ImmediateAnswer extends FixedAnswer {\n constructor(s) {\n super();\n this.s = s;\n }\n structSync() {\n return this.s;\n }\n findClient(transform) {\n const p = transformPtr(this.s, transform);\n return getInterfaceClientOrNull(p);\n }\n pipelineCall(transform, call) {\n return this.findClient(transform).call(call);\n }\n pipelineClose(transform) {\n this.findClient(transform).close();\n }\n}\n\nclass Queue {\n // creates a new queue that starts with n elements.\n // The interface's length must not change over the course of\n // the queue's usage.\n constructor(q, n) {\n this.q = q;\n this.n = n;\n this.cap = q.len();\n }\n start = 0;\n cap;\n // len returns the length of the queue. This is different from the underlying\n // interface's length, which is the queue's capacity.\n len() {\n return this.n;\n }\n // push reserves space for an element on the queue, returning its index.\n // if the queue is full, push returns -1.\n push() {\n if (this.n >= this.cap) {\n return -1;\n }\n const i = (this.start + this.n) % this.cap;\n this.n++;\n return i;\n }\n // front returns the index of the front of the queue, or -1 if the queue is empty.\n front() {\n if (this.n === 0) {\n return -1;\n }\n return this.start;\n }\n // pop pops an element from the queue, returning whether it succeeded.\n pop() {\n if (this.n === 0) {\n return false;\n }\n this.q.clear(this.start);\n this.start = (this.start + 1) % this.cap;\n this.n--;\n return true;\n }\n}\n\nclass EmbargoClient {\n _client;\n q;\n calls;\n constructor(client, queue) {\n this._client = client;\n this.calls = queue.copy();\n this.q = new Queue(this.calls, this.calls.len());\n this.flushQueue();\n }\n flushQueue() {\n let c = null;\n {\n const i = this.q.front();\n if (i !== -1) {\n c = this.calls.data[i];\n }\n }\n while (c && c.call) {\n const ans = this._client.call(c.call);\n void (async (f, ans2) => {\n try {\n f.fulfill(await ans2.struct());\n } catch (error_) {\n f.reject(error_);\n }\n })(c.f, ans);\n this.q.pop();\n {\n const i = this.q.front();\n c = i === -1 ? null : this.calls.data[i];\n }\n }\n }\n // client returns the underlying client if the embargo has\n // been lifted and null otherwise\n client() {\n return this.isPassthrough() ? this._client : null;\n }\n isPassthrough() {\n return this.q.len() === 0;\n }\n // call either queues a call to the underlying client or starts a\n // call if the embargo has been lifted\n call(call) {\n if (this.isPassthrough()) {\n return this._client.call(call);\n }\n return this.push(call);\n }\n push(_call) {\n const f = new Fulfiller();\n const call = copyCall(_call);\n const i = this.q.push();\n if (i === -1) {\n return new ErrorAnswer(new Error(RPC_CALL_QUEUE_FULL));\n }\n this.calls.data[i] = {\n call,\n f\n };\n return f;\n }\n close() {\n while (this.q.len() > 0) {\n const first = this.calls.data[this.q.front()];\n if (!first) {\n throw new Error(INVARIANT_UNREACHABLE_CODE);\n }\n first.f.reject(new Error(RPC_QUEUE_CALL_CANCEL));\n this.q.pop();\n }\n this._client.close();\n }\n}\n\nclass Ecalls {\n data;\n constructor(data) {\n this.data = data;\n }\n static copyOf(data) {\n return new Ecalls([...data]);\n }\n len() {\n return this.data.length;\n }\n clear(i) {\n this.data[i] = null;\n }\n copy() {\n return Ecalls.copyOf(this.data);\n }\n}\n\nconst callQueueSize = 64;\nclass Fulfiller {\n resolved = false;\n answer;\n queue = [];\n queueCap = callQueueSize;\n deferred = new Deferred();\n fulfill(s) {\n this.answer = new ImmediateAnswer(s);\n const queues = this.emptyQueue(s);\n const msgcap = s.segment.message._capnp;\n if (!msgcap.capTable) {\n msgcap.capTable = [];\n }\n const ctab = msgcap.capTable;\n for (const _capIdx of Object.keys(queues)) {\n const capIdx = +_capIdx;\n const q = queues[capIdx];\n const client = ctab[capIdx];\n if (!client) {\n throw new Error(INVARIANT_UNREACHABLE_CODE);\n }\n ctab[capIdx] = new EmbargoClient(client, q);\n }\n this.deferred.resolve(s);\n }\n reject(err) {\n this.deferred.reject(err);\n }\n peek() {\n return this.answer;\n }\n async struct() {\n return await this.deferred.promise;\n }\n // pipelineCall calls pipelineCall on the fulfilled answer or\n // queues the call if f has not been fulfilled\n pipelineCall(transform, call) {\n {\n const a = this.peek();\n if (a) {\n return a.pipelineCall(transform, call);\n }\n }\n if (this.queue.length === this.queueCap) {\n return new ErrorAnswer(new Error(RPC_CALL_QUEUE_FULL));\n }\n const cc = copyCall(call);\n const g = new Fulfiller();\n this.queue.push({\n call: cc,\n f: g,\n transform\n });\n return g;\n }\n // pipelineClose waits until f is resolved and then calls\n // pipelineClose on the fulfilled answer\n // FIXME: should this be async?\n pipelineClose(transform) {\n const onFinally = () => {\n if (this.answer) {\n this.answer.pipelineClose(transform);\n }\n };\n this.deferred.promise.then(onFinally, onFinally);\n }\n // emptyQueue splits the queue by which capability it targets and\n // drops any invalid calls. Once this function returns, f.queue will\n // be nil.\n emptyQueue(s) {\n const qs = {};\n for (let i = 0; i < this.queue.length; i++) {\n const pc = this.queue[i];\n let c;\n try {\n c = transformPtr(s, pc.transform);\n } catch (error_) {\n pc.f.reject(error_);\n continue;\n }\n const iface = Interface.fromPointer(c);\n if (!iface) {\n pc.f.reject(new Error(RPC_NULL_CLIENT));\n continue;\n }\n const cn = iface.getCapId();\n if (!qs[cn]) {\n qs[cn] = new Ecalls([]);\n }\n qs[cn].data.push(pc);\n }\n this.queue = [];\n return qs;\n }\n}\n\nclass PipelineClient {\n constructor(pipeline) {\n this.pipeline = pipeline;\n }\n transform() {\n return this.pipeline.transform();\n }\n call(call) {\n return this.pipeline.answer.pipelineCall(this.transform(), call);\n }\n close() {\n this.pipeline.answer.pipelineClose(this.transform());\n }\n}\n\nclass Pipeline {\n // Returns a new Pipeline based on an answer\n constructor(ResultsClass, answer, op, parent) {\n this.ResultsClass = ResultsClass;\n this.answer = answer;\n this.parent = parent;\n this.op = op || { field: 0 };\n }\n op;\n pipelineClient;\n // transform returns the operations needed to transform the root answer\n // into the value p represents.\n transform() {\n const xform = [];\n for (let q = this; q.parent; q = q.parent) {\n xform.unshift(q.op);\n }\n return xform;\n }\n // Struct waits until the answer is resolved and returns the struct\n // this pipeline represents.\n async struct() {\n const s = await this.answer.struct();\n const t = transformPtr(s, this.transform());\n if (!t) {\n if (this.op.defaultValue) {\n copyFrom(this.op.defaultValue, t);\n } else {\n initStruct(this.ResultsClass._capnp.size, t);\n }\n }\n return getAs(this.ResultsClass, t);\n }\n // client returns the client version of this pipeline\n client() {\n if (!this.pipelineClient) {\n this.pipelineClient = new PipelineClient(this);\n }\n return this.pipelineClient;\n }\n // getPipeline returns a derived pipeline which yields the pointer field given\n getPipeline(ResultsClass, off, defaultValue) {\n return new Pipeline(\n ResultsClass,\n this.answer,\n { field: off, defaultValue },\n this\n );\n }\n}\n\nclass MethodError extends Error {\n constructor(method, message) {\n super(\n format(\n RPC_METHOD_ERROR,\n method.interfaceName,\n method.methodName,\n message\n )\n );\n this.method = method;\n }\n}\n\nclass Registry {\n static interfaces = /* @__PURE__ */ new Map();\n static register(id, def) {\n this.interfaces.set(id, def);\n }\n static lookup(id) {\n return this.interfaces.get(id);\n }\n}\n\nclass Server {\n constructor(target, methods) {\n this.target = target;\n this.methods = methods;\n }\n startCall(call) {\n const msg = new Message();\n const results = msg.initRoot(call.method.ResultsClass);\n call.serverMethod.impl.call(this.target, call.params, results).then(() => call.answer.fulfill(results)).catch((error_) => call.answer.reject(error_));\n }\n call(call) {\n const serverMethod = this.methods[call.method.methodId];\n if (!serverMethod) {\n return new ErrorAnswer(\n new MethodError(call.method, RPC_METHOD_NOT_IMPLEMENTED)\n );\n }\n const serverCall = {\n ...copyCall(call),\n answer: new Fulfiller(),\n serverMethod\n };\n this.startCall(serverCall);\n return serverCall.answer;\n }\n close() {\n }\n}\n\nexport { Deferred as D, Fulfiller as F, Interface as I, MethodError as M, Pipeline as P, Queue as Q, Registry as R, Server as S, PipelineClient as a, isDataCall as b, copyCall as c, isFuncCall as i, placeParams as p, transformPtr as t };\n","import { S as Struct, O as ObjectSize, e as getUint32, f as setUint32, h as getBit, j as setBit, s as setUint16, a as adopt, g as getPointer, d as disown, t as testWhich, b as getUint16, k as getStruct, i as isNull, l as initStructAt, c as copyFrom, m as getList, n as initList, o as getUint8, p as setUint8, q as getText, r as setText, u as getUint64, v as setUint64, w as getAs } from '../shared/capnp-es.0-_cOx6D.mjs';\nimport { g as getBitMask, a as getUint8Mask, C as CompositeList } from '../shared/capnp-es.BvfUH5E6.mjs';\n\nconst _capnpFileId = BigInt(\"0xb312981b2552a250\");\nconst Message_Which = {\n /**\n * The sender previously received this message from the peer but didn't understand it or doesn't\n * yet implement the functionality that was requested. So, the sender is echoing the message\n * back. In some cases, the receiver may be able to recover from this by pretending the sender\n * had taken some appropriate \"null\" action.\n *\n * For example, say `resolve` is received by a level 0 implementation (because a previous call\n * or return happened to contain a promise). The level 0 implementation will echo it back as\n * `unimplemented`. The original sender can then simply release the cap to which the promise\n * had resolved, thus avoiding a leak.\n *\n * For any message type that introduces a question, if the message comes back unimplemented,\n * the original sender may simply treat it as if the question failed with an exception.\n *\n * In cases where there is no sensible way to react to an `unimplemented` message (without\n * resource leaks or other serious problems), the connection may need to be aborted. This is\n * a gray area; different implementations may take different approaches.\n *\n */\n UNIMPLEMENTED: 0,\n /**\n * Sent when a connection is being aborted due to an unrecoverable error. This could be e.g.\n * because the sender received an invalid or nonsensical message or because the sender had an\n * internal error. The sender will shut down the outgoing half of the connection after `abort`\n * and will completely close the connection shortly thereafter (it's up to the sender how much\n * of a time buffer they want to offer for the client to receive the `abort` before the\n * connection is reset).\n *\n */\n ABORT: 1,\n /**\n * Request the peer's bootstrap interface.\n *\n */\n BOOTSTRAP: 8,\n /**\n * Begin a method call.\n *\n */\n CALL: 2,\n /**\n * Complete a method call.\n *\n */\n RETURN: 3,\n /**\n * Release a returned answer / cancel a call.\n *\n */\n FINISH: 4,\n /**\n * Resolve a previously-sent promise.\n *\n */\n RESOLVE: 5,\n /**\n * Release a capability so that the remote object can be deallocated.\n *\n */\n RELEASE: 6,\n /**\n * Lift an embargo used to enforce E-order over promise resolution.\n *\n */\n DISEMBARGO: 13,\n /**\n * Obsolete request to save a capability, resulting in a SturdyRef. This has been replaced\n * by the `Persistent` interface defined in `persistent.capnp`. This operation was never\n * implemented.\n *\n */\n OBSOLETE_SAVE: 7,\n /**\n * Obsolete way to delete a SturdyRef. This operation was never implemented.\n *\n */\n OBSOLETE_DELETE: 9,\n /**\n * Provide a capability to a third party.\n *\n */\n PROVIDE: 10,\n /**\n * Accept a capability provided by a third party.\n *\n */\n ACCEPT: 11,\n /**\n * Directly connect to the common root of two or more proxied caps.\n *\n */\n JOIN: 12\n};\nclass Message extends Struct {\n static UNIMPLEMENTED = Message_Which.UNIMPLEMENTED;\n static ABORT = Message_Which.ABORT;\n static BOOTSTRAP = Message_Which.BOOTSTRAP;\n static CALL = Message_Which.CALL;\n static RETURN = Message_Which.RETURN;\n static FINISH = Message_Which.FINISH;\n static RESOLVE = Message_Which.RESOLVE;\n static RELEASE = Message_Which.RELEASE;\n static DISEMBARGO = Message_Which.DISEMBARGO;\n static OBSOLETE_SAVE = Message_Which.OBSOLETE_SAVE;\n static OBSOLETE_DELETE = Message_Which.OBSOLETE_DELETE;\n static PROVIDE = Message_Which.PROVIDE;\n static ACCEPT = Message_Which.ACCEPT;\n static JOIN = Message_Which.JOIN;\n static _capnp = {\n displayName: \"Message\",\n id: \"91b79f1f808db032\",\n size: new ObjectSize(8, 1)\n };\n _adoptUnimplemented(value) {\n setUint16(0, 0, this);\n adopt(value, getPointer(0, this));\n }\n _disownUnimplemented() {\n return disown(this.unimplemented);\n }\n /**\n * The sender previously received this message from the peer but didn't understand it or doesn't\n * yet implement the functionality that was requested. So, the sender is echoing the message\n * back. In some cases, the receiver may be able to recover from this by pretending the sender\n * had taken some appropriate \"null\" action.\n *\n * For example, say `resolve` is received by a level 0 implementation (because a previous call\n * or return happened to contain a promise). The level 0 implementation will echo it back as\n * `unimplemented`. The original sender can then simply release the cap to which the promise\n * had resolved, thus avoiding a leak.\n *\n * For any message type that introduces a question, if the message comes back unimplemented,\n * the original sender may simply treat it as if the question failed with an exception.\n *\n * In cases where there is no sensible way to react to an `unimplemented` message (without\n * resource leaks or other serious problems), the connection may need to be aborted. This is\n * a gray area; different implementations may take different approaches.\n *\n */\n get unimplemented() {\n testWhich(\"unimplemented\", getUint16(0, this), 0, this);\n return getStruct(0, Message, this);\n }\n _hasUnimplemented() {\n return !isNull(getPointer(0, this));\n }\n _initUnimplemented() {\n setUint16(0, 0, this);\n return initStructAt(0, Message, this);\n }\n get _isUnimplemented() {\n return getUint16(0, this) === 0;\n }\n set unimplemented(value) {\n setUint16(0, 0, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptAbort(value) {\n setUint16(0, 1, this);\n adopt(value, getPointer(0, this));\n }\n _disownAbort() {\n return disown(this.abort);\n }\n /**\n * Sent when a connection is being aborted due to an unrecoverable error. This could be e.g.\n * because the sender received an invalid or nonsensical message or because the sender had an\n * internal error. The sender will shut down the outgoing half of the connection after `abort`\n * and will completely close the connection shortly thereafter (it's up to the sender how much\n * of a time buffer they want to offer for the client to receive the `abort` before the\n * connection is reset).\n *\n */\n get abort() {\n testWhich(\"abort\", getUint16(0, this), 1, this);\n return getStruct(0, Exception, this);\n }\n _hasAbort() {\n return !isNull(getPointer(0, this));\n }\n _initAbort() {\n setUint16(0, 1, this);\n return initStructAt(0, Exception, this);\n }\n get _isAbort() {\n return getUint16(0, this) === 1;\n }\n set abort(value) {\n setUint16(0, 1, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptBootstrap(value) {\n setUint16(0, 8, this);\n adopt(value, getPointer(0, this));\n }\n _disownBootstrap() {\n return disown(this.bootstrap);\n }\n /**\n * Request the peer's bootstrap interface.\n *\n */\n get bootstrap() {\n testWhich(\"bootstrap\", getUint16(0, this), 8, this);\n return getStruct(0, Bootstrap, this);\n }\n _hasBootstrap() {\n return !isNull(getPointer(0, this));\n }\n _initBootstrap() {\n setUint16(0, 8, this);\n return initStructAt(0, Bootstrap, this);\n }\n get _isBootstrap() {\n return getUint16(0, this) === 8;\n }\n set bootstrap(value) {\n setUint16(0, 8, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptCall(value) {\n setUint16(0, 2, this);\n adopt(value, getPointer(0, this));\n }\n _disownCall() {\n return disown(this.call);\n }\n /**\n * Begin a method call.\n *\n */\n get call() {\n testWhich(\"call\", getUint16(0, this), 2, this);\n return getStruct(0, Call, this);\n }\n _hasCall() {\n return !isNull(getPointer(0, this));\n }\n _initCall() {\n setUint16(0, 2, this);\n return initStructAt(0, Call, this);\n }\n get _isCall() {\n return getUint16(0, this) === 2;\n }\n set call(value) {\n setUint16(0, 2, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptReturn(value) {\n setUint16(0, 3, this);\n adopt(value, getPointer(0, this));\n }\n _disownReturn() {\n return disown(this.return);\n }\n /**\n * Complete a method call.\n *\n */\n get return() {\n testWhich(\"return\", getUint16(0, this), 3, this);\n return getStruct(0, Return, this);\n }\n _hasReturn() {\n return !isNull(getPointer(0, this));\n }\n _initReturn() {\n setUint16(0, 3, this);\n return initStructAt(0, Return, this);\n }\n get _isReturn() {\n return getUint16(0, this) === 3;\n }\n set return(value) {\n setUint16(0, 3, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptFinish(value) {\n setUint16(0, 4, this);\n adopt(value, getPointer(0, this));\n }\n _disownFinish() {\n return disown(this.finish);\n }\n /**\n * Release a returned answer / cancel a call.\n *\n */\n get finish() {\n testWhich(\"finish\", getUint16(0, this), 4, this);\n return getStruct(0, Finish, this);\n }\n _hasFinish() {\n return !isNull(getPointer(0, this));\n }\n _initFinish() {\n setUint16(0, 4, this);\n return initStructAt(0, Finish, this);\n }\n get _isFinish() {\n return getUint16(0, this) === 4;\n }\n set finish(value) {\n setUint16(0, 4, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptResolve(value) {\n setUint16(0, 5, this);\n adopt(value, getPointer(0, this));\n }\n _disownResolve() {\n return disown(this.resolve);\n }\n /**\n * Resolve a previously-sent promise.\n *\n */\n get resolve() {\n testWhich(\"resolve\", getUint16(0, this), 5, this);\n return getStruct(0, Resolve, this);\n }\n _hasResolve() {\n return !isNull(getPointer(0, this));\n }\n _initResolve() {\n setUint16(0, 5, this);\n return initStructAt(0, Resolve, this);\n }\n get _isResolve() {\n return getUint16(0, this) === 5;\n }\n set resolve(value) {\n setUint16(0, 5, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptRelease(value) {\n setUint16(0, 6, this);\n adopt(value, getPointer(0, this));\n }\n _disownRelease() {\n return disown(this.release);\n }\n /**\n * Release a capability so that the remote object can be deallocated.\n *\n */\n get release() {\n testWhich(\"release\", getUint16(0, this), 6, this);\n return getStruct(0, Release, this);\n }\n _hasRelease() {\n return !isNull(getPointer(0, this));\n }\n _initRelease() {\n setUint16(0, 6, this);\n return initStructAt(0, Release, this);\n }\n get _isRelease() {\n return getUint16(0, this) === 6;\n }\n set release(value) {\n setUint16(0, 6, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptDisembargo(value) {\n setUint16(0, 13, this);\n adopt(value, getPointer(0, this));\n }\n _disownDisembargo() {\n return disown(this.disembargo);\n }\n /**\n * Lift an embargo used to enforce E-order over promise resolution.\n *\n */\n get disembargo() {\n testWhich(\"disembargo\", getUint16(0, this), 13, this);\n return getStruct(0, Disembargo, this);\n }\n _hasDisembargo() {\n return !isNull(getPointer(0, this));\n }\n _initDisembargo() {\n setUint16(0, 13, this);\n return initStructAt(0, Disembargo, this);\n }\n get _isDisembargo() {\n return getUint16(0, this) === 13;\n }\n set disembargo(value) {\n setUint16(0, 13, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptObsoleteSave(value) {\n setUint16(0, 7, this);\n adopt(value, getPointer(0, this));\n }\n _disownObsoleteSave() {\n return disown(this.obsoleteSave);\n }\n /**\n * Obsolete request to save a capability, resulting in a SturdyRef. This has been replaced\n * by the `Persistent` interface defined in `persistent.capnp`. This operation was never\n * implemented.\n *\n */\n get obsoleteSave() {\n testWhich(\"obsoleteSave\", getUint16(0, this), 7, this);\n return getPointer(0, this);\n }\n _hasObsoleteSave() {\n return !isNull(getPointer(0, this));\n }\n get _isObsoleteSave() {\n return getUint16(0, this) === 7;\n }\n set obsoleteSave(value) {\n setUint16(0, 7, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptObsoleteDelete(value) {\n setUint16(0, 9, this);\n adopt(value, getPointer(0, this));\n }\n _disownObsoleteDelete() {\n return disown(this.obsoleteDelete);\n }\n /**\n * Obsolete way to delete a SturdyRef. This operation was never implemented.\n *\n */\n get obsoleteDelete() {\n testWhich(\"obsoleteDelete\", getUint16(0, this), 9, this);\n return getPointer(0, this);\n }\n _hasObsoleteDelete() {\n return !isNull(getPointer(0, this));\n }\n get _isObsoleteDelete() {\n return getUint16(0, this) === 9;\n }\n set obsoleteDelete(value) {\n setUint16(0, 9, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptProvide(value) {\n setUint16(0, 10, this);\n adopt(value, getPointer(0, this));\n }\n _disownProvide() {\n return disown(this.provide);\n }\n /**\n * Provide a capability to a third party.\n *\n */\n get provide() {\n testWhich(\"provide\", getUint16(0, this), 10, this);\n return getStruct(0, Provide, this);\n }\n _hasProvide() {\n return !isNull(getPointer(0, this));\n }\n _initProvide() {\n setUint16(0, 10, this);\n return initStructAt(0, Provide, this);\n }\n get _isProvide() {\n return getUint16(0, this) === 10;\n }\n set provide(value) {\n setUint16(0, 10, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptAccept(value) {\n setUint16(0, 11, this);\n adopt(value, getPointer(0, this));\n }\n _disownAccept() {\n return disown(this.accept);\n }\n /**\n * Accept a capability provided by a third party.\n *\n */\n get accept() {\n testWhich(\"accept\", getUint16(0, this), 11, this);\n return getStruct(0, Accept, this);\n }\n _hasAccept() {\n return !isNull(getPointer(0, this));\n }\n _initAccept() {\n setUint16(0, 11, this);\n return initStructAt(0, Accept, this);\n }\n get _isAccept() {\n return getUint16(0, this) === 11;\n }\n set accept(value) {\n setUint16(0, 11, this);\n copyFrom(value, getPointer(0, this));\n }\n _adoptJoin(value) {\n setUint16(0, 12, this);\n adopt(value, getPointer(0, this));\n }\n _disownJoin() {\n return disown(this.join);\n }\n /**\n * Directly connect to the common root of two or more proxied caps.\n *\n */\n get join() {\n testWhich(\"join\", getUint16(0, this), 12, this);\n return getStruct(0, Join, this);\n }\n _hasJoin() {\n return !isNull(getPointer(0, this));\n }\n _initJoin() {\n setUint16(0, 12, this);\n return initStructAt(0, Join, this);\n }\n get _isJoin() {\n return getUint16(0, this) === 12;\n }\n set join(value) {\n setUint16(0, 12, this);\n copyFrom(value, getPointer(0, this));\n }\n toString() {\n return \"Message_\" + super.toString();\n }\n which() {\n return getUint16(0, this);\n }\n}\nclass Bootstrap extends Struct {\n static _capnp = {\n displayName: \"Bootstrap\",\n id: \"e94ccf8031176ec4\",\n size: new ObjectSize(8, 1)\n };\n /**\n * A new question ID identifying this request, which will eventually receive a Return message\n * containing the restored capability.\n *\n */\n get questionId() {\n return getUint32(0, this);\n }\n set questionId(value) {\n setUint32(0, value, this);\n }\n _adoptDeprecatedObjectId(value) {\n adopt(value, getPointer(0, this));\n }\n _disownDeprecatedObjectId() {\n return disown(this.deprecatedObjectId);\n }\n /**\n * ** DEPRECATED **\n *\n * A Vat may export multiple bootstrap interfaces. In this case, `deprecatedObjectId` specifies\n * which one to return. If this pointer is null, then the default bootstrap interface is returned.\n *\n * As of version 0.5, use of this field is deprecated. If a service wants to export multiple\n * bootstrap interfaces, it should instead define a single bootstrap interface that has methods\n * that return each of the other interfaces.\n *\n * **History**\n *\n * In the first version of Cap'n Proto RPC (0.4.x) the `Bootstrap` message was called `Restore`.\n * At the time, it was thought that this would eventually serve as the way to restore SturdyRefs\n * (level 2). Meanwhile, an application could offer its \"main\" interface on a well-known\n * (non-secret) SturdyRef.\n *\n * Since level 2 RPC was not implemented at the time, the `Restore` message was in practice only\n * used to obtain the main interface. Since most applications had only one main interface that\n * they wanted to restore, they tended to designate this with a null `objectId`.\n *\n * Unfortunately, the earliest version of the EZ RPC interfaces set a precedent of exporting\n * multiple main interfaces by allowing them to be exported under string names. In this case,\n * `objectId` was a Text value specifying the name.\n *\n * All of this proved problematic for several reasons:\n *\n * - The arrangement assumed that a client wishing to restore a SturdyRef would know exactly what\n * machine to connect to and would be able to immediately restore a SturdyRef on connection.\n * However, in practice, the ability to restore SturdyRefs is itself a capability that may\n * require going through an authentication process to obtain. Thus, it makes more sense to\n * define a \"restorer service\" as a full Cap'n Proto interface. If this restorer interface is\n * offered as the vat's bootstrap interface, then this is equivalent to the old arrangement.\n *\n * - Overloading \"Restore\" for the purpose of obtaining well-known capabilities encouraged the\n * practice of exporting singleton services with string names. If singleton services are desired,\n * it is better to have one main interface that has methods that can be used to obtain each\n * service, in order to get all the usual benefits of schemas and type checking.\n *\n * - Overloading \"Restore\" also had a security problem: Often, \"main\" or \"well-known\"\n * capabilities exported by a vat are in fact not public: they are intended to be accessed only\n * by clients who are capable of forming a connection to the vat. This can lead to trouble if\n * the client itself has other clients and wishes to forward some `Restore` requests from those\n * external clients -- it has to be very careful not to allow through `Restore` requests\n * addressing the default capability.\n *\n * For example, consider the case of a sandboxed Sandstorm application and its supervisor. The\n * application exports a default capability to its supervisor that provides access to\n * functionality that only the supervisor is supposed to access. Meanwhile, though, applications\n * may publish other capabilities that may be persistent, in which case the application needs\n * to field `Restore` requests that could come from anywhere. These requests of course have to\n * pass through the supervisor, as all communications with the outside world must. But, the\n * supervisor has to be careful not to honor an external request addressing the application's\n * default capability, since this capability is privileged. Unfortunately, the default\n * capability cannot be given an unguessable name, because then the supervisor itself would not\n * be able to address it!\n *\n * As of Cap'n Proto 0.5, `Restore` has been renamed to `Bootstrap` and is no longer planned for\n * use in restoring SturdyRefs.\n *\n * Note that 0.4 also defined a message type called `Delete` that, like `Restore`, addressed a\n * SturdyRef, but indicated that the client would not restore the ref again in the future. This\n * operation was never implemented, so it was removed entirely. If a \"delete\" operation is desired,\n * it should exist as a method on the same interface that handles restoring SturdyRefs. However,\n * the utility of such an operation is questionable. You wouldn't be able to rely on it for\n * garbage collection since a client could always disappear permanently without remembering to\n * delete all its SturdyRefs, thus leaving them dangling forever. Therefore, it is advisable to\n * design systems such that SturdyRefs never represent \"owned\" pointers.\n *\n * For example, say a SturdyRef points to an image file hosted on some server. That image file\n * should also live inside a collection (a gallery, perhaps) hosted on the same server, owned by\n * a user who can delete the image at any time. If the user deletes the image, the SturdyRef\n * stops working. On the other hand, if the SturdyRef is discarded, this has no effect on the\n * existence of the image in its collection.\n *\n */\n get deprecatedObjectId() {\n return getPointer(0, this);\n }\n _hasDeprecatedObjectId() {\n return !isNull(getPointer(0, this));\n }\n set deprecatedObjectId(value) {\n copyFrom(value, getPointer(0, this));\n }\n toString() {\n return \"Bootstrap_\" + super.toString();\n }\n}\nconst Call_SendResultsTo_Which = {\n /**\n * Send the return message back to the caller (the usual).\n *\n */\n CALLER: 0,\n /**\n * **(level 1)**\n *\n * Don't actually return the results to the sender. Instead, hold on to them and await\n * instructions from the sender regarding what to do with them. In particular, the sender\n * may subsequently send a `Return` for some other call (which the receiver had previously made\n * to the sender) with `takeFromOtherQuestion` set. The results from this call are then used\n * as the results of the other call.\n *\n * When `yourself` is used, the receiver must still send a `Return` for the call, but sets the\n * field `resultsSentElsewhere` in that `Return` rather than including the results.\n *\n * This feature can be used to implement tail calls in which a call from Vat A to Vat B ends up\n * returning the result of a call from Vat B back to Vat A.\n *\n * In particular, the most common use case for this feature is when Vat A makes a call to a\n * promise in Vat B, and then that promise ends up resolving to a capability back in Vat A.\n * Vat B must forward all the queued calls on that promise back to Vat A, but can set `yourself`\n * in the calls so that the results need not pass back through Vat B.\n *\n * For example:\n * - Alice, in Vat A, calls foo() on Bob in Vat B.\n * - Alice makes a pipelined call bar() on the promise returned by foo().\n * - Later on, Bob resolves the promise from foo() to point at Carol, who lives in Vat A (next\n * to Alice).\n * - Vat B dutifully forwards the bar() call to Carol. Let us call this forwarded call bar'().\n * Notice that bar() and bar'() are travelling in opposite directions on the same network\n * link.\n * - The `Call` for bar'() has `sendResultsTo` set to `yourself`.\n * - Vat B sends a `Return` for bar() with `takeFromOtherQuestion` set in place of the results,\n * with the value set to the question ID of bar'(). Vat B does not wait for bar'() to return,\n * as doing so would introduce unnecessary round trip latency.\n * - Vat A receives bar'() and delivers it to Carol.\n * - When bar'() returns, Vat A sends a `Return` for bar'() to Vat B, with `resultsSentElsewhere`\n * set in place of results.\n * - Vat A sends a `Finish` for the bar() call to Vat B.\n * - Vat B receives the `Finish` for bar() and sends a `Finish` for bar'().\n *\n */\n YOURSELF: 1,\n /**\n * **(level 3)**\n *\n * The call's result should be returned to a different vat. The receiver (the callee) expects\n * to receive an `Accept` message from the indicated vat, and should return the call's result\n * to it, rather than to the sender of the `Call`.\n *\n * This operates much like `yourself`, above, except that Carol is in a separate Vat C. `Call`\n * messages are sent from Vat A -> Vat B and Vat B -> Vat C. A `Return` message is sent from\n * Vat B -> Vat A that contains `acceptFromThirdParty` in place of results. When Vat A sends\n * an `Accept` to Vat C, it receives back a `Return` containing the call's actual result. Vat C\n * also sends a `Return` to Vat B with `resultsSentElsewhere`.\n *\n */\n THIRD_PARTY: 2\n};\nclass Call_SendResultsTo extends Struct {\n static CALLER = Call_SendResultsTo_Which.CALLER;\n static YOURSELF = Call_SendResultsTo_Which.YOURSELF;\n static THIRD_PARTY = Call_SendResultsTo_Which.THIRD_PARTY;\n static _capnp = {\n displayName: \"sendResultsTo\",\n id: \"dae8b0f61aab5f99\",\n size: new ObjectSize(24, 3)\n };\n get _isCaller() {\n return getUint16(6, this) === 0;\n }\n set caller(_) {\n setUint16(6, 0, this);\n }\n get _isYourself() {\n return getUint16(6, this) === 1;\n }\n set yourself(_) {\n setUint16(6, 1, this);\n }\n _adoptThirdParty(value) {\n setUint16(6, 2, this);\n adopt(value, getPointer(2, this));\n }\n _disownThirdParty() {\n return disown(this.thirdParty);\n }\n /**\n * **(level 3)**\n *\n * The call's result should be returned to a different vat. The receiver (the callee) expects\n * to receive an `Accept` message from the indicated vat, and should return the call's result\n * to it, rather than to the sender of the `Call`.\n *\n * This operates much like `yourself`, above, except that Carol is in a separate Vat C. `Call`\n * messages are sent from Vat A -> Vat B and Vat B -> Vat C. A `Return` message is sent from\n * Vat B -> Vat A that contains `acceptFromThirdParty` in place of results. When Vat A sends\n * an `Accept` to Vat C, it receives back a `Return` containing the call's actual result. Vat C\n * also sends a `Return` to Vat B with `resultsSentElsewhere`.\n *\n */\n get thirdParty() {\n testWhich(\"thirdParty\", getUint16(6, this), 2, this);\n return getPointer(2, this);\n }\n _hasThirdParty() {\n return !isNull(getPointer(2, this));\n }\n get _isThirdParty() {\n return getUint16(6, this) === 2;\n }\n set thirdParty(value) {\n setUint16(6, 2, this);\n copyFrom(value, getPointer(2, this));\n }\n toString() {\n return \"Call_SendResultsTo_\" + super.toString();\n }\n which() {\n return getUint16(6, this);\n }\n}\nclass Call extends Struct {\n static _capnp = {\n displayName: \"Call\",\n id: \"836a53ce789d4cd4\",\n size: new ObjectSize(24, 3),\n defaultAllowThirdPartyTailCall: getBitMask(false, 0),\n defaultNoPromisePipelining: getBitMask(false, 1),\n defaultOnlyPromisePipeline: getBitMask(false, 2)\n };\n /**\n * A number, chosen by the caller, that identifies this call in future messages. This number\n * must be different from all other calls originating from the same end of the connection (but\n * may overlap with question IDs originating from the opposite end). A fine strategy is to use\n * sequential question IDs, but the recipient should not assume this.\n *\n * A question ID can be reused once both:\n * - A matching Return has been received from the callee.\n * - A matching Finish has been sent from the caller.\n *\n */\n get questionId() {\n return getUint32(0, this);\n }\n set questionId(value) {\n setUint32(0, value, this);\n }\n _adoptTarget(value) {\n adopt(value, getPointer(0, this));\n }\n _disownTarget() {\n return disown(this.target);\n }\n /**\n * The object that should receive this call.\n *\n */\n get target() {\n return getStruct(0, MessageTarget, this);\n }\n _hasTarget() {\n return !isNull(getPointer(0, this));\n }\n _initTarget() {\n return initStructAt(0, MessageTarget, this);\n }\n set target(value) {\n copyFrom(value, getPointer(0, this));\n }\n /**\n * The type ID of the interface being called. Each capability may implement multiple interfaces.\n *\n */\n get interfaceId() {\n return getUint64(8, this);\n }\n set interfaceId(value) {\n setUint64(8, value, this);\n }\n /**\n * The ordinal number of the method to call within the requested interface.\n *\n */\n get methodId() {\n return getUint16(4, this);\n }\n set methodId(value) {\n setUint16(4, value, this);\n }\n /**\n * Indicates whether or not the receiver is allowed to send a `Return` containing\n * `acceptFromThirdParty`. Level 3 implementations should set this true. Otherwise, the callee\n * will have to proxy the return in the case of a tail call to a third-party vat.\n *\n */\n get allowThirdPartyTailCall() {\n return getBit(128, this, Call._capnp.defaultAllowThirdPartyTailCall);\n }\n set allowThirdPartyTailCall(value) {\n setBit(128, value, this, Call._capnp.defaultAllowThirdPartyTailCall);\n }\n /**\n * If true, the sender promises that it won't make any promise-pipelined calls on the results of\n * this call. If it breaks this promise, the receiver may throw an arbitrary error from such\n * calls.\n *\n * The receiver may use this as an optimization, by skipping the bookkeeping needed for pipelining\n * when no pipelined calls are expected. The sender typically sets this to false when the method's\n * schema does not specify any return capabilities.\n *\n */\n get noPromisePipelining() {\n return getBit(129, this, Call._capnp.defaultNoPromisePipelining);\n }\n set noPromisePipelining(value) {\n setBit(129, value, this, Call._capnp.defaultNoPromisePipelining);\n }\n /**\n * If true, the sender only plans to use this call to make pipelined calls. The receiver need not\n * send a `Return` message (but is still allowed to do so).\n *\n * Since the sender does not know whether a `Return` will be sent, it must release all state\n * related to the call when it sends `Finish`. However, in the case that the callee does not\n * recognize this hint and chooses to send a `Return`, then technically the caller is not allowed\n * to reuse the question ID until it receives said `Return`. This creates a conundrum: How does\n * the caller decide when it's OK to reuse the ID? To sidestep the problem, the C++ implementation\n * uses high-numbered IDs (with the high-order bit set) for such calls, and cycles through the\n * IDs in order. If all 2^31 IDs in this space are used without ever seeing a `Return`, then the\n * implementation assumes that the other end is in fact honoring the hint, and the ID counter is\n * allowed to loop around. If a `Return` is ever seen when `onlyPromisePipeline` was set, then\n * the implementation stops using this hint.\n *\n */\n get onlyPromisePipeline() {\n return getBit(130, this, Call._capnp.defaultOnlyPromisePipeline);\n }\n set onlyPromisePipeline(value) {\n setBit(130, value, this, Call._capnp.defaultOnlyPromisePipeline);\n }\n _adoptParams(value) {\n adopt(value, getPointer(1, this));\n }\n _disownParams() {\n return disown(this.params);\n }\n /**\n * The call parameters. `params.content` is a struct whose fields correspond to the parameters of\n * the method.\n *\n */\n get params() {\n return getStruct(1, Payload, this);\n }\n _hasParams() {\n return !isNull(getPointer(1, this));\n }\n _initParams() {\n return initStructAt(1, Payload, this);\n }\n set params(value) {\n copyFrom(value, getPointer(1, this));\n }\n /**\n * Where should the return message be sent?\n *\n */\n get sendResultsTo() {\n return getAs(Call_SendResultsTo, this);\n }\n _initSendResultsTo() {\n return getAs(Call_SendResultsTo, this);\n }\n toString() {\n return \"Call_\" + super.toString();\n }\n}\nconst Return_Which = {\n /**\n * Equal to the QuestionId of the corresponding `Call` message.\n *\n */\n RESULTS: 0,\n /**\n * If true, all capabilities that were in the params should be considered released. The sender\n * must not send separate `Release` messages for them. Level 0 implementations in particular\n * should always set this true. This defaults true because if level 0 implementations forget to\n * set it they'll never notice (just silently leak caps), but if level >=1 implementations forget\n * to set it to false they'll quickly get errors.\n *\n * The receiver should act as if the sender had sent a release message with count=1 for each\n * CapDescriptor in the original Call message.\n *\n */\n EXCEPTION: 1,\n /**\n * The result.\n *\n * For regular method calls, `results.content` points to the result struct.\n *\n * For a `Return` in response to an `Accept` or `Bootstrap`, `results` contains a single\n * capability (rather than a struct), and `results.content` is just a capability pointer with\n * index 0. A `Finish` is still required in this case.\n *\n */\n CANCELED: 2,\n /**\n * Indicates that the call failed and explains why.\n *\n */\n RESULTS_SENT_ELSEWHERE: 3,\n /**\n * Indicates that the call was canceled due to the caller sending a Finish message\n * before the call had completed.\n *\n */\n TAKE_FROM_OTHER_QUESTION: 4,\n /**\n * This is set when returning from a `Call` that had `sendResultsTo` set to something other\n * than `caller`.\n *\n * It doesn't matter too much when this is sent, as the receiver doesn't need to do anything\n * with it, but the C++ implementation appears to wait for the call to finish before sending\n * this.\n *\n */\n ACCEPT_FROM_THIRD_PARTY: 5\n};\nclass Return extends Struct {\n static RESULTS = Return_Which.RESULTS;\n static EXCEPTION = Return_Which.EXCEPTION;\n static CANCELED = Return_Which.CANCELED;\n static RESULTS_SENT_ELSEWHERE = Return_Which.RESULTS_SENT_ELSEWHERE;\n static TAKE_FROM_OTHER_QUESTION = Return_Which.TAKE_FROM_OTHER_QUESTION;\n static ACCEPT_FROM_THIRD_PARTY = Return_Which.ACCEPT_FROM_THIRD_PARTY;\n static _capnp = {\n displayName: \"Return\",\n id: \"9e19b28d3db3573a\",\n size: new ObjectSize(16, 1),\n defaultReleaseParamCaps: getBitMask(true, 0),\n defaultNoFinishNeeded: getBitMask(false, 1)\n };\n /**\n * Equal to the QuestionId of the corresponding `Call` message.\n *\n */\n get answerId() {\n return getUint32(0, this);\n }\n set answerId(value) {\n setUint32(0, value, this);\n }\n /**\n * If true, all capabilities that were in the params should be considered released. The sender\n * must not send separate `Release` messages for them. Level 0 implementations in particular\n * should always set this true. This defaults true because if level 0 implementations forget to\n * set it they'll never notice (just silently leak caps), but if level >=1 implementations forget\n * to set it to false they'll quickly get errors.\n *\n * The receiver should act as if the sender had sent a release message with count=1 for each\n * CapDescriptor in the original Call message.\n *\n */\n get releaseParamCaps() {\n return getBit(32, this, Return._capnp.defaultReleaseParamCaps);\n }\n set releaseParamCaps(value) {\n setBit(32, value, this, Return._capnp.defaultReleaseParamCaps);\n }\n /**\n * If true, the sender does not need the receiver to send a `Finish` message; its answer table\n * entry has already been cleaned up. This implies that the results do not contain any\n * capabilities, since the `Finish` message would normally release those capabilities from\n * promise pipelining responsibility. The caller may still send a `Finish` message if it wants,\n * which will be silently ignored by the callee.\n *\n */\n get noFinishNeeded() {\n return getBit(33, this, Return._capnp.defaultNoFinishNeeded);\n }\n set noFinishNeeded(value) {\n setBit(33, value, this, Return._capnp.defaultNoFinishNeeded);\n }\n _adoptResults(value) {\n setUint16(6, 0, this);\n adopt(value, getPointer(0, this));\n }\n _disownResults() {\n return disown(this.res