[Haskell-cafe] Interpreting fields in a buffer

Gregory Wright gwright at antiope.com
Sun Jan 25 22:44:58 EST 2004


I have a question related to a program I'm writing. I have to handle IP 
which will be read into a buffer. What is the best haskell idiom for 
getting access
to the fields in the buffer?

The IP header has a number of fixed format fields. In C, I would define 
a struct,
then cast the pointer to the beginning of the buffer to a pointer to 
the struct. I would then be
able to access each field in the header as <packet_struct_ptr> -> 

Is there a way in haskell to declare the format of the header, then 
access the
components of the buffer as elements of those types? I'm only going to 
do read
access on the buffer (an unboxed array). Most fields won't be examined 
but I can't
tell in advance which ones will have to be looked at.

I've not seen an example of this kind and was wondering if this was
especially awkward.


Best Wishes,

Gregory Wright
Antiope Associates LLC
18 Clay Street
Fair Haven, New Jersey 07704

gwright at antiope.com

More information about the Haskell-Cafe mailing list