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

Function FillPgbsonElementUnsafe

pg_documentdb_core/src/io/pgbsonelement.c:327–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325
326
327static bool
328FillPgbsonElementUnsafe(uint8_t *data, uint32_t data_len, pgbsonelement *element)
329{
330#if BSON_BYTE_ORDER == BSON_BIG_ENDIAN
331 bson_iter_t iterator;
332
333 if (!bson_iter_init_from_data(&iterator,
334 data,
335 data_len))
336 {
337 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
338 errmsg("Could not initialize bson iterator.")));
339 }
340
341 if (!bson_iter_next(&iterator))
342 {
343 ereport(ERROR, errmsg("invalid input BSON: Should not be empty document"));
344 }
345
346 BsonIterToPgbsonElement(&iterator, element);
347 return true;
348#else
349 uint32_t minLength = 5;
350 uint32_t typeOffset = 4;
351 Assert(data != NULL);
352
353 if (data_len < minLength)
354 {
355 ereport(ERROR, errmsg("invalid input BSON: Should not be empty document"));
356 }
357
358 /* First 4 bytes are the length */
359 uint32_t length;
360 memcpy(&length, data, sizeof(uint32_t));
361
362 /* Fifth byte is the value */
363 element->bsonValue.value_type = (bson_type_t) data[typeOffset];
364
365 /* Then the path that is null terminated */
366 element->path = (char *) &data[minLength];
367 element->pathLength = strlen(element->path);
368 data += element->pathLength + minLength + 1;
369
370 int lengthLeft = length - element->pathLength - minLength;
371 return FillBsonElementValueAndPathUnsafe(element, data, lengthLeft);
372#endif
373}
374
375
376#if BSON_BYTE_ORDER != BSON_BIG_ENDIAN

Calls 2

BsonIterToPgbsonElementFunction · 0.85

Tested by

no test coverage detected