<br><br><div class="gmail_quote">On Tue, Jun 2, 2009 at 1:32 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;">
Perhaps there's some place in your code that's forcing the lazy read<br>
to consume more. Perhaps you could replace it with an explict (and<br>
strict) getBytes[1] in combination with remaining[2]?</blockquote><div><br></div><div>Unfortunately, I'm using a Lazy ByteString network IO lib. So I don't think going to a strict ByteString is going to be possible.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<br>
Is there a reason you want to use lazy byte strings rather than<br>
forcing full consumption? Do the 9P packets generally have a lot of<br>
trailing useless data?</blockquote><div><br></div><div>Nope. Just I noticed that there was a Network ByteString package that utilized lazy bytestrings :-).</div><div><br></div><div>Even if that's why it's going for a 20th byte, shouldn't that be a bug? :-)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<br>
1. <a href="http://hackage.haskell.org/packages/archive/binary/0.5.0.1/doc/html/Data-Binary-Get.html#v%3AgetBytes" target="_blank">http://hackage.haskell.org/packages/archive/binary/0.5.0.1/doc/html/Data-Binary-Get.html#v%3AgetBytes</a><br>
2. <a href="http://hackage.haskell.org/packages/archive/binary/0.5.0.1/doc/html/Data-Binary-Get.html#v%3Aremaining" target="_blank">http://hackage.haskell.org/packages/archive/binary/0.5.0.1/doc/html/Data-Binary-Get.html#v%3Aremaining</a><br>
<div><div></div><div class="h5"><br>
On Tue, Jun 2, 2009 at 4:28 PM, David Leimbach <<a href="mailto:leimy2k@gmail.com">leimy2k@gmail.com</a>> wrote:<br>
><br>
><br>
> On Tue, Jun 2, 2009 at 10:24 AM, Thomas DuBuisson<br>
> <<a href="mailto:thomas.dubuisson@gmail.com">thomas.dubuisson@gmail.com</a>> wrote:<br>
>><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>
><br>
> I've shown that I am not trying to decode more than I'm providing. I've<br>
> asked, expliciitly, for 13 bytes, and then "remaining", and the library is<br>
> complaining about the 20th byte.<br>
><br>
>><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>
> The other branch is Rerror, which is a shorter message decode stream.<br>
> Unfortunately, I can't get Debug.Trace to show anything to prove it's<br>
> taking this fork of the code. I suppose I could unsafePerformIO :-)<br>
> Perhaps I just need a new version of "binary"?? I'll give it a go and try<br>
> your version. But I need to decode over a dozen message types, so I will<br>
> need a case or guard or something.<br>
> Dave<br>
>><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>
</div></div>--<br>
<font color="#888888">/jve<br>
</font></blockquote></div><br>