Question

I have a candidate key (mongodb candidate key, __id) thats looks like the following in protocol buffers :

message qrs_signature
{
  required uint32    region_id = 1;
  repeated fixed32 urls = 2;
};

Naturally I can't use a protocol buffers encoded string (via ParseToString(std::string)) in my bson document since it can contain non-printing characters. Therefore, I am using the ascii85 encoding to encode the data (using this library). I have two questions.

  1. Is b85 encoding bson-safe.
  2. What is bson's binary type for ? is there some way that I can implant my (binary) string into that field using a mongodb API call , or is it just syntactic sugar to denote a value-type that needs to be processed in some form (--i.e., not a native mongodb entity)?

edit

The append binary api's show's data being encoded as hex(OMG!), base85 is therefore more space efficient (22 bytes per record in my case).

Was it helpful?

Solution

  1. BSON safe, yes. The output of ASCII85 encoding is also valid utf-8 iirc.
  2. It's used to store chunks of binary data. Binary data is an officially supported type and you should be able to push binary values to BSON fields using the appropriate driver code, BSONObj in your case. Refer to your driver docs or the source code for details.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top