Skip to content

Commit 55b68b7

Browse files
committed
chore: comments
1 parent a088639 commit 55b68b7

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/cmap/commands.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ export class DocumentSequence {
433433
documents: Document[];
434434
serializedDocumentsLength: number;
435435
private chunks: Uint8Array[];
436-
private header?: Buffer;
436+
private header: Buffer;
437437

438438
/**
439439
* Create a new document sequence for the provided field.
@@ -444,33 +444,27 @@ export class DocumentSequence {
444444
this.documents = [];
445445
this.chunks = [];
446446
this.serializedDocumentsLength = 0;
447-
this.init();
448-
if (documents) {
449-
for (const doc of documents) {
450-
this.push(doc, BSON.serialize(doc));
451-
}
452-
}
453-
}
454-
455-
/**
456-
* Initialize the buffer chunks.
457-
*/
458-
private init() {
459447
// Document sequences starts with type 1 at the first byte.
448+
// Field strings must always be UTF-8.
460449
const buffer = Buffer.allocUnsafe(1 + 4 + this.field.length + 1);
461450
buffer[0] = 1;
462451
// Third part is the field name at offset 5 with trailing null byte.
463452
encodeUTF8Into(buffer, `${this.field}\0`, 5);
464453
this.chunks.push(buffer);
465454
this.header = buffer;
455+
if (documents) {
456+
for (const doc of documents) {
457+
this.push(doc, BSON.serialize(doc));
458+
}
459+
}
466460
}
467461

468462
/**
469463
* Push a document to the document sequence. Will serialize the document
470464
* as well and return the current serialized length of all documents.
471465
* @param document - The document to add.
472466
* @param buffer - The serialized document in raw BSON.
473-
* @returns The new totoal document sequence length.
467+
* @returns The new total document sequence length.
474468
*/
475469
push(document: Document, buffer: Uint8Array): number {
476470
this.serializedDocumentsLength += buffer.length;

src/operations/client_bulk_write/command_builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class ClientBulkWriteCommandBuilder {
105105
currentCommandLength + operationBuffer.length < maxMessageSizeBytes &&
106106
currentCommand.ops.documents.length < maxWriteBatchSize
107107
) {
108-
// Pushing to the ops document sequence returns the bytes length added.
108+
// Pushing to the ops document sequence returns the total byte length of the document sequence.
109109
currentCommandLength =
110110
MESSAGE_OVERHEAD_BYTES + this.addOperation(currentCommand, operation, operationBuffer);
111111
} else {
@@ -185,7 +185,7 @@ export class ClientBulkWriteCommandBuilder {
185185
operation: Document,
186186
operationBuffer: Uint8Array
187187
): number {
188-
// Pushing to the ops document sequence returns the bytes length added.
188+
// Pushing to the ops document sequence returns the total byte length of the document sequence.
189189
return command.ops.push(operation, operationBuffer);
190190
}
191191

@@ -196,7 +196,7 @@ export class ClientBulkWriteCommandBuilder {
196196
nsInfo: Document,
197197
nsInfoBuffer: Uint8Array
198198
): number {
199-
// Pushing to the nsInfo document sequence returns the bytes length added.
199+
// Pushing to the nsInfo document sequence returns the total byte length of the document sequence.
200200
const nsInfoLength = command.nsInfo.push(nsInfo, nsInfoBuffer);
201201
const opsLength = this.addOperation(command, operation, operationBuffer);
202202
return nsInfoLength + opsLength;

0 commit comments

Comments
 (0)