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

Function PgbsonToHexadecimalString

pg_documentdb_core/src/io/pgbson.c:169–187  ·  view source on GitHub ↗

* Converts a pgbson to a hexadecimal string representation. */

Source from the content-addressed store, hash-verified

167 * Converts a pgbson to a hexadecimal string representation.
168 */
169const char *
170PgbsonToHexadecimalString(const pgbson *bsonDocument)
171{
172 size_t binarySize = VARSIZE_ANY_EXHDR(bsonDocument);
173 size_t hexEncodedSize = binarySize * 2;
174 size_t hexStringSize = hexEncodedSize + 1 + BsonHexPrefixLength; /* add \0 and prefix "BSONHEX"; */
175 char *hexString = palloc(hexStringSize);
176
177 memcpy(hexString, BsonHexPrefix, BsonHexPrefixLength);
178
179 const char *pgbsonData = VARDATA_ANY(bsonDocument);
180
181 uint64 hexStringActualSize = hex_encode(pgbsonData, binarySize,
182 &hexString[BsonHexPrefixLength]);
183 Assert(hexStringActualSize == hexEncodedSize);
184
185 hexString[hexStringActualSize + BsonHexPrefixLength] = 0;
186 return hexString;
187}
188
189
190/*

Callers 15

bson_outFunction · 0.85
bson_to_bson_hexFunction · 0.85
ConstructDropCommandCstrFunction · 0.85
create_roleFunction · 0.85
drop_roleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected