Class: Buffer
- Includes:
- Native::Wrapper
- Defined in:
- opal/stdlib/buffer/view.rb,
opal/stdlib/buffer.rb,
opal/stdlib/buffer/array.rb
Overview
backtick_javascript: true
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(size, bits = 8) ⇒ Buffer
constructor
A new instance of Buffer.
- #length ⇒ Object (also: #size)
- #to_a(bits = 8, type = :unsigned) ⇒ Object
- #to_s ⇒ Object
- #view(offset = nil, length = nil) ⇒ Object
Methods included from Native::Wrapper
Constructor Details
#initialize(size, bits = 8) ⇒ Buffer
Returns a new instance of Buffer.
23 24 25 26 27 28 29 |
# File 'opal/stdlib/buffer.rb', line 23 def initialize(size, bits = 8) if native?(size) super(size) else super(`new ArrayBuffer(size * (bits / 8))`) end end |
Class Method Details
.name_for(bits, type) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'opal/stdlib/buffer.rb', line 14 def self.name_for(bits, type) part = case type when :unsigned then 'Uint' when :signed then 'Int' when :float then 'Float' end "#{part}#{bits}" end |
.supported? ⇒ Boolean
10 11 12 |
# File 'opal/stdlib/buffer.rb', line 10 def self.supported? !$$[:ArrayBuffer].nil? end |
Instance Method Details
#length ⇒ Object Also known as: size
31 32 33 |
# File 'opal/stdlib/buffer.rb', line 31 def length `#{@native}.byteLength` end |
#to_a(bits = 8, type = :unsigned) ⇒ Object
35 36 37 |
# File 'opal/stdlib/buffer.rb', line 35 def to_a(bits = 8, type = :unsigned) Array.new(self, bits, type) end |
#to_s ⇒ Object
43 44 45 |
# File 'opal/stdlib/buffer.rb', line 43 def to_s to_a.to_a.pack('c*') end |