mirror of
https://github.com/LuanRT/googlevideo.git
synced 2026-06-13 00:32:11 +00:00
refactor(UMP): Simplify readVarInt method
Based on the following from the latest `base.js` from YouTube:
```ts
if (a.Kx(b, 1)) {
var c = a.getUint8(b);
c = c < 128 ? 1 : c < 192 ? 2 : c < 224 ? 3 : c < 240 ? 4 : 5
} else
c = 0;
```
This commit is contained in:
@@ -38,24 +38,13 @@ export class UMP {
|
||||
}
|
||||
}
|
||||
|
||||
public readVarInt(offset: number): [ number, number ] {
|
||||
public readVarInt(offset: number): [number, number] {
|
||||
let byteLength: number;
|
||||
|
||||
// Determine the length of the val
|
||||
if (this.chunkedDataBuffer.canReadBytes(offset, 1)) {
|
||||
const firstByte = this.chunkedDataBuffer.getUint8(offset);
|
||||
|
||||
// Determine the length of the val
|
||||
if (firstByte < 128) {
|
||||
byteLength = 1;
|
||||
} else if (firstByte < 192) {
|
||||
byteLength = 2;
|
||||
} else if (firstByte < 224) {
|
||||
byteLength = 3;
|
||||
} else if (firstByte < 240) {
|
||||
byteLength = 4;
|
||||
} else {
|
||||
byteLength = 5;
|
||||
}
|
||||
byteLength = firstByte < 128 ? 1 : firstByte < 192 ? 2 : firstByte < 224 ? 3 : firstByte < 240 ? 4 : 5;
|
||||
} else {
|
||||
byteLength = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user