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:
Luan
2024-11-02 10:30:41 -03:00
parent 008ded015f
commit 3faff2f6f5

View File

@@ -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;
}