[erlang-questions] C data encoding/decoding

Serge Aleynikov <>
Mon Sep 11 14:53:06 CEST 2006


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:
> Hi
> 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.
> Thanks
> Bob
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list