Binary read/write WAS [storing to a file]
Shawn P. Garbett
Thu, 14 Nov 2002 16:59:42 -0600
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
Xlib sockets and binding wasn't the point of the question. The example wa=
contrived to show the basic problem or reading / writing some arbitrary=20
I looked at the solution in the Fudgets library, an interesting solution =
ine there for typed sockets.=20
http://www.cs.chalmers.se/~hallgren/Thesis/client_server.html. It allows =
a typed return on a socket, with a nice tight set of code. This typed ret=
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 =
the open connection request is a "string" for the vendor. The length of t=
string is at byte 24 in the reply, it's a 2 byte Word. The string of the=20
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=20
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=
the reply in as a String and process it. Problem is I don't even know how=
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 int=
going on. Is that the purpose of it to help in such situations?