Sunday, June 10, 2007

Matching Protocol status code using Binary notation .

Once you're succesfully connected to some remote host, you may need to read what this peer sends you...

Sometimes the protocol is using simple integer number to describe what's going on. Let's have a look at the SMTP protocol:
2XX are ok codes,
5XX are error codes.

Testing Binary matching:

-export([test/0, check/1]).

test() ->
Bin = <<"200 OK\r\n">>,

check(<<"200", Rest/binary>>) ->
{200, Rest};
check(<<"300", Rest/binary>>) ->
{300, Rest};
check(_Bin) ->
{800, unknown}.

No comments: