设计(二进制)文件格式时有什么要点? [英] What are important points when designing a (binary) file format?

查看:142
本文介绍了设计(二进制)文件格式时有什么要点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计用于记录的二进制数据的文件格式,有什么属性,你会觉得格式应该有哪些?到目前为止,我已经提出了以下要点:

When designing a file format for recording binary data, what attributes would you think the format should have? So far, I've come up with the following important points:


  • 有一些神奇字节开头,要能够识别文件(在我的特殊情况,这应该也有助于区分遗产文件中的文件)

  • 有开头的文件版本号,以使文件格式可以在以后不会破坏兼容性来改变

  • 指定所有数据项的字节序和大小;或:包括一些空间来描述数据的字节顺序/大小(我倾向于前者)

  • 可能保留一些空间,可能会在未来有必要进一步每个文件属性?

还有什么会使得格式的面向未来的,并尽量减少在未来的头痛是有用的?

What else would be useful to make the format more future-proof and minimize headache in the future?

推荐答案

看看在 PNG规范。这种格式背后都有一些很好的理由。

Take a look at the PNG spec. This format has some very good rationale behind it.

此外,决定什么是对你的未来格式重要:紧凑性,兼容性,允许嵌入里面其他格式(不同的COM pression算法)。另一个有趣的例子是谷歌的协议缓冲区中的大小在哪里传输的数据为王。

Also, decide what's important for your future format: compactness, compatibility, allowing to embed other formats (different compression algorithms) inside it. Another interesting example would be the Google's protocol buffers, where size of the transferred data is the king.

至于字节顺序,我建议你选择一个选项,并坚持下去,不容许不同的字节顺序。否则,阅读和写作库只会变得更加复杂和缓慢。

As for endianness, I'd suggest you to pick one option and stick with it, not allowing different byte orders. Otherwise, reading and writing libraries will only get more complex and slower.

这篇关于设计(二进制)文件格式时有什么要点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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