-
Type: New Feature
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
None
-
Storage Execution
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
lang_tag := 0x01 C | 0x02 C++ | 0x03 C# | 0x04 Go | 0x05 Java | 0x06 Node.js | 0x07 Perl 5 | 0x08 PHP | 0x09 Python | 0x0A Ruby | 0x0B Scala | 0x0C Perl 6
- Add additional language tags over time by request, if any
Usage example:
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:
1f00000005610012000000060c010100000000000000030000000000000000
Broken up for visibility, those parts are:
1f000000 05 "a"00 12000000 06 0C 0101000000000000000300000000000000 00 length type key datalength subtype lang lang-specific-payload term