New binary subtype / Default subtype change

134 views
Skip to first unread message

Michael Dirolf

unread,
Jun 16, 2010, 11:35:10 AM6/16/10
to bs...@googlegroups.com
Several implementors have pointed out that the default subtype for
binary, 0x02, has an unnecessary extra length specifier. This was a
historical accident, and as a fix we have added a new generic binary
subtype, 0x00. This addition *doesn't require* changes to any current
BSON implementation, but we recommend that implementors transition to
using subtype 0x00 as the default for binary data. All implementations
should continue to support subtype 0x02 as well, since it is in wide
use for existing BSON data.

This isn't a spec revision, as it should be a completely non-breaking
change. That said, the specification has been updated with the new
subtype:
http://bsonspec.org/#/specification

Feel free to follow up with any comments or questions.

- Mike

Sascha Matzke

unread,
Jun 16, 2010, 5:19:55 PM6/16/10
to bs...@googlegroups.com
Hi,

maybe it's because English isn't my native language, but I don't understand why 0x02 had an unnecessary length specifier.

In my implementation (Mongodb driver for Factor) 0x02 has the format:

<length of binary data>0x02<binary data>

Is this wrong? If not... Where's the unnecessary length specifier?

Sascha
-- 
Through the darkness of future past
the magician longs to see
One chants out between two worlds
Fire walk with me.

Michael Dirolf

unread,
Jun 16, 2010, 5:27:35 PM6/16/10
to bs...@googlegroups.com
Yeah I don't think your implementation for subtype 2 is quite right -
be sure to read the hover text carefully on the spec page (or compare
output w/ a known good driver). To store "ab" as subtype 2 we'd end up
with something like:

\x06\x00\x00\x00 (binary length) 0x02 (subtype) \x02\x00\x00\x00
(inner length - "extra") ab (data)

Sascha Matzke

unread,
Jun 17, 2010, 12:31:55 AM6/17/10
to bs...@googlegroups.com
Hi,

On Wed, Jun 16, 2010 at 23:27, Michael Dirolf <mi...@10gen.com> wrote:
\x06\x00\x00\x00 (binary length) 0x02 (subtype) \x02\x00\x00\x00
(inner length - "extra") ab (data)

Okay... That length is definitely unnecessary ;-) You're right... My existing implementation is wrong at this point. I'll fix it.

Sascha
-- 
Reply all
Reply to author
Forward
0 new messages