What's the best way to serialize data in a language-independent binary format?

孤街浪徒 提交于 2019-11-27 19:50:41

Given your requirements, I would go with Google Protocol Buffers. It sounds like it's ideally suited to your application.

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.

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 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 is a binary format created by Facebook. Here's a comparison with google protocol buffers.

Check out Hessian

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.

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.

Few Thing's you need to Consider

1. Storage
2. Encoding Style (1 byte 2 byte)
3. TLV standards

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!