|
4 | 4 | ByteUtils, |
5 | 5 | type Document, |
6 | 6 | type Long, |
7 | | - readInt32LE, |
8 | | - writeInt32LE |
| 7 | + NumberUtils, |
| 8 | + readInt32LE |
9 | 9 | } from '../bson'; |
10 | 10 | import { MongoInvalidArgumentError, MongoRuntimeError } from '../error'; |
11 | 11 | import { type ReadPreference } from '../read_preference'; |
@@ -481,7 +481,11 @@ export class DocumentSequence { |
481 | 481 | this.chunks.push(buffer); |
482 | 482 | // Write the new length. |
483 | 483 | if (this.header) { |
484 | | - writeInt32LE(this.header, 4 + this.field.length + 1 + this.serializedDocumentsLength, 1); |
| 484 | + NumberUtils.setInt32LE( |
| 485 | + this.header, |
| 486 | + 1, |
| 487 | + 4 + this.field.length + 1 + this.serializedDocumentsLength |
| 488 | + ); |
485 | 489 | } |
486 | 490 | return this.serializedDocumentsLength + this.header.length; |
487 | 491 | } |
@@ -567,11 +571,11 @@ export class OpMsgRequest { |
567 | 571 | const command = this.command; |
568 | 572 | totalLength += this.makeSections(buffers, command); |
569 | 573 |
|
570 | | - writeInt32LE(header, totalLength, 0); // messageLength |
571 | | - writeInt32LE(header, this.requestId, 4); // requestID |
572 | | - writeInt32LE(header, 0, 8); // responseTo |
573 | | - writeInt32LE(header, OP_MSG, 12); // opCode |
574 | | - writeInt32LE(header, flags, 16); // flags |
| 574 | + NumberUtils.setInt32LE(header, 0, totalLength); // messageLength |
| 575 | + NumberUtils.setInt32LE(header, 4, this.requestId); // requestID |
| 576 | + NumberUtils.setInt32LE(header, 8, 0); // responseTo |
| 577 | + NumberUtils.setInt32LE(header, 12, OP_MSG); // opCode |
| 578 | + NumberUtils.setInt32LE(header, flags, 16); // flags |
575 | 579 | return buffers; |
576 | 580 | } |
577 | 581 |
|
@@ -779,18 +783,18 @@ export class OpCompressedRequest { |
779 | 783 | const compressedMessage = await compress(this.options, messageToBeCompressed); |
780 | 784 | // Create the msgHeader of OP_COMPRESSED |
781 | 785 | const msgHeader = ByteUtils.allocate(MESSAGE_HEADER_SIZE); |
782 | | - writeInt32LE( |
| 786 | + NumberUtils.setInt32LE( |
783 | 787 | msgHeader, |
784 | | - MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage.length, |
785 | | - 0 |
| 788 | + 0, |
| 789 | + MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage.length |
786 | 790 | ); // messageLength |
787 | | - writeInt32LE(msgHeader, this.command.requestId, 4); // requestID |
788 | | - writeInt32LE(msgHeader, 0, 8); // responseTo (zero) |
789 | | - writeInt32LE(msgHeader, OP_COMPRESSED, 12); // opCode |
| 791 | + NumberUtils.setInt32LE(msgHeader, 4, this.command.requestId); // requestID |
| 792 | + NumberUtils.setInt32LE(msgHeader, 8, 0); // responseTo (zero) |
| 793 | + NumberUtils.setInt32LE(msgHeader, 12, OP_COMPRESSED); // opCode |
790 | 794 | // Create the compression details of OP_COMPRESSED |
791 | 795 | const compressionDetails = ByteUtils.allocate(COMPRESSION_DETAILS_SIZE); |
792 | | - writeInt32LE(compressionDetails, originalCommandOpCode, 0); // originalOpcode |
793 | | - writeInt32LE(compressionDetails, messageToBeCompressed.length, 4); // Size of the uncompressed compressedMessage, excluding the MsgHeader |
| 796 | + NumberUtils.setInt32LE(compressionDetails, 0, originalCommandOpCode); // originalOpcode |
| 797 | + NumberUtils.setInt32LE(compressionDetails, 4, messageToBeCompressed.length); // Size of the uncompressed compressedMessage, excluding the MsgHeader |
794 | 798 | compressionDetails[8] = Compressor[this.options.agreedCompressor]; // compressorID |
795 | 799 | return [msgHeader, compressionDetails, compressedMessage]; |
796 | 800 | } |
|
0 commit comments