| 298 | } |
| 299 | |
| 300 | readVarUInt32() { |
| 301 | // Reduce memory reads as much as possible. Reading a uint32 at once is far faster than reading four uint8s separately. |
| 302 | const cursor = this.cursor; |
| 303 | if (this.byteLength - cursor >= 5) { |
| 304 | const fourByteValue = this.dataView.getUint32(cursor, true); |
| 305 | let readIdx = cursor + 1; |
| 306 | // | 1bit + 7bits | 1bit + 7bits | 1bit + 7bits | 1bit + 7bits | |
| 307 | let result = fourByteValue & 0x7f; |
| 308 | if ((fourByteValue & 0x80) != 0) { |
| 309 | readIdx++; |
| 310 | // 0x3f80: 0b1111111 << 7 |
| 311 | result |= (fourByteValue >>> 1) & 0x3f80; |
| 312 | if ((fourByteValue & 0x8000) != 0) { |
| 313 | readIdx++; |
| 314 | // 0x1fc000: 0b1111111 << 14 |
| 315 | result |= (fourByteValue >>> 2) & 0x1fc000; |
| 316 | if ((fourByteValue & 0x800000) != 0) { |
| 317 | readIdx++; |
| 318 | // 0xfe00000: 0b1111111 << 21 |
| 319 | result |= (fourByteValue >>> 3) & 0xfe00000; |
| 320 | if ((fourByteValue & 0x80000000) != 0) { |
| 321 | result |= this.dataView.getUint8(readIdx++) << 28; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | this.cursor = readIdx; |
| 327 | return result >>> 0; |
| 328 | } |
| 329 | let byte = this.readUint8(); |
| 330 | let result = byte & 0x7f; |
| 331 | if ((byte & 0x80) != 0) { |
| 332 | byte = this.readUint8(); |
| 333 | result |= (byte & 0x7f) << 7; |
| 334 | if ((byte & 0x80) != 0) { |
| 335 | byte = this.readUint8(); |
| 336 | result |= (byte & 0x7f) << 14; |
| 337 | if ((byte & 0x80) != 0) { |
| 338 | byte = this.readUint8(); |
| 339 | result |= (byte & 0x7f) << 21; |
| 340 | if ((byte & 0x80) != 0) { |
| 341 | byte = this.readUint8(); |
| 342 | result |= byte << 28; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | return result >>> 0; |
| 348 | } |
| 349 | |
| 350 | readVarUint32Small7(): number { |
| 351 | const readIdx = this.cursor; |