二进制解析器还是序列化?
我想存储游戏中不同对象的图表,它们的类可能相关也可能不相关,它们可能包含也可能不包含简单结构的向量。
- 我希望解析操作能够很快,数据可以很大。
- 添加新东西不应该很困难,也不应该破坏向后兼容性。
- 较小的文件大小很重要
- 可读性计数
我的意思是,使对象序列化自己,这是有效的,但我需要为此为不同的对象编写不同的序列化方法。
通过二进制解析/组合,我的意思是,创建一个新的解析器/组合器树来保存和读取这些对象的数据,并将其传递给我的对象推/拉它们的数据。
我也可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
逐点:
因此,文本为三票,二进制为一票。就我个人而言,除了图像(以及“自然”二进制的其他数据)之外,我会使用文本来表示所有内容。然后,将所有内容存储在一个大的 zip 文件中(我可以想到有几个游戏会这样做或类似的事情)。
好读物:文本化的重要性和纯文本的力量。
Point by point:
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.
查看 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.
我们正在使用 Boost.Serialization。不知道它与 samkass 提供的产品相比表现如何。
We're using Boost.Serialization. Don't know how it performs next to those offered by samkass.