Actions
Feature #17834
openAdd a Bytes and BytesArray class that implement memoryview
Status:
Open
Assignee:
-
Target version:
-
Description
"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) not just plain array
or add a new %b literal that returns an immutable ByteString %b('this is a string')
Actions
Like0
Like0Like0