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

Method parse

src/cmap/commands.ts:366–410  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

364 }
365
366 parse(): Uint8Array {
367 // Don't parse again if not needed
368 if (this.parsed) return this.sections[0];
369
370 // Position within OP_REPLY at which documents start
371 // (See https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/#wire-op-reply)
372 this.index = 20;
373
374 // Read the message body
375 this.responseFlags = readInt32LE(this.data, 0);
376 this.cursorId = new BSON.Long(readInt32LE(this.data, 4), readInt32LE(this.data, 8));
377 this.startingFrom = readInt32LE(this.data, 12);
378 this.numberReturned = readInt32LE(this.data, 16);
379
380 if (this.numberReturned < 0 || this.numberReturned > 2 ** 32 - 1) {
381 throw new RangeError(
382 `OP_REPLY numberReturned is an invalid array length ${this.numberReturned}`
383 );
384 }
385
386 this.cursorNotFound = (this.responseFlags & CURSOR_NOT_FOUND) !== 0;
387 this.queryFailure = (this.responseFlags & QUERY_FAILURE) !== 0;
388 this.shardConfigStale = (this.responseFlags & SHARD_CONFIG_STALE) !== 0;
389 this.awaitCapable = (this.responseFlags & AWAIT_CAPABLE) !== 0;
390
391 // Parse Body
392 for (let i = 0; i < this.numberReturned; i++) {
393 const bsonSize =
394 this.data[this.index] |
395 (this.data[this.index + 1] << 8) |
396 (this.data[this.index + 2] << 16) |
397 (this.data[this.index + 3] << 24);
398
399 const section = this.data.subarray(this.index, this.index + bsonSize);
400 this.sections.push(section);
401
402 // Adjust the index
403 this.index = this.index + bsonSize;
404 }
405
406 // Set parsed
407 this.parsed = true;
408
409 return this.sections[0];
410 }
411}
412
413// Msg Flags

Callers 15

mainFunction · 0.45
friendlyDateFunction · 0.45
collectTestsFunction · 0.45
mainFunction · 0.45
ZFunction · 0.45
getCSFLEKMSProvidersFunction · 0.45
cloneMethod · 0.45
initializeFilterMethod · 0.45
specialCheckFunction · 0.45
gatherTestSuitesFunction · 0.45
runTestSuiteTestFunction · 0.45

Calls 2

readInt32LEFunction · 0.90
pushMethod · 0.45

Tested by 14

testFunction · 0.36
readTestFilesForFunction · 0.36
loadExternalFunction · 0.36
loadLimitsFunction · 0.36
prepareOptionsFunction · 0.36
loadCorpusDataFunction · 0.36
toComparableExtendedJSONFunction · 0.36
readFixtureFunction · 0.36
loadFLEDataFileFunction · 0.36
collectStalenessTestsFunction · 0.36
collectTestsFunction · 0.36
cloneMapFunction · 0.36