Bson

http://en.wikipedia.org/wiki/BSON
 
From Wikipedia, the free encyclopedia
 
 
BSON
Filename extension.bson
Internet media typenone[1]
Type of formatData interchange
Extended fromJSON
Standard(s)no RFC yet
Websitebsonspec.org

BSON (play /ˈbsɒn/) is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structuresand associative arrays (called objects or documents in MongoDB). The name "BSON" is based on the term JSON and stands for "Binary JSON".[2]

Contents

   [hide

[edit]Data types and syntax

BSON documents (objects) consist of an ordered list of elements. Each element consists of a field name, a type, and a value. Field names are strings. Types include:

BSON types are nominally a superset of JSON types (JSON does not have a date or a byte array type, for example[3]), with one exception of not having a universal "number" type as JSON does.

[edit]Efficiency

Compared to JSON, BSON is designed to be efficient both in storage space and scan-speed. Large elements in a BSON document are prefixed with a length field to facilitate scanning. In some cases, BSON will use more space than JSON due to the length prefixes and explicit array indices.[2]

[edit]See also

[edit]References

[edit]External links

View page ratings
Rate this page
 
Trustworthy
 
 
 
Objective
 
 
 
Complete
 
 
 
Well-written
 
 
 
 
I am highly knowledgeable about this topic (optional)
 
Submit ratings
 
 
 
 
 
 
 
 
 
 
 

BSON

}
01010100
11101011
10101110
01010101
{

Version 1.0

BSON is a binary format in which zero or more key/value pairs are stored as a single entity. We call this entity a document.

The following grammar specifies version 1.0 of the BSON standard. We've written the grammar using a pseudo-BNF syntax. Valid BSON data is represented by the document non-terminal.

Basic Types

The following basic types are used as terminals in the rest of the grammar. Each type must be serialized in little-endian format.

byte1 byte (8-bits)
int324 bytes (32-bit signed integer)
int648 bytes (64-bit signed integer)
double8 bytes (64-bit IEEE 754 floating point)

Non-terminals

The following specifies the rest of the BSON grammar. Note that quoted strings represent terminals, and should be interpreted with C semantics (e.g. "\x01" represents the byte0000 0001). Also note that we use the * operator as shorthand for repetition (e.g.("\x01"*2) is "\x01\x01"). When used as a unary operator, * means that the repetition can occur 0 or more times.

document::=int32 e_list "\x00"BSON Document
e_list::=element e_listSequence of elements
 |"" 
element::="\x01" e_name doubleFloating point
 |"\x02" e_name stringUTF-8 string
 |"\x03" e_name documentEmbedded document
 |"\x04" e_name documentArray
 |"\x05" e_name binaryBinary data
 |"\x06" e_nameUndefined — Deprecated
 |"\x07" e_name (byte*12)ObjectId
 |"\x08" e_name "\x00"Boolean "false"
 |"\x08" e_name "\x01"Boolean "true"
 |"\x09" e_name int64UTC datetime
 |"\x0A" e_nameNull value
 |"\x0B" e_name cstring cstringRegular expression
 |"\x0C" e_name string (byte*12)DBPointer — Deprecated
 |"\x0D" e_name stringJavaScript code
 |"\x0E" e_name stringSymbol — Deprecated
 |"\x0F" e_name code_w_sJavaScript code w/ scope
 |"\x10" e_name int3232-bit Integer
 |"\x11" e_name int64Timestamp
 |"\x12" e_name int6464-bit integer
 |"\xFF" e_nameMin key
 |"\x7F" e_nameMax key
e_name::=cstringKey name
string::=int32 (byte*) "\x00"String
cstring::=(byte*) "\x00"CString
binary::=int32 subtype (byte*)Binary
subtype::="\x00"Binary / Generic
 |"\x01"Function
 |"\x02"Binary (Old)
 |"\x03"UUID (Old)
 |"\x04"UUID
 |"\x05"MD5
 |"\x80"User defined
code_w_s::=int32 string documentCode w/ scope

Examples

The following are some example documents (in JavaScript / Python style syntax) and their corresponding BSON representations. Try mousing over them for some useful correlation.

{"hello""world"}"\x16\x00\x00\x00\x02hello\x00 
 \x06\x00\x00\x00world\x00\x00"
{"BSON"["awesome"5.05,1986]}"\x31\x00\x00\x00\x04BSON\x00\x26\x00 
 \x00\x00
\x020\x00\x08\x00\x00 
 \x00awesome\x00
\x011\x00\x33\x33\x33\x33\x33\x33
 \x14\x40
\x102\x00\xc2\x07\x00\x00 
 \x00\x00"
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值