Bit syntax frustrations, again

Vance Shipley vances@REDACTED
Thu Oct 3 21:39:37 CEST 2002


On Thu, Oct 03, 2002 at 08:39:31PM +0200, Tony Rogvall wrote:
>
> You need to give the emulator some hint on the length of Payload,

Point is I don't know. :)

>    1. The header contains the length of PayLoad
> 
>        <<Len:16, Header:16, Payload:Len/binary, Trailer:16>> = Packet

So therefore I can't do this.

>    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?

Yes, perfect.  I just wrote a parser for a protocol where there is an
ascii STX (Start of Transmission) followed by a variable length data
string and then an ascii ETX (End of Transmission).  It would nice if
this worked:

-define(STX, 2).
-define(ETX, 3).


get_data(Packet) ->
	<<?STX, Data/binary, ?ETX>>.



   -Vance

Vance Shipley
Motivity Telecom Inc.
+1 519 579 5816



More information about the erlang-questions mailing list