MCPcopy Create free account
hub / github.com/documentdb/documentdb / SetupCursorPagePreamble

Function SetupCursorPagePreamble

pg_documentdb/src/commands/cursors.c:2476–2507  ·  view source on GitHub ↗

* Set-up the preamble for the cursor page - including the cursorId (which will be * overwritten later), the namespace, and sets up the documents array. */

Source from the content-addressed store, hash-verified

2474 * overwritten later), the namespace, and sets up the documents array.
2475 */
2476void
2477SetupCursorPagePreamble(pgbson_writer *topLevelWriter, pgbson_writer *cursorDoc,
2478 pgbson_array_writer *arrayWriter,
2479 const char *namespaceName, bool isFirstPage,
2480 uint32_t *accumulatedLength)
2481{
2482 PgbsonWriterInit(topLevelWriter);
2483
2484 /* Write the preface */
2485 PgbsonWriterStartDocument(topLevelWriter, "cursor", 6, cursorDoc);
2486
2487 /* Write the cursor ID, this is overwritten later */
2488 PgbsonWriterAppendInt64(cursorDoc, "id", 2, 0);
2489
2490 /* write the namespace */
2491 PgbsonWriterAppendUtf8(cursorDoc, "ns", 2, namespaceName);
2492
2493 *accumulatedLength += PgbsonWriterGetSize(cursorDoc);
2494
2495 /* Write the documents */
2496 const char *pathName = "firstBatch";
2497 if (!isFirstPage)
2498 {
2499 pathName = "nextBatch";
2500 }
2501
2502 uint32_t pathLength = strlen(pathName);
2503 *accumulatedLength += pathLength;
2504
2505 PgbsonWriterStartArray(cursorDoc, pathName, pathLength, arrayWriter);
2506 *accumulatedLength += 5;
2507}
2508
2509
2510/*

Callers 2

HandleFirstPageRequestFunction · 0.85

Calls 6

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt64Function · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterGetSizeFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85

Tested by

no test coverage detected