best approach to bitmatching...

9 views
Skip to first unread message

Jessica Hamilton

unread,
May 14, 2009, 1:28:00 AM5/14/09
to bitstring
I have a little query :)

For the network stack I'm implementing for snowflake[1], I'm using
bitstring quite extensively.

However, I wonder if there's a better approach to chaining the parsing
of bitstrings.

Currently, I do something like:

let parse_eth bits = bitmatch bits with { .....; content : -1 :
bitstring } -> (* return a type encapsulating content *)
let parse_ip bits = bitmatch bits with { .....; content : -1 :
bitstring } -> (* return a type encapsulating content *)

etc.

Is there much/any overhead in doing:
let eth = parse_eth data in
if eth encapsulate an IP packet then
let ip = parse_ip eth.content in
do something with ip

I'm pretty sure it doesn't use String.sub in this case, avoiding any
copying.

Jessica

Richard Jones

unread,
May 17, 2009, 7:52:57 AM5/17/09
to bits...@googlegroups.com

For the definitive answer on efficiency, you need to look at the
generated code. However I'm 99% certain in this case that String.sub
will *not* be used. It'll instead just use an efficient bit-substring
operation which just involves updating the start offset, and keeps the
underlying data string untouched.

Rich.

--
Richard Jones
Red Hat

Reply all
Reply to author
Forward
0 new messages