
On Thursday 14 November 2002 03:46 pm, you wrote:
I've been fiddling with binary read/write in Haskell. I put together a little example demonstrating my lack of understanding. It creates a connection requestion XAtom and spits it out over a socket. My real hangup occurs when I get a String back from the Socket and would like it nicely marshalled into the ConnectSuccess type. These techniques I would assume apply to binary read/write for files as well.
IIRC, the Fudgets library reads and writes X sockets so you could look here:
http://www.cs.chalmers.se/ComputingScience/Research/Functional/Fudgets/
Xlib sockets and binding wasn't the point of the question. The example was contrived to show the basic problem or reading / writing some arbitrary binary sequence. I looked at the solution in the Fudgets library, an interesting solution is ine there for typed sockets. http://www.cs.chalmers.se/~hallgren/Thesis/client_server.html. It allows for a typed return on a socket, with a nice tight set of code. This typed return I understand relies on the types being members of the Read class. The problem of the Xatom, is a bit more difficult. Embedded in the reply of the open connection request is a "string" for the vendor. The length of the string is at byte 24 in the reply, it's a 2 byte Word. The string of the vendor starts at byte 40. This is followed by a 4-byte padding. Once your past this oddness, it gets a lot funner with all kinds of other embedded information pointing all over the place in the packet. I don't think String is a member of the Read class. So my thinking was to read the reply in as a String and process it. Problem is I don't even know how to extract the first four bytes of a String as a raw Word32. That would be a start, but the general problem is a tad bit more difficult. I've been reading some about the "Binary" module and it's translation into GHC going on. Is that the purpose of it to help in such situations? Shawn