[Haskell-cafe] Serializing with alignment
ben.franksen at online.de
Tue Nov 6 22:33:56 CET 2012
I want to implement a binary protocol that, unfortunately, has some
alignment restrictions. In order to fulfill these, I need access to the
"current offset" in the bytestring. The binary package does provide a
bytesRead :: Get Int64
but only for the Get monad; there is no equivalent for the Put monad.
So my first question: is there a serialization library that offers something
bytesWritten :: PutM Int64
Failing that, would you think adding it to binary is a reasonable feature
request? I have taken a cursory look at the implementation and it looks like
this is not a matter of simply adding a missing function, but would probably
need an addition to internal data structures.
I could also try and wrap the PutM from binary with a StateT transformer and
count the bytes myself. I will probably have to use at least a ReaderT
wrapper anyway, since I have to pass the byte order as a parameter (byte
order gets negotiated between client and server, it is not fixed).
I was really hoping that there is some library that has built-in support for
stateful serialization (alignment, byte-order, etc).
Any pointers, hints, etc are much appreciated.
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
More information about the Haskell-Cafe