Add packet type derivation logic, new verifyKeyPackets options, new determinePacketType method

This commit is contained in:
Vanilagy
2025-07-24 16:09:01 +02:00
parent 904ac2e366
commit 5e933d9362
12 changed files with 581 additions and 204 deletions
+6 -2
View File
@@ -48,7 +48,7 @@ export class Bitstream {
this.pos = 8 * byteOffset;
}
readBit() {
private readBit() {
const byteIndex = Math.floor(this.pos / 8);
const byte = this.bytes[byteIndex] ?? 0;
const bitIndex = 0b111 - (this.pos & 0b111);
@@ -59,6 +59,10 @@ export class Bitstream {
}
readBits(n: number) {
if (n === 1) {
return this.readBit();
}
let result = 0;
for (let i = 0; i < n; i++) {
@@ -100,7 +104,7 @@ export class Bitstream {
/** Reads an exponential-Golomb universal code from a Bitstream. */
export const readExpGolomb = (bitstream: Bitstream) => {
let leadingZeroBits = 0;
while (bitstream.readBit() === 0 && leadingZeroBits < 32) {
while (bitstream.readBits(1) === 0 && leadingZeroBits < 32) {
leadingZeroBits++;
}