We want to pass a forest - a dictionary with values which can be: dictionaries, arrays, sets, numbers, strings, byte buffers - between Objective C and C# efficiently (time-wise, space is a lesser concern). Google's Protocol Buffers looked good, but they seem to handle only structured data, while ours is arbitrary. Ultimately we can write a binary (de)serialiser ourselves, but surely this was done before and released as FOSS somewhere?
Asked
Active
Viewed 378 times
2
-
Why binary? Otherwise JSON would be the obvious choice. If you need to transmit large amounts over a bandwidth constrained medium: JSON and then compress. – Richard Sep 04 '13 at 07:54
-
1With "tagged union" messages (a message with an enum value saying what kind of value it is, then one field for each of those kinds) Protocol Buffers can represent data pretty flexibly. – Jon Skeet Sep 04 '13 at 07:54
-
@JonSkeet it wouldn't even need to be tagged, thinking about it - just check which one has values. Of course, it also wouldn't be a true `union` in the normal sense... – Marc Gravell Sep 04 '13 at 07:58
-
@Richard, string manipulation can be slow, especially when handling byte buffers (we don't want to start messing with base64). – Vladimir Gritsenko Sep 04 '13 at 08:01
-
@JonSkeet, interesting, I'll take a second look. – Vladimir Gritsenko Sep 04 '13 at 08:01
-
ASN.1 has a few good binary serialisers (most people use BER). The C# side is not a problem, however the Obj-C side may have to use C or C++ objects (i don't know Obj-C, don't know if that's possible). The tools from Objective Systems are pretty good but not free – bazza Sep 05 '13 at 04:58
-
@JonSkeet, it still seems to miss our requirement - we have an existing platform data type (e.g., NSDictionary) we'd like to serialise, while protobuf will output its own classes. – Vladimir Gritsenko Sep 08 '13 at 09:29
-
@MarcGravell: It wouldn't *have* to be tagged, but in my experience it's significantly easier to worked with a tagged version :) – Jon Skeet Sep 08 '13 at 11:17
-
@VladimirGritsenko: You'd have to convert from `NSDictionary` to a Protocol Buffers message, yes. But doing that is likely to be much simpler than inventing your own binary serialization protocol. – Jon Skeet Sep 08 '13 at 11:17
1 Answers
0
Have you considered using ASN.1? Since ASN.1 is independent of programing language or system architecture, it can be used efficiently regardless of whether you need C, C#, C++, or Java.
You create a description of the information you wish to exchange, and the use an ASN.1 tool to generate an encoder/decoder for your target programming language. ASN.1 also supports a few different rules for transmitting the date which range from the efficient PER (Packed Encoding Rules) to the verbose, but flexible XER (XML Encoding Rules).
To play with ASN.1 to see if this might work for you, try the free online ASN.1 compiler and encoder/decoder at http://asn1-playground.oss.com to see if this might work for you.

Paul Thorpe
- 1,930
- 17
- 23
-
This looks interesting, but Google's Protocol Buffers looks more accessible, in terms of learning curve and tools. – Vladimir Gritsenko Sep 08 '13 at 08:02
-
1Take a look at "ASN.1 Made Simple" at http://www.oss.com/asn1/resources/asn1-made-simple/introduction.html and you will see that ASN.1 may actually be easier to write than Google Protocol Buffers. – Paul Thorpe Sep 09 '13 at 18:56