(n: number, value: number)
| 441 | } |
| 442 | |
| 443 | writeBits(n: number, value: number) { |
| 444 | const end = this.pos + n; |
| 445 | |
| 446 | for (let i = this.pos; i < end; i++) { |
| 447 | const byteIndex = Math.floor(i / 8); |
| 448 | let byte = this.bytes[byteIndex]; |
| 449 | const bitIndex = 0b111 - (i & 0b111); |
| 450 | |
| 451 | byte &= ~(1 << bitIndex); |
| 452 | byte |= ((value & (1 << (end - i - 1))) >> (end - i - 1)) << bitIndex; |
| 453 | this.bytes[byteIndex] = byte; |
| 454 | } |
| 455 | |
| 456 | this.pos = end; |
| 457 | }; |
| 458 | |
| 459 | readAlignedByte() { |
| 460 | // Ensure we're byte-aligned |