Thomas, You're correct. For some reason, I based my advice on the thought that 19 was the minimum size instead of 13.
On Tue, Jun 2, 2009 at 1:24 PM, Thomas DuBuisson <[email protected]> wrote: >> I think getRemainingLazyByteString expects at least one byte > No, it works with an empty bytestring. Or, my tests do with binary 0.5.0.1. > > The specific error means you are requiring more data than providing. > First check the length of the bytestring you pass in to the to level > decode (or 'get') routine and walk though that to figure out how much > it should be consuming. I notice you have a guard on the > 'getSpecific' function, hopefully you're sure the case you gave us is > the branch being taken. > > I think the issue isn't with the code provided. I cleaned up the code > (which did change behavior due to the guard and data declarations that > weren't in the mailling) and it works fine all the way down to the > expected minimum of 13 bytes. > > >> import Data.ByteString.Lazy >> import Data.Binary >> import Data.Binary.Get >> >> data RV = >> Rversion { size :: Word32, >> mtype :: Word8, >> tag :: Word16, >> msize :: Word32, >> ssize :: Word16, >> version :: ByteString} >> deriving (Eq, Ord, Show) > >> instance Binary RV where >> get = do s <- getWord32le >> mtype <- getWord8 >> getSpecific s mtype >> where >> getSpecific s mt = do t <- getWord16le >> ms <- getWord32le >> ss <- getWord16le >> v <- getRemainingLazyByteString >> return $ Rversion {size=s, >> mtype=mt, >> tag=t, >> msize=ms, >> ssize=ss, >> version=v } >> put _ = undefined > -- /jve _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
