11import {
2- allocateBuffer ,
3- allocateUnsafeBuffer ,
42 BSON ,
53 type BSONSerializeOptions ,
64 ByteUtils ,
7- concatBuffers ,
85 type Document ,
96 type Long ,
107 readInt32LE ,
@@ -192,7 +189,7 @@ export class OpQueryRequest {
192189 if ( this . batchSize !== this . numberToReturn ) this . numberToReturn = this . batchSize ;
193190
194191 // Allocate write protocol header buffer
195- const header = allocateBuffer (
192+ const header = ByteUtils . allocate (
196193 4 * 4 + // Header
197194 4 + // Flags
198195 ByteUtils . utf8ByteLength ( this . ns ) +
@@ -456,7 +453,7 @@ export class DocumentSequence {
456453 this . serializedDocumentsLength = 0 ;
457454 // Document sequences starts with type 1 at the first byte.
458455 // Field strings must always be UTF-8.
459- const buffer = allocateUnsafeBuffer ( 1 + 4 + this . field . length + 1 ) ;
456+ const buffer = ByteUtils . allocateUnsafe ( 1 + 4 + this . field . length + 1 ) ;
460457 buffer [ 0 ] = 1 ;
461458 // Third part is the field name at offset 5 with trailing null byte.
462459 encodeUTF8Into ( buffer , `${ this . field } \0` , 5 ) ;
@@ -494,7 +491,7 @@ export class DocumentSequence {
494491 * @returns The section bytes.
495492 */
496493 toBin ( ) : Uint8Array {
497- return concatBuffers ( this . chunks ) ;
494+ return ByteUtils . concat ( this . chunks ) ;
498495 }
499496}
500497
@@ -559,7 +556,7 @@ export class OpMsgRequest {
559556 flags |= OPTS_EXHAUST_ALLOWED ;
560557 }
561558
562- const header = allocateBuffer (
559+ const header = ByteUtils . allocate (
563560 4 * 4 + // Header
564561 4 // Flags
565562 ) ;
@@ -583,7 +580,7 @@ export class OpMsgRequest {
583580 */
584581 makeSections ( buffers : Uint8Array [ ] , document : Document ) : number {
585582 const sequencesBuffer = this . extractDocumentSequences ( document ) ;
586- const payloadTypeBuffer = allocateUnsafeBuffer ( 1 ) ;
583+ const payloadTypeBuffer = ByteUtils . allocateUnsafe ( 1 ) ;
587584 payloadTypeBuffer [ 0 ] = 0 ;
588585
589586 const documentBuffer = this . serializeBson ( document ) ;
@@ -618,11 +615,11 @@ export class OpMsgRequest {
618615 }
619616 }
620617 if ( chunks . length > 0 ) {
621- return concatBuffers ( chunks ) ;
618+ return ByteUtils . concat ( chunks ) ;
622619 }
623620 // If we have no document sequences we return an empty buffer for nothing to add
624621 // to the payload.
625- return allocateBuffer ( 0 ) ;
622+ return ByteUtils . allocate ( 0 ) ;
626623 }
627624
628625 serializeBson ( document : Document ) : Uint8Array {
@@ -771,7 +768,7 @@ export class OpCompressedRequest {
771768 }
772769
773770 async toBin ( ) : Promise < Uint8Array [ ] > {
774- const concatenatedOriginalCommandBuffer = concatBuffers ( this . command . toBin ( ) ) ;
771+ const concatenatedOriginalCommandBuffer = ByteUtils . concat ( this . command . toBin ( ) ) ;
775772 // otherwise, compress the message
776773 const messageToBeCompressed = concatenatedOriginalCommandBuffer . slice ( MESSAGE_HEADER_SIZE ) ;
777774
@@ -781,7 +778,7 @@ export class OpCompressedRequest {
781778 // Compress the message body
782779 const compressedMessage = await compress ( this . options , messageToBeCompressed ) ;
783780 // Create the msgHeader of OP_COMPRESSED
784- const msgHeader = allocateBuffer ( MESSAGE_HEADER_SIZE ) ;
781+ const msgHeader = ByteUtils . allocate ( MESSAGE_HEADER_SIZE ) ;
785782 writeInt32LE (
786783 msgHeader ,
787784 MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage . length ,
@@ -791,7 +788,7 @@ export class OpCompressedRequest {
791788 writeInt32LE ( msgHeader , 0 , 8 ) ; // responseTo (zero)
792789 writeInt32LE ( msgHeader , OP_COMPRESSED , 12 ) ; // opCode
793790 // Create the compression details of OP_COMPRESSED
794- const compressionDetails = allocateBuffer ( COMPRESSION_DETAILS_SIZE ) ;
791+ const compressionDetails = ByteUtils . allocate ( COMPRESSION_DETAILS_SIZE ) ;
795792 writeInt32LE ( compressionDetails , originalCommandOpCode , 0 ) ; // originalOpcode
796793 writeInt32LE ( compressionDetails , messageToBeCompressed . length , 4 ) ; // Size of the uncompressed compressedMessage, excluding the MsgHeader
797794 writeInt32LE ( compressionDetails , Compressor [ this . options . agreedCompressor ] , 8 ) ; // compressorID
0 commit comments