( input: Uint8Array, aI: number, offset: number, )
| 205 | } |
| 206 | |
| 207 | function decodeFive( |
| 208 | input: Uint8Array, |
| 209 | aI: number, |
| 210 | offset: number, |
| 211 | ): [{ [k: string]: CborType }, number] { |
| 212 | if (aI <= 27) { |
| 213 | const x = calcLength(input, aI, offset); |
| 214 | // Can safely assume `x[0] < 2 ** 53` as JavaScript doesn't support an `Object` being that large. |
| 215 | const length = Number(x[0]); |
| 216 | offset = x[1]; |
| 217 | const output: { [k: string]: CborType } = {}; |
| 218 | for (let i = 0; i < length; ++i) { |
| 219 | const y = decode(input, offset); |
| 220 | if (typeof y[0] !== "string") { |
| 221 | throw new TypeError( |
| 222 | `Cannot decode key of type (${typeof y[ |
| 223 | 0 |
| 224 | ]}): This implementation only supports "text string" keys`, |
| 225 | ); |
| 226 | } |
| 227 | if (output[y[0]] !== undefined) { |
| 228 | throw new TypeError( |
| 229 | `A Map cannot have duplicate keys: Key (${y[0]}) already exists`, |
| 230 | ); // https://datatracker.ietf.org/doc/html/rfc8949#name-specifying-keys-for-maps |
| 231 | } |
| 232 | const z = decode(input, y[1]); |
| 233 | output[y[0]] = z[0]; |
| 234 | offset = z[1]; |
| 235 | } |
| 236 | return [output, offset]; |
| 237 | } |
| 238 | if (aI === 31) { |
| 239 | const output: { [k: string]: CborType } = {}; |
| 240 | while (input[offset] !== 0b111_11111) { |
| 241 | const x = decode(input, offset); |
| 242 | if (typeof x[0] !== "string") { |
| 243 | throw new TypeError( |
| 244 | `Cannot decode key of type (${typeof x[ |
| 245 | 0 |
| 246 | ]}): This implementation only supports "text string" keys`, |
| 247 | ); |
| 248 | } |
| 249 | if (output[x[0]] !== undefined) { |
| 250 | throw new TypeError( |
| 251 | `A Map cannot have duplicate keys: Key (${x[0]}) already exists`, |
| 252 | ); // https://datatracker.ietf.org/doc/html/rfc8949#name-specifying-keys-for-maps |
| 253 | } |
| 254 | const y = decode(input, x[1]); |
| 255 | output[x[0]] = y[0]; |
| 256 | offset = y[1]; |
| 257 | } |
| 258 | return [output, offset + 1]; |
| 259 | } |
| 260 | throw new RangeError( |
| 261 | `Cannot decode value (0b101_${aI.toString(2).padStart(5, "0")})`, |
| 262 | ); |
| 263 | } |
| 264 |
no test coverage detected