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

Function PgbsonInitFromHexadecimalString

pg_documentdb_core/src/io/pgbson.c:134–163  ·  view source on GitHub ↗

* Initializes a pgbson structure from a hexadecimal String. */

Source from the content-addressed store, hash-verified

132 * Initializes a pgbson structure from a hexadecimal String.
133 */
134pgbson *
135PgbsonInitFromHexadecimalString(const char *hexadecimalString)
136{
137 uint32_t strLength = strlen(hexadecimalString);
138
139 uint32_t hexStringLength = (strLength - BsonHexPrefixLength);
140 if (hexStringLength <= 0 || (hexStringLength % 2 != 0))
141 {
142 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), errmsg(
143 "Invalid Hex string for pgbson input")));
144 }
145
146 if (strncmp(hexadecimalString, BsonHexPrefix, BsonHexPrefixLength) != 0)
147 {
148 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
149 errmsg("Bson Hex string does not have valid prefix %s",
150 BsonHexPrefix)));
151 }
152
153 uint32_t binaryLength = hexStringLength / 2;
154
155 int allocSize = binaryLength + VARHDRSZ;
156 pgbson *pgbsonVal = (pgbson *) palloc(allocSize);
157
158 uint64 actualBinarySize = hex_decode(&hexadecimalString[BsonHexPrefixLength],
159 hexStringLength, VARDATA(pgbsonVal));
160 Assert(actualBinarySize == binaryLength);
161 SET_VARSIZE(pgbsonVal, (uint32_t) actualBinarySize + VARHDRSZ);
162 return pgbsonVal;
163}
164
165
166/*

Callers 9

bson_inFunction · 0.85
bson_hex_to_bsonFunction · 0.85
AddIndexBuildsFunction · 0.85
RunQueryOnAllServerNodesFunction · 0.85
command_compactFunction · 0.85
bsonaggvalue_inFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected