What's the best way to serialize data in a lan

2019-01-13 22:01发布

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?

10条回答
Explosion°爆炸
2楼-- · 2019-01-13 22:26

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.

查看更多
够拽才男人
3楼-- · 2019-01-13 22:34

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.

查看更多
我只想做你的唯一
4楼-- · 2019-01-13 22:34

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.

查看更多
Animai°情兽
5楼-- · 2019-01-13 22:37

Another option is SNAC/TLV which is used by AOL in it's Oscar/AIM protocol.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-13 22:40

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!

查看更多
▲ chillily
7楼-- · 2019-01-13 22:44

Also check out Muscle. While it does quite a bit, it serializes to a binary format.

查看更多
登录 后发表回答