[erlang-questions] segments of variable length
Richard Andrews
bbmaj7@REDACTED
Sat Apr 4 12:52:13 CEST 2009
> -module(aa).
> -define(X,<<131,107,0,18,36,65,86,82,77,67,44,49,50,51,52,44,49,53,49,55,51,54>>).
> -export([start/0]).
>
> start()->
> case binary_to_term(?X) of
> {<>}->
> io:format("Header = ~s~n",[H]),
> io:format("Unit ID = ~s~n",[U]),
> io:format("Time = ~s~n",[T])
> end.
>
> This gives me an error.
> I was waiting for
> Header = $AVRMC
> Unit ID = 1234
> Time = 151736
As a first experiment I would suggest something like the following
(have not tested that this compiles)
%% Simulate sending side
X = term_to_binary( {myTag, H, U, T} ),
%% Receiving side
case binary_to_term(X) of
{myTag, H, U, T} ->
process_myTag( H, U, T );
_ -> error
end.
Enjoy a better web experience. Upgrade to the new Internet Explorer 8 optimised for Yahoo!7. Get it now.
More information about the erlang-questions
mailing list