On Friday 07 October 2005 12:50, Joel Reymont wrote:
I tried to generalize the endian-related code and came up with
something like the following which does not compile. What am I doing
wrong? I would like Endian to be a wrapper around Storable with the
endian flag. I want to be able to
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
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
This code hangs for me for whatever reason when I run it at the ghci
prompt. It does not matter whether I load it from a file or type it in.
On Oct 7, 2005, at 2:50 PM, Benjamin Franksen wrote:
You would probably want to wrap/unwrap values (using
BigEndian/LittleEndian) just before/after
It seems that (BigEndian x) - peek ptr_x is the culprit.
On Oct 7, 2005, at 4:48 PM, Joel Reymont wrote:
This code hangs for me for whatever reason when I run it at the
ghci prompt. It does not matter whether I load it from a file or
type it in.
On Oct 7, 2005, at 2:50 PM, Benjamin
On Friday 07 October 2005 16:51, Joel Reymont wrote:
It seems that (BigEndian x) - peek ptr_x is the culprit.
On Oct 7, 2005, at 4:48 PM, Joel Reymont wrote:
This code hangs for me for whatever reason when I run it at the
ghci prompt. It does not matter whether I load it from a file or
Regarding NewBinary... I think my challenge is how to add endian-
conversion without duplicating all the put and get methods from
NewBinary.
I would still use that bit of TH code to figure out whether my
platform is big or little endian. I don't care about cross-
compilation and what that
I don't want to replicate all the code in NewBinary for Little/Big
endian. I'm looking for an elegant solution (Haskell, the elegant
language, you know).
I don't care about cross-compiling stuff and the server that I need
to work with runs on Wintel whereas I can be either on Windows or
On Thu, 6 Oct 2005, Joel Reymont wrote:
I don't want to replicate all the code in NewBinary for Little/Big
endian. I'm looking for an elegant solution (Haskell, the elegant
language, you know).
Maybe that's why I haven't seen anyone propose a foreign interface,
but it's sure how I would do
Why doesn't this compile?
be = $( (1::CChar) /= (unsafePerformIO
$ with (1::CInt)
$ peekByteOff `flip` 0) ) :: Bool
Endian.hs:10:8:
Couldn't match `Language.Haskell.TH.Lib.ExpQ' against `Bool'
Expected type: Language.Haskell.TH.Lib.ExpQ
Solution by TheHunter on #haskell:
be = $(lift $ (1::CChar) /= (unsafePerformIO
$ with (1::CInt)
$ peekByteOff `flip` 0) ) :: Bool
Thanks, Joel
On Oct 6, 2005, at 9:13 PM, Joel Reymont wrote:
Why doesn't this compile?
be = $(
Why don't you pull out 4 bytes and assemble them manually?
To that I'd like to add a snippet from NewBinary itself:
| instance Binary Word32 where
| put_ h w = do
| putByte h (fromIntegral (w `shiftR` 24))
| putByte h (fromIntegral ((w `shiftR` 16) .. 0xff))
| putByte h
you are right, that pice of code is ugly. i would write sth simmilar
(Int32-[Word8]) like you did, iff it should be able to cross-compile or do not
need to be fast or should not need TH.
well, i think, in the case of joel's project the last sentence means ..., iff
true or true or undefined.
is
On Mon, Oct 03, 2005 at 09:33:11PM +0200, Udo Stenzel wrote:
Joel Reymont wrote:
Are there any endian conversion routines for Haskell? I'm looking to
build binary packets on top of NewBinary.Binary but my data is coming
in little-endian whereas I'll need to send it out big endian.
On 10/3/05, Joel Reymont [EMAIL PROTECTED] wrote:
Folks,Are there any endian conversion routines for Haskell? I'm looking tobuild binary packets on top of NewBinary.Binary but my data is comingin little-endian whereas I'll need to send it out big endian.
>From your question I assume you want
well, fastest conversion to compute could be an assembler-command, but if we
don't use that, it could be converted via Foreign.Storable and sth like the
following: (i did not test it, and i hope, TH works like this...)
data (Integral a) = BigEndian a = BigEndian a deriving (Eq,Ord,Enum,...)
be
Well, I'm looking for suggestions on how to implement this. I'll
basically get a chunk of data from the socket that will have things
little-endian and will need to send out a chunk that will have the
numbers big-endian.
This is a proxy server that does binary protocol conversion. It's a
for just making IO and a little bit-conversion, i would use c++ or even c. for
such a problem you have to be near the machine, not necessarily near
mathematical abstraction.
there exist assembler-commands to flip endians of register-values, so i would
just search in /usr/include/*/* for a
On Oct 3, 2005, at 6:51 AM, Marc Ziegert wrote:
data (Integral a) = BigEndian a = BigEndian a deriving
(Eq,Ord,Enum,...)
be = $( (1::CChar)/=(unsafePerformIO $ with (1::CInt) $ peekByteOff
`flip` 0) ) :: Bool
Will this always correctly determine if the platform is big-endian?
How does
Joel Reymont wrote:
Are there any endian conversion routines for Haskell? I'm looking to
build binary packets on top of NewBinary.Binary but my data is coming
in little-endian whereas I'll need to send it out big endian.
Why don't you pull out 4 bytes and assemble them manually? Three
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
On Mon, 3 Oct 2005, Joel Reymont wrote:
On Oct 3, 2005, at 6:51 AM, Marc Ziegert wrote:
data (Integral a) = BigEndian a = BigEndian a deriving
(Eq,Ord,Enum,...)
be = $( (1::CChar)/=(unsafePerformIO $ with (1::CInt) $ peekByteOff
`flip` 0) ) :: Bool
Will this always correctly
nice project. (except that winonly-closedsource-thing. my condolence.)
on which platform are you programming? mac? linux-ppc?
i see that you understood most of that code.
big-endian-test: the number 1234 has two ends (like a sausage), the end with
the 1 is the big end (1000), the 4 is the
On 10/3/05, Udo Stenzel [EMAIL PROTECTED] wrote:
Joel Reymont wrote: Are there any endian conversion routines for Haskell? I'm looking to build binary packets on top of NewBinary.Binary but my data is coming in little-endian whereas I'll need to send it out big endian.
Why don't you pull out 4
Folks,
Are there any endian conversion routines for Haskell? I'm looking to
build binary packets on top of NewBinary.Binary but my data is coming
in little-endian whereas I'll need to send it out big endian.
Thanks, Joel
--
http://wagerlabs.com/idealab
25 matches
Mail list logo