Gotta love Erlang

Posted by: Roger

Gotta love Erlang - 19/12/2015 20:47

Parsing the empeg's "/empeg/var/database3" file:

Code:
dump_database(_Tags, <<>>) ->
    % end of database
    ok;
dump_database(Tags, <<Index:8, Rest/binary>>) when Index =:= 16#FF ->
    % end of record
    io:format("-------\n"),
    dump_database(Tags, Rest);
dump_database(Tags, <<Index:8, Length:8, Data:Length/binary, Rest/binary>>) ->
    Tag = array:get(Index, Tags),
    io:format("~B (~s) = ~p (~B)\n", [Index, Tag, Data, Length]),
    dump_database(Tags, Rest).
Posted by: tfabris

Re: Gotta love Erlang - 20/12/2015 00:39

Partial credit to the guys who designed the database in such a way that it was that simple to parse. smile
Posted by: Roger

Re: Gotta love Erlang - 26/03/2016 20:18

I'll probably never get around to finishing it, but: https://github.com/rlipscombe/eplode