BSON

littledata 1,704 views 17 slides Jan 13, 2013
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

No description available for this slideshow.


Slide Content

BSON The Little Data Project littledataproject.org

BSON BSON is a serialization format.

Binary JSON JSON documents are human-readable. Like this : { “spoiled” : true }

speed But human-readable code cannot be traversed as quickly as binary code can be. Speed is important in a database containing millions of records.

BSON is binary JSON BSON is a JSON that has been serialized as a binary document.

parts of a BSON file A BSON document consists of three parts: int32 e_list “ \x00”

int32 The int32 is a 32-bit integer representing the size of the document. For instance, this document consists of 13000 bytes. In BSON encoding this becomes: \x13\x00\x00\x00

e_list The e_list is a sequence or list of elements. In our example, there is only one element. The element type is declared first, followed by an e_name , and a trailing digit: “\x08” e_name “\x00”

“\x08” e_name “\x00 ” \x08 tells us that the data type is Boolean (true/false).

“\x08” e_name “\x00 ” The e_name is the key name in a key-value pair. The word (or ‘value’) “s - p - o - i - l - e- d” would be represented in a byte array as a series of UTF-8 symbols: { 115,112,111,105,108,101,100 }

“\x08” e_name “\x00 ” But in BSON a “string” is expressed as the symbol for a UTF-8 string + value + trailing ‘0’: \x02spoiled\x00

“\x08” e_name “\x00 ” This is followed, in our example, with the Boolean symbol ‘1’ for ‘true’ or ‘0’ for ‘false’: \x01 The BSON document is closed out with a trailing integer ‘0’: \x00

“\x13\x00\x00\x00\x08\x02spoiled\x00\x01\x00”

in binary, \x02 i s 00000010 W e said that BSON is a binary correlate of JSON . The whole point of serialization with BSON is to “deflate” code into a generic, low-level state.

1 ’s & 0’s A ‘ serializer ’ program would take the BSON code we generated and convert it to binary. 01101000 00000000 00000000 0000000 00100010 100010000 011010010 00010011 01101010 10100100 11100101 0100100 10001000 01110011 10001000 10000100 11110000 10010111 10010010 0001000 10011111 01010101 00011100 11100011 10000010 11111000 11001001 11001010 11110000 10101010 10001111 01010101

01101000 00000000 00000000 0000000 00100010 100010000 011010010 00010011 01101010 10100100 11100101 0100100 10001000 01110011 10001000 10000100 11110000 10010111 10010010 0001000 10011111 01010101 00011100 11100011 10000010 11111000 11001001 11001010 11110000 10101010 10001111 01010101 01101000 00000000 00000000 0000000 00100010 100010000 011010010 00010011 01101010 10100100 11100101 0100100 10001000 01110011 10001000 10000100 11110000 10010111 10010010 0001000 10011111 01010101 00011100 11100011 10000010 11111000 11001001 11001010 11110000 10101010 10001111 01010101 110110

The Little Data Project http:// littledataproject.org