[Haskell-cafe] Data.Binary and little endian encoding

Khudyakov Alexey alexey.skladnoy at gmail.com
Sat May 16 06:46:23 EDT 2009

On Friday 15 May 2009 06:52:29 David Leimbach wrote:
> I actually need little endian encoding... wondering if anyone else hit this
> with Data.Binary. (because I'm working with Bell Lab's 9P protocol which
> does encode things on the network in little-endian order).
> Anyone got some "tricks" for this?
> Dave

You could just define data type and Binary instance for 9P messages. Something 
like this:

P9Message = Tversion { tag :: Word16, msize :: Word32, version :: String } 
    | ... 

instance Binary P9Message where
  put (Tverstion  t m v) =  putWord16le t >>  putWord32le m >> put v
  -- and so on...

  get = do 
    length <- getWord32le
    id <- getWord16le
    case is of
      p9TMessage -> do ... 
There are a lot of boilerplate code thought...

BTW could you say what do you want to do with 9P? I tried to play with it  
using libixp library but without any success. It was mainly to understand how 
does it works and how can it be used. 

More information about the Haskell-Cafe mailing list