[Haskell-beginners] doc on accessing C struct binary data
Stephen Tetley
stephen.tetley at gmail.com
Sat Jul 31 04:11:50 EDT 2010
Hi Sean
Commonly people would use Data.Word and Data.Int to get sized
integrals. There's no corresponding sized types for floats - if you're
lucky your serialized C Structs won't use floats otherwise you'll have
to dig out a reference manual to see how they are laid out.
To actually read C-structs Data.Binary.Get should provide the
primitives you need (getWord8, getWord16le, getWord16be, ...), you'll
then have to assemble a parser using these primitives to read your
struct.
You might have to pay some attention to alignment - the C struct might
be laid out with elements on byte boundaries (usually 4-byte) rather
than directly adjacent. I suspect alignment is compiler dependent, its
a long time since I looked at this but I believe C99 has pragmas to
direct the compiler on alignment.
Best wishes
Stephen
More information about the Beginners
mailing list