[Haskell-cafe] Endian conversion
Joel Reymont
joelr1 at gmail.com
Mon Oct 3 16:03:54 EDT 2005
Well, I liked that bit of Template Haskell code that Marc sent. I'm
now stuck trying to adapt it to read Storables :-).
It seems, on a second glance, that there's not that much to adapt. If
I read Marc's code correctly it "derives" Storable and uses the peek,
etc. methods to swap bytes around. Which means to me that so long as
the byte swapping methods are implemented and I try to store a
BigEndian or LittleEndian it would be stored correctly for me.
Is this so?
To recap, I'm trying to read binary packets from a socket and the
first thing I do is read the packet length. I then need to read the
packet body where the numbers are little or big endian. After
processing the packet I need to write it out and the numbers again
could be little or big endian.
I could read a FastString from a socket since it has IO methods but I
don't know how to convert the FS into a pointer suitable for
Storable. So much to learn :-).
Thanks, Joel
On Oct 3, 2005, at 9:33 PM, Udo Stenzel wrote:
> Why don't you pull out 4 bytes and assemble them manually? Three
> shifts, logical ors and fromIntegrals aren't that much of a burden
> after
> all.
--
http://wagerlabs.com/idealab
More information about the Haskell-Cafe
mailing list