二进制解析器还是序列化?

发布于 2024-09-15 16:34:58 字数 355 浏览 4 评论 0原文

我想存储游戏中不同对象的图表,它们的类可能相关也可能不相关,它们可能包含也可能不包含简单结构的向量。

  • 我希望解析操作能够很快,数据可以很大。
  • 添加新东西不应该很困难,也不应该破坏向后兼容性。
  • 较小的文件大小很重要
  • 可读性计数

我的意思是,使对象序列化自己,这是有效的,但我需要为此为不同的对象编写不同的序列化方法。

通过二进制解析/组合,我的意思是,创建一个新的解析器/组合器树来保存和读取这些对象的数据,并将其传递给我的对象推/拉它们的数据。

我也可以使用 json,但它的读取速度可能相当慢,而且当涉及相当大的矩阵和数字集时,它的大小效果不是很好。

I want to store a graph of different objects for a game, their classes may or may not be related, they may or may not contain vectors of simple structures.

  • I want parsing operation to be fast, data can be pretty big.
  • Adding new things should not be hard, and it should not break backward compatibility.
  • Smaller file size is kind of important
  • Readability counts

By serialization I mean, making objects serialize themselves, which is effective, but I will need to write different serialization methods for different objects for that.

By binary parsing/composing I mean, creating a new tree of parsers/composers that holds and reads data for these objects, and passing this around to have my objects push/pull their data.

I can also use json, but it can be pretty slow for reading, and it is not very size effective when it comes to pretty big sets of matrices, and numbers.

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

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

发布评论

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

评论(3

往事随风而去 2024-09-22 16:34:58

逐点:

  • 快速解析:二进制(因为你不一定要“解析”,你可以反序列化)
  • 添加新东西:文本
  • 较小:文本(即使gzipped文本比二进制大,它也不会太多 )更大)。
  • 可读性:文本

因此,文本为三票,二进制为一票。就我个人而言,除了图像(以及“自然”二进制的其他数据)之外,我会使用文本来表示所有内容。然后,将所有内容存储在一个大的 zip 文件中(我可以想到有几个游戏会这样做或类似的事情)。

好读物:文本化的重要性纯文本的力量

Point by point:

  • Fast Parsing: binary (since you don't necessarily have to "parse", you can just deserialize)
  • Adding New Things: text
  • Smaller: text (even if gzipped text is larger than binary, it won't be much larger).
  • Readability: text

So that's three votes for text, one point for binary. Personally, I'd go with text for everything except images (and other data which is "naturally" binary). Then, store everything in a big zip file (I can think of several games do this or something close to it).

Good reads: The Importance of Being Textual and Power Of Plain Text.

阳光的暖冬 2024-09-22 16:34:58

查看 Google 的协议缓冲区或 Apache 的 thrift。虽然它被宣传为一种轻松编写有线协议的方法,但它基本上是一种对象序列化机制,可以用多种语言创建绑定,具有高效的二进制表示、简单的版本控制、快速的性能,并且得到良好的支持。

Check out protocol buffers from Google or thrift from Apache. Although billed as a way to write wire protocols easily, it's basically an object serialization mechanism that can create bindings in a dozen languages, has efficient binary representation, easy versioning, fast performance, and is well-supported.

美人如玉 2024-09-22 16:34:58

我们正在使用 Boost.Serialization。不知道它与 samkass 提供的产品相比表现如何。

We're using Boost.Serialization. Don't know how it performs next to those offered by samkass.

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