<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    On 18.05.2011 09:21, Martin Dias wrote:
    <blockquote
      cite="mid:BANLkTinvmzm_8ispzAZpvDW+imojFyqEtA@mail.gmail.com"
      type="cite"><br>
      <br>
      <div class="gmail_quote">On Tue, May 17, 2011 at 7:16 PM, Igor
        Stasenko <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div>
            <div class="h5">On 17 May 2011 22:58, Mariano Martinez Peck
              &lt;<a moz-do-not-send="true"
                href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>&gt;
              wrote:<br>
              &gt;<br>
              &gt;<br>
              &gt; On Tue, May 17, 2011 at 10:31 PM, Sven Van
              Caekenberghe &lt;<a moz-do-not-send="true"
                href="mailto:sven@beta9.be">sven@beta9.be</a>&gt;<br>
              &gt; wrote:<br>
              &gt;&gt;<br>
              &gt;&gt; On 17 May 2011, at 21:57, Mariano Martinez Peck
              wrote:<br>
              &gt;&gt;<br>
              &gt;&gt; &gt; Sven, I want to make it work :)<br>
              &gt;&gt; &gt;<br>
              &gt;&gt; &gt; so....the missing methods I told you that I
              need are:<br>
              &gt;&gt; &gt;<br>
              &gt;&gt; &gt; #nextStringPut:<br>
              &gt;&gt; &gt; #nextNumber:put:<br>
              &gt;&gt; &gt; #nextInt32Put:<br>
              &gt;&gt; &gt; #nextWordPut:<br>
              &gt;&gt;<br>
              &gt;&gt; I guess these are pretty easy. But I think they
              clutter the interface of<br>
              &gt;&gt; ZnBufferedWriteStream, so maybe you should make a
              subclass.<br>
              &gt;&gt;<br>
              &gt;<br>
              &gt; Yeah, don't worry. I can even duplicate the class
              hehehe<br>
              &gt;<br>
              &gt;&gt;<br>
              &gt;&gt; &gt; #contents<br>
              &gt;&gt; &gt;<br>
              &gt;&gt; &gt; Implement #contents I guess it is something
              like:<br>
              &gt;&gt; &gt;<br>
              &gt;&gt; &gt; ZnBufferedWriteStream &gt;&gt; contents<br>
              &gt;&gt; &gt; ^ stream contents<br>
              &gt;&gt;<br>
              &gt;&gt; Why to you need #contents ?<br>
              &gt;<br>
              &gt; becasue I am an idiot. No, I don't need it. You are
              correct. Thanks for<br>
              &gt; asking.<br>
              &gt;<br>
              &gt;&gt;<br>
              &gt;&gt; I would say that it goes a bit against the
              concept of a stream as a sink<br>
              &gt;&gt; of data.<br>
              &gt;&gt; I haven't looked, but I would guess that saying
              #contents to a FileStream<br>
              &gt;&gt; is not efficient.<br>
              &gt;&gt;<br>
              &gt;&gt; &gt; Those missing methods I need are implemented
              PositionableStream. I took<br>
              &gt;&gt; &gt; the implementation from there and &nbsp;put it in
              ZnBufferedWriteStream.<br>
              &gt;&gt; &gt; I just added to them a first line " &nbsp; &nbsp;self
              flushBufferIfFull."<br>
              &gt;&gt;<br>
              &gt;&gt; That is probably OK, except when your string
              becomes larger than the<br>
              &gt;&gt; buffer. Have a look at #nextPutAll:<br>
              &gt;&gt;<br>
              &gt;<br>
              &gt; I am not sure if I understood. The following are
              correct for sure then:<br>
              &gt; &nbsp;#nextNumber:put:<br>
              &gt; &nbsp;#nextInt32Put:<br>
              &gt; &nbsp;#nextWordPut:<br>
              &gt;<br>
              &gt;<br>
              &gt; And #nextStringPut:&nbsp;&nbsp; is like this:<br>
              &gt;<br>
              &gt; nextStringPut: s<br>
              &gt; &nbsp;&nbsp;&nbsp; "Append the string, s, to the receiver.&nbsp; Only
              used by DataStream.&nbsp; Max<br>
              &gt; size of 64*256*256*256."<br>
              &gt;<br>
              &gt; &nbsp;&nbsp;&nbsp; | length |<br>
              &gt; &nbsp;&nbsp;&nbsp; self flushBufferIfFull.<br>
              &gt; &nbsp;&nbsp;&nbsp; (length := s size) &lt; 192<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ifTrue: [self nextPut: length]<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ifFalse:<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;[self nextPut: (length digitAt: 4)+192.<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self nextPut: (length digitAt: 3).<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self nextPut: (length digitAt: 2).<br>
              &gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self nextPut: (length digitAt: 1)].<br>
              &gt; &nbsp;&nbsp;&nbsp; self nextPutAll: s asByteArray.<br>
              &gt; &nbsp;&nbsp;&nbsp; ^s<br>
              &gt;<br>
              <br>
            </div>
          </div>
          Sorry, but i can't resist commenting on that.<br>
          Why, if you demand from stream to implement #nextInt32Put:<br>
          a the same time, you writing code like this<br>
          <div class="im"><br>
            self nextPut: (length digitAt: 4)+192.<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self nextPut: (length digitAt: 3).<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self nextPut: (length digitAt: 2).<br>
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self nextPut: (length digitAt: 1)<br>
            <br>
          </div>
          ?<br>
          Then just extend your serializer with a notion of 'length'
          field,<br>
          which you can use for anything where you need to encode
          length/size value,<br>
          but not just for Strings.<br>
          So, then the above method could be as short as:<br>
          <br>
          nextStringPut: s<br>
          &nbsp;self putLength: s size.<br>
          &nbsp;self nexPutAll: s asByteArray.<br>
          <br>
          and here you have a potential caveat because your string could
          be<br>
          WideString .. muhahaha.<br>
          <br>
          So, i suggest you to reconsider the way how you serializing
          strings.<br>
          Instead what you could do is to extend ByteString and
          WideString (and<br>
          perhaps similarily do for ByteSymbol and WideSymbol),<br>
          the methods which is responsible to turning a receiver in a
          sequence<br>
          of bytes, and then simply put it into output stream,<br>
          whatever it might be.<br>
          <br>
          Then you don't need #nextStringPut: because its<br>
          a) not polymorphic, because apparently serializing ByteString
          should<br>
          be different from serializing WideString<br>
          b) instead you implementing this in<br>
          Byte/WideString&gt;&gt;serializeToFuelStream: aStream and you
          done.<br>
        </blockquote>
        <div><br>
          Yes, I am not sure if #nextStringPut: is not polymorphic, but
          I think that with #serializeToFuelStream: we can avoid
          converting the WideString to ByteArray just to write the
          ByteArray to the stream, and instead just write the WideString
          to the stream. Right?<br>
        </div>
      </div>
    </blockquote>
    You don't ever need the asByteArray call to store ByteStrings if you
    use nextPutAll: on a default stream in binary mode, the primitive
    handles that just fine for variableByte subclasses.<br>
    <br>
    If you are doing the same as DataStream, only ByteStrings are
    written using nextStringPut: , WideStrings are stored with the
    default writeWordLike: facilities.<br>
    <br>
    Is there a document describing the binary format of Fuel somewhere?<br>
    <br>
    Cheers,<br>
    Henry<br>
  </body>
</html>