<br><br><div class="gmail_quote">On Tue, Jun 2, 2009 at 1:28 PM, John Van Enk <span dir="ltr"><<a href="mailto:vanenkj@gmail.com">vanenkj@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I think Thomas' point was that some other branch in `getSpecific' is<br>
running. Is there a chance we can see the rest of `getSpecific'?</blockquote><div><br></div><div>Sure: (In the meantime, I'll try the suggested code from before)</div><div><br></div><div><div> get = do s <- getWord32le</div>
<div> mtype <- getWord8</div><div> getSpecific s mtype</div><div> where </div><div> getSpecific s mt </div><div> | mt == mtRversion = do t <- getWord16le</div>
<div> ms <- getWord32le</div><div> ss <- getWord16le</div><div> v <- getRemainingLazyByteString</div>
<div> return $ MessageClient $ Rversion {size=s,</div><div> mtype=mt,</div><div> tag=t,</div>
<div> msize=ms,</div><div> ssize=ss,</div><div> version=v}</div>
<div> | mt == mtRerror = do t <- getWord16le</div><div> ss <- getWord16le</div><div> e <- getLazyByteString $ fromIntegral ss</div>
<div> return $ MessageClient $ Rerror {size=s,</div><div> mtype=mt,</div><div> tag=t,</div>
<div> ssize=ss,</div><div> ename=e}</div></div><div><br></div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<div><div></div><div class="h5"><br>
On Tue, Jun 2, 2009 at 4:20 PM, David Leimbach <<a href="mailto:leimy2k@gmail.com">leimy2k@gmail.com</a>> wrote:<br>
> The thing is I have 19 bytes in the hex string I provided:<br>
> 1300000065ffff000400000600395032303030<br>
> That's 38 characters or 19 bytes.<br>
> The last 4 are 9P2000<br>
> 13000000 = 4 bytes for 32bit message payload, This is little endian for 19<br>
> bytes total.<br>
> 65 = 1 byte for message type. 65 is "Rversion" or the response type for a<br>
> Tversion request<br>
> ffff = 2 bytes for 16bit message "tag".<br>
><br>
> 00040000 = 4 bytes for the 32 bit maximum message payload size I'm<br>
> negotiating with the 9P server. This is little endian for 1024<br>
> 0600 = 2 bytes for 16 bit value for the length of the "string" I'm sending.<br>
> The strings are *NOT* null terminated in 9p, and this is little endian for<br>
> 6 bytes remaining.<br>
> 5032303030 = 6 bytes the ASCII or UTF-8 string "9P2000" which is 6 bytes<br>
> 4 + 1 + 2 + 4 + 2 + 6 = 19 bytes.<br>
> As far as I can see, my "get" code does NOT ask for a 20th byte, so why am I<br>
> getting that error?<br>
> get = do s <- getWord32le -- 4<br>
> mtype <- getWord8 -- 1<br>
> getSpecific s mtype<br>
> where<br>
> getSpecific s mt<br>
> | mt == mtRversion = do t <- getWord16le -- 2<br>
> ms <- getWord32le -- 4<br>
> ss <- getWord16le -- 2<br>
> v <-<br>
> getRemainingLazyByteString -- remaining should be 6 bytes.<br>
> return $ MessageClient $<br>
> Rversion {size=s,<br>
><br>
> mtype=mt,<br>
><br>
> tag=t,<br>
><br>
> msize=ms,<br>
><br>
> ssize=ss,<br>
><br>
> version=v}<br>
> Should I file a bug? I don't believe I should be seeing an error message<br>
> claiming a failure at the 20th byte when I've never asked for one.<br>
> Dave<br>
><br>
> On Tue, Jun 2, 2009 at 10:51 AM, John Van Enk <<a href="mailto:vanenkj@gmail.com">vanenkj@gmail.com</a>> wrote:<br>
>><br>
>> Thomas,<br>
>><br>
>> You're correct. For some reason, I based my advice on the thought that<br>
>> 19 was the minimum size instead of 13.<br>
>><br>
>> On Tue, Jun 2, 2009 at 1:24 PM, Thomas DuBuisson<br>
>> <<a href="mailto:thomas.dubuisson@gmail.com">thomas.dubuisson@gmail.com</a>> wrote:<br>
>> >> I think getRemainingLazyByteString expects at least one byte<br>
>> > No, it works with an empty bytestring. Or, my tests do with binary<br>
>> > 0.5.0.1.<br>
>> ><br>
>> > The specific error means you are requiring more data than providing.<br>
>> > First check the length of the bytestring you pass in to the to level<br>
>> > decode (or 'get') routine and walk though that to figure out how much<br>
>> > it should be consuming. I notice you have a guard on the<br>
>> > 'getSpecific' function, hopefully you're sure the case you gave us is<br>
>> > the branch being taken.<br>
>> ><br>
>> > I think the issue isn't with the code provided. I cleaned up the code<br>
>> > (which did change behavior due to the guard and data declarations that<br>
>> > weren't in the mailling) and it works fine all the way down to the<br>
>> > expected minimum of 13 bytes.<br>
>> ><br>
>> ><br>
>> >> import Data.ByteString.Lazy<br>
>> >> import Data.Binary<br>
>> >> import Data.Binary.Get<br>
>> >><br>
>> >> data RV =<br>
>> >> Rversion { size :: Word32,<br>
>> >> mtype :: Word8,<br>
>> >> tag :: Word16,<br>
>> >> msize :: Word32,<br>
>> >> ssize :: Word16,<br>
>> >> version :: ByteString}<br>
>> >> deriving (Eq, Ord, Show)<br>
>> ><br>
>> >> instance Binary RV where<br>
>> >> get = do s <- getWord32le<br>
>> >> mtype <- getWord8<br>
>> >> getSpecific s mtype<br>
>> >> where<br>
>> >> getSpecific s mt = do t <- getWord16le<br>
>> >> ms <- getWord32le<br>
>> >> ss <- getWord16le<br>
>> >> v <- getRemainingLazyByteString<br>
>> >> return $ Rversion {size=s,<br>
>> >> mtype=mt,<br>
>> >> tag=t,<br>
>> >> msize=ms,<br>
>> >> ssize=ss,<br>
>> >> version=v }<br>
>> >> put _ = undefined<br>
>> ><br>
>><br>
>><br>
>><br>
>> --<br>
>> /jve<br>
><br>
><br>
</div></div><div><div></div><div class="h5">> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
/jve<br>
</div></div></blockquote></div><br>