(val: bigint | number)
| 454 | } |
| 455 | |
| 456 | writeVarUInt64(val: bigint | number) { |
| 457 | if (typeof val !== "bigint") { |
| 458 | if (Number.isSafeInteger(val) && val >= 0) { |
| 459 | this.writeVarUInt64Number(val); |
| 460 | return; |
| 461 | } |
| 462 | val = BigInt(val); |
| 463 | } |
| 464 | val = val & 0xFFFFFFFFFFFFFFFFn; // keep only the lower 64 bits |
| 465 | |
| 466 | // Match Java's 1-9 byte varuint64 encoding: |
| 467 | // - 7 bits per byte for the first 8 bytes |
| 468 | // - the 9th byte (if present) uses full 8 bits, allowing values with the 64th bit set |
| 469 | for (let i = 0; i < 8; i++) { |
| 470 | if ((val >> 7n) === 0n) { |
| 471 | this.platformBuffer[this.cursor++] = Number(val); |
| 472 | return; |
| 473 | } |
| 474 | this.platformBuffer[this.cursor++] = Number((val & 127n) | 128n); |
| 475 | val >>= 7n; |
| 476 | } |
| 477 | this.platformBuffer[this.cursor++] = Number(val & 255n); |
| 478 | } |
| 479 | |
| 480 | tryFreePool() { |
| 481 | if (this.byteLength > MAX_POOL_SIZE) { |
no test coverage detected