Skip to content

Commit

Permalink
Add message module
Browse files Browse the repository at this point in the history
  • Loading branch information
meeusr committed Aug 16, 2012
1 parent 7c69b67 commit 487e195
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions message.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-module(message).
-export([parse/1,compose/3,roundtrip/1]).

parse(Data) when is_list(Data) ->
[D1,D2,D3,D4,D5] = string:tokens(Data, " ,{}"),
{list_to_integer(D1),list_to_integer(D2),{list_to_integer(D3),list_to_integer(D4),list_to_integer(D5)}}.

compose(Idx1,Idx2,TS) when is_integer(Idx1),is_integer(Idx2), is_tuple(TS) ->
lists:flatten(io_lib:format("~w ~w ~w",[Idx1,Idx2,TS])).

roundtrip({_,_,TS} = Message) ->
timer:now_diff(erlang:now(),TS).

0 comments on commit 487e195

Please sign in to comment.