以与语言无关的二进制格式序列化数据的最佳方法是什么?
我正在研究一种以与语言无关的机制序列化数据通过套接字或共享内存传递的机制。 我不愿意使用 XML,因为这些数据将非常结构化,并且编码/解码速度至关重要。 拥有一个良好的、自由许可的 C API 很重要,但理想情况下应该支持大量其他语言。 我查看了 google 的协议缓冲区和ASN.1。 我走在正确的轨道上吗? 还有更好的吗? 我应该只实现我自己的打包结构而不是寻找一些标准吗?
I'm looking into a mechanism for serialize data to be passed over a socket or shared-memory in a language-independent mechanism. I'm reluctant to use XML since this data is going to be very structured, and encoding/decoding speed is vital. Having a good C API that's liberally licensed is important, but ideally there should be support for a ton of other languages. I've looked at google's protocol buffers and ASN.1. Am I on the right track? Is there something better? Should I just implement my own packed structure and not look for some standard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
鉴于您的要求,我会选择 Google Protocol Buffers。 听起来它非常适合您的应用程序。
Given your requirements, I would go with Google Protocol Buffers. It sounds like it's ideally suited to your application.
你可以考虑XDR。 它有一个 RFC。 我已经使用过它并且从未遇到过任何性能问题。 它被用在 ONC RPC 中,并且有一个名为 rpcgen 的工具。 当您只想序列化数据时,自己创建一个生成器也很容易(这就是我出于可移植性原因最终所做的,花了我半天时间)。
有一个开源 C 实现,但它已经存在于系统库中,因此您不需要源代码。
ASN.1 对我来说总是有点巴洛克,但根据您的实际需要可能更合适,因为 XDR 有一些限制。
You could consider XDR. It has an RFC. I've used it and never had any performance problems with it. It was used in ONC RPC and has an and comes with a tool called rpcgen. It is also easy to create a generator yourself when you just want to serialize data (which is what I ended up doing for portability reasons, took me half a day).
There is an open source C implementation, but it can already be in a system library, so you wouldn't need the sources.
ASN.1 always seemed a bit baroque to me, but depending on your actual needs might be more appropriate, since there are some limitations to XDR.
只是想将 ASN.1 加入到这个组合中。 ASN.1 是一种格式标准,但大多数语言都有库,并且通过 asn1c 的 C 接口非常有用比协议缓冲区的 C 接口更干净。
Just wanted to throw in ASN.1 into this mix. ASN.1 is a format standard, but there's libraries for most languages, and the C interface via asn1c is much cleaner than the C interface for protocol buffers.
JSON 确实是我最喜欢的这类东西。 不过,我之前对其中的二进制内容没有任何经验。 如果您计划使用 JSON,请发布您的结果!
JSON is really my favorite for this kind of stuff. I have no prior experience with binary stuff in it though. Please post your results if you are planning on using JSON!
Thrift 是 Facebook 创建的一种二进制格式。 以下是与 Google Protocol buffers 的比较。
Thrift is a binary format created by Facebook. Here's a comparison with google protocol buffers.
查看 Hessian
Check out Hessian
还有 Binary XML 但似乎还不稳定。 我链接到的文章提供了一堆可能感兴趣的链接。
There is also Binary XML but it seems not stabilized yet. The article I link to gives a bunch of links which might be of interest.
另一个选项是 SNAC/TLV,AOL 在其 Oscar/AIM 协议中使用它。
Another option is SNAC/TLV which is used by AOL in it's Oscar/AIM protocol.
另请查看肌肉。 虽然它的作用相当大,但它会序列化为二进制格式。
Also check out Muscle. While it does quite a bit, it serializes to a binary format.
您需要考虑的几件事
ASN.1 解析器非常适合二进制表示,最好的部分是 ASN.1 是一项成熟的技术,在 ITU-T 内外广泛使用。 许多软件供应商都支持该表示法。
Few Thing's you need to Consider
ASN.1 Parser is the good for binary represenations the best part is ASN.1 is a well-established technology that is widely used both within ITU-T and outside of it. The notation is supported by a number of software vendors.