<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi Bert, Hi Marcel,<br></div><div><br>On Apr 26, 2018, at 5:03 AM, Bert Freudenberg <<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><span style="font-family:arial,sans-serif;color:rgb(34,34,34)">On 26 April 2018 at 13:29, Bert Freudenberg </span><span dir="ltr" style="font-family:arial,sans-serif;color:rgb(34,34,34)"><<a href="mailto:bert@freudenbergs.de" target="_blank">bert@freudenbergs.de</a>></span><span style="font-family:arial,sans-serif;color:rgb(34,34,34)"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span class="gmail-"><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><span style="font-family:arial,sans-serif;color:rgb(34,34,34)">On 26 April 2018 at 11:28, marcel.taeumel </span><span dir="ltr" style="font-family:arial,sans-serif;color:rgb(34,34,34)"><<a href="mailto:Marcel.Taeumel@hpi.de" target="_blank">Marcel.Taeumel@hpi.de</a>></span><span style="font-family:arial,sans-serif;color:rgb(34,34,34)"> wrote:</span><br></div></span><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi, there.<br>
<br>
I cannot put a ByteString into a ByteArray via a WriteStream anymore:<br>
<br>
| s |<br>
s := WriteStream on: ByteArray new.<br>
s nextPutAll: 'hello'.<br>
<br>
You need to do:<br>
<br>
| s |<br>
s := WriteStream on: ByteArray new.<br>
s nextPutAll: 'hello' asByteArray.<br>
<br>
This breaks code.<br>
<br>
Best,<br>
Marcel<br></blockquote><div><br></div></span><div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​Tech​nically this is an expected error - you simply cannot put Characters (the elements of a String) into a ByteArray. However, for convenience we do support copying Strings into ByteArrays in various places, including <span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">WriteStream>>nextPut<wbr>All:.</span></div></div><div><br></div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">However, the test in <span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">WriteStream>>nextPutAll: is too strict. It needs to be "collection class isBits" instead of "<span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">collection isString". This makes the code actually match its comment:</span></span></div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div><font color="#000000" face="arial, helvetica, sans-serif">WriteStream>>nextPutAll: aCollection</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">      </span>| newEnd |</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">      </span>(collection class == aCollection class</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">          </span>or: [ collection <span style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">class isBits</span></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                        </span>and: [ aCollection isString</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">                     </span>and: [ collection class format = aCollection class format ] ] ]) "Let Strings with the same field size as collection take the quick route too."</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">               </span>ifFalse: [ ^ super nextPutAll: aCollection ].</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap"> </span>newEnd := position + aCollection size.</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">  </span>newEnd > writeLimit ifTrue:</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">          </span>[self growTo: newEnd + 10].</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">   </span>collection replaceFrom: position+1 to: newEnd  with: aCollection startingAt: 1.</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">    </span>position := newEnd.</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><span style="white-space:pre-wrap">     </span>^aCollection​</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div><font color="#000000" face="arial, helvetica, sans-serif">With that change your example works. I think this was the original intent of the code.</font></div><div><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div><font color="#000000" face="arial, helvetica, sans-serif">Fixed in Collections-bf.787</font></div></div></div></div></blockquote><div> </div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​PS: ​doing it this way ensures that you still get an error when you try to write a WideString into a ByteArray stream.</div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">- Bert -</div></div></div></div></div></blockquote><br><div>I agree with Sven:</div><div><br></div><div><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><b>From:</b> Sven Van Caekenberghe <<a href="mailto:sven@stfx.eu">sven@stfx.eu</a>><br><b>Date:</b> April 26, 2018 at 6:36:42 AM PDT<br><b>To:</b> Pharo Development List <<a href="mailto:pharo-dev@lists.pharo.org">pharo-dev@lists.pharo.org</a>><br><b>Subject:</b> <b>Re: [Pharo-dev] Fwd: ByteArray>>at:put:</b><br><b>Reply-To:</b> Pharo Development List <<a href="mailto:pharo-dev@lists.pharo.org">pharo-dev@lists.pharo.org</a>><br></span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">On 26 Apr 2018, at 15:21, Sean P. DeNigris <<a href="mailto:sean@clipperadams.com">sean@clipperadams.com</a>> wrote:<br></span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">Relevant to Pharo?<br></span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">From <a href="http://forum.world.st/ByteArray-at-put-tp4955848.html">http://forum.world.st/ByteArray-at-put-tp4955848.html</a> :<br></span></font></blockquote><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br>We don't (want to) mix binary and character collections or streams. Going from one to the other is called encoding and decoding, it has to be done while being conscious of which encoding you are using. Sending #asByteArray to a String or #asString to a ByteArray is dangerous, lazy and wrong (in most cases), especially in an international context.</span></font><br></blockquote><br></div><div>So I would rather see an error or a convenience method such as nextPutAllBits: which does what the above does (implicitly convert) but is explicit.  (ByteArray new: 5) writeStream nextPutAll: #[1 2 3 4 5] and (ByteString new: 5) <span style="background-color: rgba(255, 255, 255, 0);">nextPutAll: 'hello' should both raise an error (only the last does), as should (ByteArray new: 5) writeStream nextPut: $!. </span><span style="background-color: rgba(255, 255, 255, 0);"> (ByteString new: 5)</span><span style="background-color: rgba(255, 255, 255, 0);"> </span><span style="background-color: rgba(255, 255, 255, 0);">nextPut: 33 does.  At least these operations should be consistent and symmetrical.  Right now nextPut: is consistent with nextPutAll: but String<-Integer is not symmetric with ByteArray<-Character.</span></div></body></html>