[SERVER-31771] Add binary subtype reserved for language-specific types Created: 30/Oct/17  Updated: 06/Dec/22  Resolved: 13/Aug/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: David Golden Assignee: Backlog - Storage Execution Team
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Storage Execution
Participants:

 Description   

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



 Comments   
Comment by Marcel Timmerman [ 04/Nov/17 ]

I can think of the following variable types to store of which Rat and FatRat are already mentioned; Complex, Set, Range and a few others. Besides this, a user might have its own classes e.g. Coordinate or Location. Having a document like (in perl6)
BSON::Document.new( coord => ( x => 10, y => 20))
would become something like
BSON::Document.new( coord => Coordinate.new(10,20))
This makes the document more simple because no subdocument is needed and the value would be directly available in the form the user would want it without creating the object themselves.

Generated at Thu Feb 08 04:28:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.