MCPcopy Index your code
hub / github.com/cloudflare/capnweb / constructor

Method constructor

src/rpc.ts:473–499  ·  view source on GitHub ↗
(private transport: AnyRpcTransport, mainHook: StubHook,
      private options: RpcSessionOptions)

Source from the content-addressed store, hash-verified

471 private encodingLevel: EncodingLevel;
472
473 constructor(private transport: AnyRpcTransport, mainHook: StubHook,
474 private options: RpcSessionOptions) {
475 // `RpcTransport` has no `encodingLevel` field, so its presence is what marks a custom-encoding
476 // transport. Read it defensively: treat a present-but-`undefined` value (e.g. an uninitialized
477 // class field) as the default string level rather than mis-routing it down the custom-encoding
478 // path, and reject any other unrecognized value (e.g. a stale pre-rename level name) loudly
479 // instead of silently corrupting the wire.
480 let level: EncodingLevel = "string";
481 if ('encodingLevel' in transport) {
482 let raw = transport.encodingLevel as unknown;
483 if (raw !== undefined) {
484 if (raw !== "string" && raw !== "jsonCompatible" &&
485 raw !== "jsonCompatibleWithBytes" && raw !== "structuredClonable") {
486 throw new TypeError(`Unknown transport encodingLevel: ${String(raw)}`);
487 }
488 level = raw;
489 }
490 }
491 this.encodingLevel = level;
492 // Export zero is automatically the bootstrap object.
493 this.exports.push({hook: mainHook, refcount: 1});
494
495 // Import zero is the other side's bootstrap object.
496 this.imports.push(new ImportTableEntry(this, 0, false));
497
498 this.readLoop().catch(err => this.abort(err));
499 }
500
501 // Should only be called once immediately after construction.
502 getMainImport(): RpcImportHook {

Callers

nothing calls this directly

Calls 3

readLoopMethod · 0.95
abortMethod · 0.95
catchMethod · 0.80

Tested by

no test coverage detected