我可以得到有关BSON的更多解释吗? [英] Can I get more explanations for BSON?

查看:46
本文介绍了我可以得到有关BSON的更多解释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 http://来了解 BSON bsonspec.org/#/specification ,但仍然存在一些问题。

I am trying to understand BSON via http://bsonspec.org/#/specification, but still some questions remain.

让我们举一个例子上面的网站:

let's take an example from the web site above:

{"hello": "world"} → "\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00"

问题1

在上面的示例中,对于编码后的字节结果,双引号实际上不是结果的一部分

in the above example, for the encoded bytes results, the double quotes actually are not part of the results, right?

问题2

我理解前4个字节 \x16\x00\x00\x00 是整个BSON文档的大小。

I understand that the first 4 bytes \x16\x00\x00\x00 is the size of the whole BSON doc.

它是小尾数格式。但为什么?为什么不采用 big endian

And it is little endian format. But why? Why not take big endian?

问题3

示例文档的大小如何为 \x16 ,即 22

How comes the size of the example doc being \x16, i.e. 22?

问题4

通常,如果我想自己对文档进行编码,我该如何计算文档的大小?我认为我的主要麻烦是如何确定 UTF-8 字符串的大小?

Normally, if I want to encode the doc by myself, how do I calculate the size of the doc? I think my trouble majorly is how to decide the size of UTF-8 string?

再举一个例子:

{"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"

问题5

在此示例中,有一个数组。根据规范,对于数组,它实际上是 {key,value} 对的列表,而键是 0 1 等。我的问题是 0 1 这也是字符串,对吗?

In this example, there is an array. according to the specification, for array, it is actually a list of {key, value} pairs, whereas the key is 0, 1, etc. My question is so the 0, 1 here are strings too, right?

推荐答案


问题1

Question 1

对于编码的字节结果,双引号实际上不是结果的一部分,对吧?

in the above example, for the encoded bytes results, the double quotes actually are not part of the results, right?

引号不是字符串的一部分。它们用于标记JSON字符串

The quotes are not part of the strings. They're used to mark JSON strings


问题2

Question 2

,这是小端格式。但为什么?为什么不采用大字节序?

And it is little endian format. But why? Why not take big endian?

字节序的选择主要是偏好问题。 little endian的一个优点是常用平台是little endian,因此不需要反转字节。

Choice of endianness is largely a matter of preference. One advantage of little endian is that commonly used platforms are little endian, and thus don't need to reverse the bytes.


问题3

Question 3

示例文档的大小如何为\x16,即22?

How comes the size of the example doc being \x16, i.e. 22?

有22个字节(包括长度前缀) )

There are 22 bytes (including the length prefix)


问题4

Question 4

通常,如果我想自己对文档进行编码,如何计算大小文档?我认为我的主要麻烦是如何确定UTF-8字符串的大小?

Normally, if I want to encode the doc by myself, how do I calculate the size of the doc? I think my trouble majorly is how to decide the size of UTF-8 string?

首先写出文档,然后回去填写

First write out the document, and then go back to fill in the length.


问题5

Question 5

n在此示例中,存在一个数组。根据规范,对于数组,它实际上是{key,value}对的列表,而key是0、1等。我的问题是0、1也是字符串,对吗?

n this example, there is an array. according to the specification, for array, it is actually a list of {key, value} pairs, whereas the key is 0, 1, etc. My question is so the 0, 1 here are strings too, right?

是的。零终止的字符串,没有确切的长度前缀。 (在列表中称为 cstring )。就像嵌入式文档一样。

Yes. Zero terminated strings without length prefix to be exact. (Called cstring in the list). Just like an embedded document.

这篇关于我可以得到有关BSON的更多解释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆