[erlang-questions] C data encoding/decoding
Mon Sep 11 15:20:51 CEST 2006
Thanks, that looks useful. I can see a little study will be required here.
From: Serge Aleynikov [mailto:]
Sent: 11 September 2006 13:53
To: Bob Cowdery
Cc: Erlang Users' List
Subject: Re: [erlang-questions] C data encoding/decoding
You can look here for an example of how to use EI for marshaling terms:
As far as the guidelines on how to represent C structs, you can declare
records on the Erlang side, and encode C structs as tuples. Though to
the best of my knowledge, there's no single recommendation on how to
deal with complex structures, and you'll have to figure out the most
suitable representation that fits your case.
Bob Cowdery wrote:
> Having got a C Port client and server working I am now moving that into the real application. Now comes the question of sending and receiving real messages between C Nodes.
> The data that forms the interface between these two nodes is C structs. Some of these structs are arrays or may contain arrays of structs or other simple types. One particular struct also has unions in it.
> I started out just using erl_format() which got me so far. I really only found it suitable for simple parameters and fixed structures. I then read the Erlang Interface document. From this it definitely seems I should be using the ei module. The external format looks like its much more adept at dealing with dynamic data. It is quite a difficult read though and there arn't any examples. Before I write too much codeI want to be sure this is the right approach so a few questions to anyone kind enough to give guidence.
> 1. Is the ei module the right one to use for reasonably complex dynamic data or am I not getting the full milage out of erl_format().
> 2. If I use the external format is that suitable for digestion by a pure Erlang node as I don't expect at least one end of this interface to stay in C.
> 3. I can see an ei_send() takes a message in binary format (i'm assuming this is the same as external format). However, the receive functions don't explicitly say what they expect. I assume ei_receive accepts a message in binary format.
> 4. I could really do with an example of packing and unpacking say an array of structs to/from binary format. Can anyone point me to such an example.
> All help appreciated.
> erlang-questions mailing list
More information about the erlang-questions