Convert C types to Erlang types

Bengt Kleberg eleberg@REDACTED
Mon Dec 9 10:28:30 CET 2002


> Paroli, Bernardo writes:
>  > I'm make a server socket in Erlang and I send message from C
>  > client. The C client send the next message:
>  > 
>  > typedef struct
>  > {
>  > 	int first;
>  > 	char second;
>  > } Message;
>  > 
>  > char buf[1024];
>  > Message*p;
>  > p = (Message*) buf;
>  > 
>  > p->first   = 1567;
>  > p->second = 's';
>  > 
>  > send(s, buf, sizeof(Message), 0);
>  > 
>  > In the Erlang server I'm receive the next binary message:
>  > <<31,6,0,0,115,255,255,255>>
>  > 
>  > I need convernt this structure to the corresponding C structure. 
>  > Exist in Erlang something function to make this conversion?

a practice suggested by the plan9 developpers is to always use ascii
for this kind of transfer. send the numbers as text. parse the text to
numbers on the erlang side.
see http://plan9.bell-labs.com/sys/doc/index.html for all plan9
documentation.
example quoute:
''To avoid byte order problems, data is communicated between programs
as text whenever practical.''


bengt




More information about the erlang-questions mailing list