* If BufferPool contains 4 bytes or more construct an int32 from the leading bytes, * otherwise return null. Size can be negative, caller should error check.
()
| 816 | * otherwise return null. Size can be negative, caller should error check. |
| 817 | */ |
| 818 | getInt32(): number | null { |
| 819 | if (this.totalByteLength < 4) { |
| 820 | return null; |
| 821 | } |
| 822 | const firstBuffer = this.buffers.first(); |
| 823 | if (firstBuffer != null && firstBuffer.byteLength >= 4) { |
| 824 | return NumberUtils.getInt32LE(firstBuffer, 0); |
| 825 | } |
| 826 | |
| 827 | // Unlikely case: an int32 is split across buffers. |
| 828 | // Use read and put the returned buffer back on top |
| 829 | const top4Bytes = this.read(4); |
| 830 | const value = NumberUtils.getInt32LE(top4Bytes, 0); |
| 831 | |
| 832 | // Put it back. |
| 833 | this.totalByteLength += 4; |
| 834 | this.buffers.unshift(top4Bytes); |
| 835 | |
| 836 | return value; |
| 837 | } |
| 838 | |
| 839 | /** Reads the requested number of bytes, optionally consuming them */ |
| 840 | read(size: number): Uint8Array { |
no test coverage detected