[Haskell-cafe] ANNOUNCE: binary: high performance, pure binary serialisation

John Meacham john at repetae.net
Fri Jan 26 15:36:50 EST 2007


On Fri, Jan 26, 2007 at 04:42:48PM +0100, Tomasz Zielonka wrote:
> I also have to use a specific serialisation format. I guess we could
> both simply use putWord8, but then we'll probably lose most of the
> benefits of using the library.
> 
> Perhaps we could think about introducing some "encoding contexts", with
> a default encoding that can be automatically derived, but also with the
> ability to create one's own encodings?

one can use newtypes they would be faster in any case, I was thinking
something like:


> newtype XDRInt = XDRInt Int
> newtype XDRSTring sz = ...

and so forth, now if you build up a structure

> data NfsSattr = NfsSattr {
>         mode :: XdrUnsigend,  -- protection mode bits
>         uid :: XdrUnsigned,   -- owner user id 
>         gid :: XdrUnsigned,   -- owner group id
>         size :: XdrUnsigned,  -- file size in bytes
>         atime :: XdrNfsTime,  -- time of last access
>         mtime :: XdrNfsTime   -- time of last modification
>         }

now you can speak nfs directly by serializing right from and to your
socket! :) a whole filesystem implemented in haskell in not so many
lines. very nice.

actually, I probably will write Data.Binary.Protocol.Xdr (better
location?). I actually do have a NFS server written in haskell in a much
more clunky way I could revive.

now, the only new primitives I would need are:

> alignTo :: Word8 -> Int -> Put
> alignTo _ _ = ...
>
> setAlignment :: Int -> Put
> setAlignment _ = ...

where alignTo would output some number of bytes in order to bring the
stream to the next alignment boundry specified, and setAlignment would
force the current alignment to be some value, without outputing any
bytes. Would these be doable? They would open up a lot of possibilities.

        John


-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell-Cafe mailing list