MCPcopy
hub / github.com/mongodb/node-mongodb-native / getInt32

Method getInt32

src/utils.ts:818–837  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

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 {

Callers 2

utils.test.tsFile · 0.80
_transformMethod · 0.80

Calls 3

readMethod · 0.95
firstMethod · 0.80
unshiftMethod · 0.80

Tested by

no test coverage detected