Class: Buffer
- Includes:
 - Native::Wrapper
 
- Defined in:
 - opal/stdlib/buffer.rb,
opal/stdlib/buffer/view.rb,
opal/stdlib/buffer/array.rb 
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.
      21 22 23 24 25 26 27  | 
    
      # File 'opal/stdlib/buffer.rb', line 21 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
      12 13 14 15 16 17 18 19  | 
    
      # File 'opal/stdlib/buffer.rb', line 12 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
      8 9 10  | 
    
      # File 'opal/stdlib/buffer.rb', line 8 def self.supported? !$$[:ArrayBuffer].nil? end  | 
  
Instance Method Details
#length ⇒ Object Also known as: size
      29 30 31  | 
    
      # File 'opal/stdlib/buffer.rb', line 29 def length `#{@native}.byteLength` end  | 
  
#to_a(bits = 8, type = :unsigned) ⇒ Object
      33 34 35  | 
    
      # File 'opal/stdlib/buffer.rb', line 33 def to_a(bits = 8, type = :unsigned) Array.new(self, bits, type) end  | 
  
#to_s ⇒ Object
      41 42 43  | 
    
      # File 'opal/stdlib/buffer.rb', line 41 def to_s to_a.to_a.pack('c*') end  |