--4ea378f5_327b517e_1124 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Saturday, October 22, 2011 at 12:43 PM, Jon wrote: > > > What Ruby needs (IMHO), is the equivalent of Obj-C's NSData class. That is, something which can hold a contiguous span of raw bytes without encoding, but with the ability to access ranges and iterate over the data like a String. I regret that I did not recall this desire of mine for the original Ruby 2.0 feature list (I originally encountered the need for this when writing the ControlTower server for MacRuby; which, consequently, does make use of NSData). I would, however, like to propose such a class for Ruby 2.0. > > > > > > > > > > > > What's your view regarding both the `bytes` (immutable) and `bytearray` (mutable) abstractions from > > http://docs.python.org/py3k/library/functions.html#bytearray > > > Yes, this sounds like a very similar idea (NSData is immutable and has an NSMutableData counterpart). I think the intro for the NSData documentation captures the motivation perfectly: > NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects. Basically, since the Array class in Ruby is designed to hold objects, there is an annoying amount of overhead required to use Ruby arrays to hold simple bytes (e.g. you have to manually decompose bytes on each append operation). On the other hand, since Ruby does its best to always do the right thing with encodings for String objects, it can get annoying to try and use Ruby strings to hold bytes (you never know when your BINARY string might be coerced into UTF-8). --4ea378f5_327b517e_1124 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline <div><span class="Apple-style-span" style="color: rgb(160, 160, 168); ">On Saturday, October 22, 2011 at 12:43 PM, Jonrote:</span></div> <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;"> <span><div><div><div><div> </div><blockquote type="cite"><div><div><div> What Ruby needs (IMHO), is the equivalent of Obj-C's NSData class. That is, something which can hold a contiguous span of raw bytes without encoding, but with the ability to access ranges and iterate over the data like a String. I regret that I did not recall this desire of mine for the original Ruby 2.0 feature list (I originally encountered the need for this when writing the ControlTower server for MacRuby; which, consequently, doesake use of NSData). I would, however, like to propose such a class for Ruby 2.0.</div> </div><div><div> </div></div></div></blockquote><div> </div><div> </div><div>What's your view regarding both the `bytes` (immutable) and `bytearray` (mutable) abstractions from</div><div> </div><div> http://docs.python.org/py3k/library/functions.html#bytearray</div> </div></div></div></span></blockquote><div><br> </div><div><br></div><div>Yes, this sounds like a very similar idea (NSData is immutable and has an NSMutableData counterpart). I think the intro for the NSData documentation captures the motivation perfectly:</div><div><br></div><div><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: rgb(102, 102, 102); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "></code><blockquote type="cite"><code style="font-size: 13px; font-family: Courier, Consolas, monospace; color: rgb(102, 102, 102); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">NSData</code><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; "> and its mutable subclass </span><codetyle="font-size: 13px; font-family: Courier, Consolas, monospace; color: rgb(102, 102, 102); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">NSMutableData</code><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px;ont-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto;ext-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; "> provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects.</span></blockquote><div><br></div><div>Basically, since the Array class in Ruby is designed to hold objects, there is an annoying amount of overhead required to use Ruby arrays to hold simple bytes (e.g. you have toanually decompose bytes on each append operation). On the other hand, since Ruby does its best to always do the right thing with encodings for String objects, it can get annoying to try and use Ruby strings to hold bytes (you never know when your BINARY string might be coerced into UTF-8). </div><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande', Geneva, Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none; "></span></div> --4ea378f5_327b517e_1124--