Based on this mongodb-dev thread, it would help driver implementers to reserve a BSON binary subtype for language-specific types, along with reserving the first byte of the binary payload of that subtype to indicate a specific language. We would also add a language registry to the BSON spec.
For example, if the Perl 6 driver wants to store a Rat type (rational with separate numerator and denominator), it could do so by using the language-specific subtype, a registry-assigned byte for "Perl 6" and a Perl 6 driver defined type byte to identify the Rat type and then 16 bytes of data (2 unint64s).
Specific proposal for changes to the BSON Spec:
- Add binary subtype "0x06" to be "language-specific arbitrary type (binary_lang_type)".
- Define language specific type as: binary_lang_type := lang_tag (byte*)
- Define lang_tag as
- Add additional language tags over time by request, if any
For example, if Perl 6 wanted to use the first byte to determine the type, it could choose 0x01 for the Rat type. Then BSON::Document.new("a" => (1/3)) could be encoded as:
Broken up for visibility, those parts are: