* Builds the pgbson response for the validate() command */
| 321 | * Builds the pgbson response for the validate() command |
| 322 | */ |
| 323 | static pgbson * |
| 324 | BuildResponseMessage(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 | } |
no test coverage detected