Bit syntax frustrations, again

Tony Rogvall <>
Thu Oct 3 20:39:31 CEST 2002


Vance Shipley wrote:

>I am working heavily with the bit syntax right now and my two cents
>on this matter is that it is unfortunate that I can't do this:
>
>	<<Header:32, Payload/binary, Trailer:16>> = Packet
>
>It would make my life a lot easier.
>
>	-Vance
>  
>
You need to give the emulator some hint on the length of Payload,
we had two different ways in the prototype.

    1. The header contains the length of PayLoad

        <<Len:16, Header:16, Payload:Len/binary, Trailer:16>> = Packet
                                     ---


        In this case we used Variable bindings from left to right which was
        a bit controversial... (I do not remember why :-) The first 
binding of
        Len can be used later on in the bit pattern.



    2. The pattern search.

            Assume that Trailer is bound then the pattern

	<<Header:32, Payload/binary, Trailer:16>> = Packet

	Would be interpreted as "first get the header" then start search
	for a bit pattern "Trailer" when "Trailer" is found then bind the
	Payload to the bits(bytes).

Something like that?

/Tony






More information about the erlang-questions mailing list