On 12-12-20 05:23 AM,
wrote:
> On Thursday, December 20, 2012 2:04:17 PM UTC+1, glen herrmannsfeldt wrote:
>>
>>> At first this approach was good, but now I'm finding many problems.
>>> Mostly I have to keep the two applications synchronized: if I add
>>> a parameter (maybe in the middle of the answer, because an array
>>> size is increased) or enlarge a numerical values (from 1 to 2 bytes)
>>> or something else, I have to change both applications.
>>> I usually want to have a retro-compatible master application
>>> (master should communicate well with new or older slaves
>>> application), so the code will be filled with many ifs
>>> (if the slave answer version is 1.0 than there is one parameter
>>> here, if it is 1.2 the array size is 3 and not 2...)
>>
>>> Is there a better approach to exchange data on the wire between
>>> two C applications, considering the limitations of memory,
>>> the low speed and the length of messages of a small embedded
>>> platform?
>>
>> You might look at XDR, which is meant for communication between
>> unlike devices. It may or may not do what you want, but it is
>> conveniently well standardized. (It is in a few internet RFCs.)
>
> Thank you for your suggestion. Anyway XDR seems to encode everything with a 4-bytes unit base. I have many small integer values and many bytes would be added without info.
>
> I'd like to use a more compact serialization format and simple to implement in embedded applications.
> BSON? JSON? Protocol Buffers? Other suggestions?
>
JSON has certain advantages. Since everything is text it is extensible
by interpretation. It's delimited by {} so boundaries are clear.
Interpreting fields is up to the protocol interpreter since the data
won't tell you its type, however it is reasonably easy to work out a
scheme of some sort.
e.g. {"int_array":[1,3,34,245],"string":"Hello, World","double":2.34}
It is certainly easy to come up with a more compact protocol and sane
updates to a specification are required in any case but it's easily
extensible and debugged and widely used.