I've got the following "printHex" string as a response from a 9P server running on the Inferno Operating System. (thanks to a friendly mailing list contributor who sent a nice example of using Data.Binary)
Rversion {size :: Word32,
mtype :: Word8,
tag :: Word16,
msize :: Word32,
ssize :: Word16,
version :: ByteString}
But when I try to use the following implementation of "get" to decode this stream, I'm getting the following error:
"too few bytes. Failed reading at byte position 20"
Unfortunately, I'm only expecting 19 bytes, and in fact never asked for byte 20. (I am just asking for everything up to ssize, and then "getRemainingLazyByteString").
Is this a bug? Is it mine or in Data.Binary? :-)
Here's my "get" function:
get = do s <- getWord32le
mtype <- getWord8
getSpecific s mtype
where
getSpecific s mt
| mt == mtRversion = do t <- getWord16le
ms <- getWord32le
ss <- getWord16le
v <- getRemainingLazyByteString
return $ MessageClient $ Rversion {size=s,
mtype=mt,
tag=t,
msize=ms,
ssize=ss,
version=v}
The good news is I'm talking 9P otherwise, correctly, just having some decoding issues. I hope to have a hackage package eventually for this.
Dave