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

Function BuildResponseMessage

pg_documentdb/src/commands/validate.c:323–357  ·  view source on GitHub ↗

* Builds the pgbson response for the validate() command */

Source from the content-addressed store, hash-verified

321 * Builds the pgbson response for the validate() command
322 */
323static pgbson *
324BuildResponseMessage(ValidateResult *result)
325{
326 pgbson_writer writer;
327 PgbsonWriterInit(&writer);
328
329 PgbsonWriterAppendUtf8(&writer, "ns", 2, result->ns);
330 PgbsonWriterAppendInt64(&writer, "nIndexes", 8, result->totalIndexes);
331 PgbsonWriterAppendDocument(&writer, "indexDetails", 12, result->indexDetailsPgbson);
332 PgbsonWriterAppendBool(&writer, "valid", 5, result->isValid);
333 PgbsonWriterAppendBool(&writer, "repaired", 8, result->isRepaired);
334
335 pgbson_array_writer writeWarningsWriter;
336 PgbsonWriterStartArray(&writer, "warnings", 8, &writeWarningsWriter);
337 ListCell *writeWarningCell = NULL;
338 foreach(writeWarningCell, result->warnings)
339 {
340 StringInfo warning = lfirst(writeWarningCell);
341 PgbsonArrayWriterWriteUtf8(&writeWarningsWriter, warning->data);
342 }
343 PgbsonWriterEndArray(&writer, &writeWarningsWriter);
344
345 pgbson_array_writer writeErrorsWriter;
346 PgbsonWriterStartArray(&writer, "errors", 6, &writeErrorsWriter);
347 ListCell *writeErrorCell = NULL;
348 foreach(writeErrorCell, result->errors)
349 {
350 StringInfo error = lfirst(writeErrorCell);
351 PgbsonArrayWriterWriteUtf8(&writeErrorsWriter, error->data);
352 }
353 PgbsonWriterEndArray(&writer, &writeErrorsWriter);
354
355 PgbsonWriterAppendDouble(&writer, "ok", 2, result->ok);
356 return PgbsonWriterGetPgbson(&writer);
357}

Callers 1

command_validateFunction · 0.70

Calls 11

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterAppendInt64Function · 0.85
PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterStartArrayFunction · 0.85
PgbsonWriterEndArrayFunction · 0.85
PgbsonWriterAppendDoubleFunction · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected