Project

General

Profile

Actions

Feature #17834

open

Add a Bytes and BytesArray class that implement memoryview

Added by dsisnero (Dominic Sisneros) over 3 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:103608]

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 #1

Updated by Eregon (Benoit Daloze) over 3 years ago

  • Description updated (diff)
Actions #2

Updated by dsisnero (Dominic Sisneros) over 3 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0