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

Function bsonaggvalue_recv

pg_documentdb/src/aggregation/bson_aggregates.c:2696–2719  ·  view source on GitHub ↗

* bsonaggvalue_recv: Deserialize BsonAggValue from binary network data. * Parses pgbson bytes, extracts the value and optional collation string. */

Source from the content-addressed store, hash-verified

2694 * Parses pgbson bytes, extracts the value and optional collation string.
2695 */
2696Datum
2697bsonaggvalue_recv(PG_FUNCTION_ARGS)
2698{
2699 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
2700
2701 /* Parse the buffer as pgbson */
2702 pgbson *bson = PgbsonInitFromBuffer(buf->data, buf->len);
2703
2704 /* Mark buffer as consumed */
2705 buf->cursor = buf->len;
2706
2707 pgbsonelement element;
2708 const char *collationString =
2709 PgbsonToSinglePgbsonElementWithCollation(bson, &element);
2710
2711 /* Allocate BsonAggValue and collation and deep-copy their values */
2712 BsonAggValue *state = (BsonAggValue *) palloc0(sizeof(BsonAggValue));
2713 SET_VARSIZE(state, sizeof(BsonAggValue));
2714 bson_value_copy(&element.bsonValue, &state->value);
2715 state->collationString = collationString != NULL ?
2716 pstrdup(collationString) : NULL;
2717
2718 PG_RETURN_POINTER(state);
2719}

Callers

nothing calls this directly

Tested by

no test coverage detected