From: dsisnero@... Date: 2021-04-26T23:09:55+00:00 Subject: [ruby-core:103608] [Ruby master Feature#17834] Add a Bytes and BytesArray class that implement memoryview Issue #17834 has been reported by dsisnero (Dominic Sisneros). ---------------------------------------- Feature #17834: Add a Bytes and BytesArray class that implement memoryview https://bugs.ruby-lang.org/issues/17834 * Author: dsisnero (Dominic Sisneros) * Status: Open * Priority: Normal ---------------------------------------- "this is a string.bytes should == Bytes.new('this is a string') # an immutable bytes object that implements memory view bytestring = Bytes.new('this is a string') mv = Fiddle::MemoryView.new(bytestring) mv[0] # 116 similary String.new('this is a string').bytes == ByteArray.new('this is a string') # a mutable byte array object that implements memoryview , takes an optional encoding that uses current string encoding ba = ByteArray.new('this is a string') mv = Fiddle::MemoryView.new(ba) mv[0] # 116 mv[0] = 120 # memoryview works on underlying object - changes mv.obj ba.pack('C*').force_encoding('UTF-8') # 'xhis is a string' also it would be good if String#bytes returns the new classes - (return something that implements memoryview) -- https://bugs.ruby-lang.org/ Unsubscribe: