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