<br><br><div class="gmail_quote">On Tue, Jun 2, 2009 at 1:32 PM, John Van Enk <span dir="ltr">&lt;<a href="mailto:vanenkj@gmail.com">vanenkj@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Perhaps there&#39;s some place in your code that&#39;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&#39;m using a Lazy ByteString network IO lib.  So I don&#39;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&#39;s why it&#39;s going for a 20th byte, shouldn&#39;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 &lt;<a href="mailto:leimy2k@gmail.com">leimy2k@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Jun 2, 2009 at 10:24 AM, Thomas DuBuisson<br>
&gt; &lt;<a href="mailto:thomas.dubuisson@gmail.com">thomas.dubuisson@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; I think getRemainingLazyByteString expects at least one byte<br>
&gt;&gt; No, it works with an empty bytestring.  Or, my tests do with binary<br>
&gt;&gt; 0.5.0.1.<br>
&gt;&gt;<br>
&gt;&gt; The specific error means you are requiring more data than providing.<br>
&gt;<br>
&gt; I&#39;ve shown that I am not trying to decode more than I&#39;m providing.  I&#39;ve<br>
&gt; asked, expliciitly, for 13 bytes, and then &quot;remaining&quot;, and the library is<br>
&gt; complaining about the 20th byte.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; First check the length of the bytestring you pass in to the to level<br>
&gt;&gt; decode (or &#39;get&#39;) routine and walk though that to figure out how much<br>
&gt;&gt; it should be consuming.  I notice you have a guard on the<br>
&gt;&gt; &#39;getSpecific&#39; function, hopefully you&#39;re sure the case you gave us is<br>
&gt;&gt; the branch being taken.<br>
&gt;<br>
&gt; The other branch is Rerror, which is a shorter message decode stream.<br>
&gt;  Unfortunately, I can&#39;t get Debug.Trace to show anything to prove it&#39;s<br>
&gt; taking this fork of the code.  I suppose I could unsafePerformIO :-)<br>
&gt; Perhaps I just need a new version of &quot;binary&quot;??  I&#39;ll give it a go and try<br>
&gt; your version.  But I need to decode over a dozen message types, so I will<br>
&gt; need a case or guard or something.<br>
&gt; Dave<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I think the issue isn&#39;t with the code provided.  I cleaned up the code<br>
&gt;&gt; (which did change behavior due to the guard and data declarations that<br>
&gt;&gt; weren&#39;t in the mailling) and it works fine all the way down to the<br>
&gt;&gt; expected minimum of 13 bytes.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; &gt; import Data.ByteString.Lazy<br>
&gt;&gt; &gt; import Data.Binary<br>
&gt;&gt; &gt; import Data.Binary.Get<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; data RV =<br>
&gt;&gt; &gt; Rversion {     size   :: Word32,<br>
&gt;&gt; &gt;                mtype  :: Word8,<br>
&gt;&gt; &gt;                tag    :: Word16,<br>
&gt;&gt; &gt;                msize  :: Word32,<br>
&gt;&gt; &gt;                ssize  :: Word16,<br>
&gt;&gt; &gt;                version :: ByteString}<br>
&gt;&gt; &gt;       deriving (Eq, Ord, Show)<br>
&gt;&gt;<br>
&gt;&gt; &gt; instance Binary RV where<br>
&gt;&gt; &gt;  get = do s &lt;- getWord32le<br>
&gt;&gt; &gt;          mtype &lt;- getWord8<br>
&gt;&gt; &gt;          getSpecific s mtype<br>
&gt;&gt; &gt;   where<br>
&gt;&gt; &gt;    getSpecific s mt = do t &lt;- getWord16le<br>
&gt;&gt; &gt;                          ms &lt;- getWord32le<br>
&gt;&gt; &gt;                          ss &lt;- getWord16le<br>
&gt;&gt; &gt;                          v &lt;- getRemainingLazyByteString<br>
&gt;&gt; &gt;                          return $ Rversion {size=s,<br>
&gt;&gt; &gt;                                             mtype=mt,<br>
&gt;&gt; &gt;                                             tag=t,<br>
&gt;&gt; &gt;                                             msize=ms,<br>
&gt;&gt; &gt;                                             ssize=ss,<br>
&gt;&gt; &gt;                                             version=v }<br>
&gt;&gt; &gt;  put _ = undefined<br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
</div></div>--<br>
<font color="#888888">/jve<br>
</font></blockquote></div><br>