(x: CborStreamInput[])
| 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 }, |
no test coverage detected