* Set-up the preamble for the cursor page - including the cursorId (which will be * overwritten later), the namespace, and sets up the documents array. */
| 2474 | * overwritten later), the namespace, and sets up the documents array. |
| 2475 | */ |
| 2476 | void |
| 2477 | SetupCursorPagePreamble(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 | /* |
no test coverage detected