I have a Byte[] buffer that may contain one or multiple data frames, I need to read the first bytes to know how long the actual frame is.
This is a "non-working" version of what I want to do:
let extractFrame (buffer:byte[]) =
match buffer with
| [|head1;head2;head3;..|] when head2 < (byte)128 -> processDataFrame buffer head2
| <...others....>
| _ -> raise(new System.Exception())
Basically, I need to evaluate the first three bytes, and then call processDataFrame with the buffer and the actual length of the frame. Depending on the headers, the frame can be data, control, etc...
Can this be done with any kind of match (lists, sequences, ...etc...)? Or will I have to create another small array with just the length of the header?(I would like to avoid this).
If you want to use matching you could create active pattern (http://msdn.microsoft.com/en-us/library/dd233248.aspx):