为什么叫BSON?

发布于 2024-09-15 21:33:09 字数 309 浏览 2 评论 0原文

那么 BSON 是 JSON 序列化的吗?

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

但为什么叫Binary Json呢?二进制代表什么?

我总是倾向于将二进制与 10101010101 联系起来。但是上面的 BSON 序列化格式并不是 101010101010 形式。

有人可以帮我解释一下这里的二进制意味着什么,以便我理解为什么它被称为二进制 JSON 吗?

So BSON is JSON serialized right?

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

But why is it called Binary Json? What does binary stands for?

I always tend to associate binary with 10101010101. But the BSON serialization format above wasn't in 101010101010 form.

Could someone explain for me what the Binary here means so I understand why it's called Binary JSON?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

失去的东西太少 2024-09-22 21:33:09

它是二进制的,而不是文本。 JSON 是人类可读的文本,而 BSON 是二进制数据(只是字节)。您可以将其写为 1001010 等,但更常见的是一次显示每个字节(因此 \x16 只是十六进制 16,即十进制字节 22)。基本上,这里的“二进制”是用来与文本数据进行比较的,并不是说它实际上是特别的基数2。

这意味着您只能在可以传输任意二进制数据的情况下使用 BSON。例如,如果您想在 XML 文档中嵌入 BSON(无论出于何种原因!),您必须首先对其进行 Base64 编码,因为 XML 是基于文本的表示形式。

It's binary as opposed to text. Whereas JSON is human-readable text, BSON is binary data (just bytes). You could write it out as 1001010 etc, but it's more common to show each byte at a time (so \x16 is just hex 16, i.e. the decimal byte 22). Basically "binary" here is used to compare it with textual data, not to say that it's actually base 2 in particular.

This means that you can only use BSON in situations where you can transport arbitrary binary data. For example, if you wanted to embed BSON in an XML document (for whatever reason!) you'd have to base64 encode it first, because XML is a text-based representation.

残龙傲雪 2024-09-22 21:33:09

二进制实际上是一个用词不当,因为计算机上的所有内容在某种程度上都是“二进制”的。当涉及文件或网络流格式时,二进制意味着人类不容易理解。它也趋于紧凑。

文本或“人类可读”(人类可理解)文件和流格式的示例:

“二进制”文件和流格式的示例:

这里最值得注意的是人类可理解的格式需要很多如果你只是打开它们并开始阅读,那么解释就更少了。二进制文件格式可能需要整本书来解释:)

不过,格式不一定是纯粹的“二进制”或纯粹人类可以理解的。例如,您可能会理解一系列不带空格的个位数,它们代表一个个位数的数组。您可能无法理解一系列 48 个数字(没有空格),它们代表 16 个 3d 顶点的 x、y 和 z 值,即使您可以“读取”它们。此外,还有 Skeet 的编码“二进制”数据的示例,特别是如果它以更容易理解的格式嵌入的话。

Binary is really a misnomer, since everything on your computer is "binary" at some level. Binary, when it comes to file or network stream formats, means not-easily-human-understandable. It also tends to be compact.

Examples of textual or "human readable" (human understandable) file and stream formats:

Examples of "binary" file and stream formats:

The thing of most note here is that human understandable formats need a lot less explanation if you simply crack them open and start reading. Binary file formats might need whole books to explain :)

A format isn't necessarily purely "binary" or purely human understandable, though. For example, you could probably understand a series of single digit numbers with no spaces, which represent an array of single digit numbers. You probably couldn't understand a series of 48 numbers (with no spaces), which represent x, y, and z values for 16 3d vertices, even though you can "read" them. Also, there is Skeet's example of encoded "binary" data, especially if it is embedded in a more human understandable format.

青瓷清茶倾城歌 2024-09-22 21:33:09

它被称为“二进制”的原因已经解释过:基本上,它不是文本的,因此有 unix 风格的区别(二进制文件与文本文件)。

但 JSON 部分也很奇怪,因为 BSON 不是 JSON——它既不是子集也不是超集。它有更多的数据类型,所以它是一种超集;但由于属性名称和字符串值长度限制等限制,它也不支持所有合法的 JSON。

The reason it is called 'binary' is explained already: basically, it is not textual, hence unix-style distinction (binary vs text files).

But JSON part is odd as well, since BSON is NOT JSON -- it's neither subset nor superset. It has many more datatypes, so it is sort of superset; but it also does not support all legal JSON because of limitations on things like property name and string value length limitations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文