MCPcopy Create free account
hub / github.com/denoland/std / #encodeObject

Method #encodeObject

cbor/sequence_encoder_stream.ts:164–182  ·  view source on GitHub ↗
(
    x: { [k: string]: CborStreamInput },
  )

Source from the content-addressed store, hash-verified

162 }
163
164 async *#encodeObject(
165 x: { [k: string]: CborStreamInput },
166 ): AsyncGenerator<Uint8Array> {
167 const len = Object.keys(x).length;
168 if (len < 24) yield new Uint8Array([0b101_00000 + len]);
169 else if (len < 2 ** 8) yield new Uint8Array([0b101_11000, len]);
170 else if (len < 2 ** 16) {
171 yield new Uint8Array([0b101_11001, ...numberToArray(2, len)]);
172 } else if (len < 2 ** 32) {
173 yield new Uint8Array([0b101_11010, ...numberToArray(4, len)]);
174 } // Can safely assume `len < 2 ** 64` as JavaScript doesn't support an `Object` being that Large.
175 else yield new Uint8Array([0b101_11011, ...numberToArray(8, len)]);
176 for (const [k, v] of Object.entries(x)) {
177 yield encodeCbor(k);
178 for await (const y of this.#encode(v)) {
179 yield y;
180 }
181 }
182 }
183
184 async *#encodeTag(x: CborTag<CborStreamInput>): AsyncGenerator<Uint8Array> {
185 const tagNumber = BigInt(x.tagNumber);

Callers 1

#encodeMethod · 0.95

Calls 5

#encodeMethod · 0.95
numberToArrayFunction · 0.90
encodeCborFunction · 0.90
keysMethod · 0.80
entriesMethod · 0.45

Tested by

no test coverage detected