* Converts a pgbson to a hexadecimal string representation. */
| 167 | * Converts a pgbson to a hexadecimal string representation. |
| 168 | */ |
| 169 | const char * |
| 170 | PgbsonToHexadecimalString(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 | /* |
no outgoing calls
no test coverage detected