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

Method #encodeArray

cbor/sequence_encoder_stream.ts:148–162  ·  view source on GitHub ↗
(x: CborStreamInput[])

Source from the content-addressed store, hash-verified

146 }
147
148 async *#encodeArray(x: CborStreamInput[]): AsyncGenerator<Uint8Array> {
149 if (x.length < 24) yield new Uint8Array([0b100_00000 + x.length]);
150 else if (x.length < 2 ** 8) yield new Uint8Array([0b100_11000, x.length]);
151 else if (x.length < 2 ** 16) {
152 yield new Uint8Array([0b100_11001, ...numberToArray(2, x.length)]);
153 } else if (x.length < 2 ** 32) {
154 yield new Uint8Array([0b100_11010, ...numberToArray(4, x.length)]);
155 } // Can safely assume `x.length < 2 ** 64` as JavaScript doesn't support an `Array` being that large.
156 else yield new Uint8Array([0b100_11011, ...numberToArray(8, x.length)]);
157 for (const y of x) {
158 for await (const z of this.#encode(y)) {
159 yield z;
160 }
161 }
162 }
163
164 async *#encodeObject(
165 x: { [k: string]: CborStreamInput },

Callers 1

#encodeMethod · 0.95

Calls 2

#encodeMethod · 0.95
numberToArrayFunction · 0.90

Tested by

no test coverage detected