Binary text encoding, non-printable characters, protocol buffers, mongodb and bson

I have a candidate key (mongodb candidate key, __id) that looks like this in protocol buffers:

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

Naturally, I cannot use the encoded protocol buffer string (via ParseToString(std::string)) in my bson document, as it may contain non-printable characters. Therefore, I use ascii85 encoding to encode data (using this library ). I have two questions.

  • Is b85 an encoding of bson-safe.
  • What is bson binary type for ? Is there a way that I can embed my (binary) string into this field using the mongodb API call, or is it just syntactic sugar to indicate the type of value that needs to be processed in some form (-ie, and not the native mongodb)?

change

The append binaryshow api data is encoded as hex (OMG!), So base 85 is more economical (22 bytes per record in my case).

+5
source share
1 answer
  • BSON is safe, yes. ASCII85 encoding output is also valid utf-8 iirc.
  • . , BSON , BSONObj . . .
+4

All Articles