What I have in mind is composing a packet structure from a list of
storables. These would be the packet fields. Alternatively, I guess I
could declare my record to be an instance of storable and implement
the peek, poker, etc. Would this work?
On Oct 7, 2005, at 4:39 PM, Benjamin Franksen wrote:
On Friday 07 October 2005 14:50, Benjamin Franksen wrote:
First a version that should work (at least it compiles) for poke:
\begin{code}
instance (Storable a) => Storable (Endian a) where
sizeOf (Endian a _) = sizeOf a
alignment (Endian a _) = alignment a
pokeByteOff p i (Endian a b) =
if getHostByteOrder == b
then pokeByteOff p i a
else pokeByteOff p (sizeOf a - 1 - i) a
\end{code}
Note that even this breaks down for more complex types (i.e. records).
For instance, with the obvious Storable instance of (Int16,Int16), the
elements will get swapped, too. I can't see how to solve this in a
generic way.
--
http://wagerlabs.com/idealab
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe