Decode binaries in C linked-in driver
Cosmin Gheorghita
cosminidis@REDACTED
Sat Jul 31 02:37:01 CEST 2004
Hello to everyone.
I have the following problem with Erlang: I need to read a file that contains integers
from Erlang and send it to a linked-in driver written in VC++. Here is my code:
Erlang:
F = "fis.txt",
case file:open(F, [read, raw, binary]) of
{ok, FHandler} ->
io:format("The file ~p was successfully opened ~n", [FHandler]),
case file:read_file(F) of
{ok, Bin} ->
io:format("~nBin file read:~n ~w~n", [floating(Bin)]),
call_port({testF, Bin}),
io:format("~nBin file ok~n");
{error, Reason} ->
io:format("~nBig error while reading the file: ~p~n", [Reason])
end.
The data is sent by: Port ! {self(), {command, encode(Msg)}},
and encode() looks like this: encode({testF, LBin}) -> [4, LBin].
Now on the C part, the code is as follows:
} else if (fn == 4) {
index = 0;
f_temp = fopen("fis_temp.txt", "wt");
fprintf(f_temp, "%d\n", bufflen);
ei_get_type(buff, &index, &type, &size);
fprintf(f_temp, "%d - %d\n", type, size);
ei_decode_binary(buff, &index, (void*) dec_buff, &bufflen);
for(i = 0;i < bufflen;i++) {
fprintf(f_temp, "%d\n", dec_buff[i]);
}
fclose(f_temp);
The dec_buff[] array is all full of 0's (I allocated mem with calloc())... Reading
directly from buff[] doesn't work either..
All I want for the beginning is to read a file from Erlang and be able to write it back
using fprinf(f, %d%, ...). So I want to decode the binaries into integers. Any idea on
this?
Thank you in advance,
Cosmin
P.S. I am a total beginner in Erlang, so pls be as explicit as possible
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
More information about the erlang-questions
mailing list