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

Function FillBuffer

pg_documentdb/src/infrastructure/cursor_store.c:530–570  ·  view source on GitHub ↗

* Fills the specified buffer with length bytes from the cursor file. * returns false if the end of the file is reached. */

Source from the content-addressed store, hash-verified

528 * returns false if the end of the file is reached.
529 */
530static bool
531FillBuffer(CursorFileState *cursorFileState, char *buffer, int32_t length)
532{
533 while (length > 0)
534 {
535 if (cursorFileState->nbytes == 0)
536 {
537 int bytesRead = FileRead(cursorFileState->bufFile,
538 cursorFileState->buffer.data, BLCKSZ,
539 cursorFileState->next_offset,
540 WAIT_EVENT_BUFFILE_READ);
541 cursorFileState->nbytes += bytesRead;
542 cursorFileState->pos = 0;
543 if (bytesRead == 0)
544 {
545 /* There's no more bytes left */
546 cursorFileState->cursorComplete = true;
547 return false;
548 }
549 }
550
551 int32_t currentAvailable = cursorFileState->nbytes - cursorFileState->pos;
552 if (currentAvailable >= length)
553 {
554 memcpy(buffer, cursorFileState->buffer.data + cursorFileState->pos, length);
555 cursorFileState->pos += length;
556 cursorFileState->next_offset += length;
557 return true;
558 }
559
560 memcpy(buffer, cursorFileState->buffer.data + cursorFileState->pos,
561 currentAvailable);
562
563 cursorFileState->pos = cursorFileState->nbytes = 0;
564 cursorFileState->next_offset += currentAvailable;
565 buffer += currentAvailable;
566 length -= currentAvailable;
567 }
568
569 return true;
570}
571
572
573/*

Callers 1

ReadFromCursorFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected