[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mapping data

Steven Shaw wrote:
> Erlang has something called "bit syntax".
> 	http://c2.com/cgi/wiki?ErlangBitSyntax

I was about to suggest a look at Erlang's Bit Syntax when Steven beat me 
to it.  Anyone who is interested should take a look at


specfically section 1.4.  One interesting example is erlang code to 
match an IP datagram

-define(IP_VERSION, 4).
-define(IP_MIN_HDR_LEN, 5).

DgramSize = size(Dgram),
case Dgram of
   <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16,
     ID:16, Flgs:3, FragOff:13,
     TTL:8, Proto:8, HdrChkSum:16,
     DestIP:32, RestDgram/binary>> when HLen >= 5, 4*HLen =< DgramSize ->
       OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN),
       <<Opts:OptsLen/binary,Data/binary>> = RestDgram,

I also need to make clear that I do not currently know erlang 
sufficiently to discuss it properly.  I am currently learning erlang for 
my own interest, and thought of this thread when I saw this code.

Andrae Muys

  Andrae Muys    <andrae.muys@braintree.com.au>
  Engineer       Braintree Communications