Class: Buffer::View

Inherits:
Object show all
Includes:
Native
Defined in:
opal/stdlib/buffer/view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Native

call, convert, included, is_a?, proc, #to_n, try_convert

Constructor Details

#initialize(buffer, offset = nil, length = nil) ⇒ View

Returns a new instance of View



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'opal/stdlib/buffer/view.rb', line 12

def initialize(buffer, offset = nil, length = nil)
  if native?(buffer)
    super(buffer)
  elsif offset && length
    super(`new DataView(#{buffer.to_n}, #{offset.to_n}, #{length.to_n})`)
  elsif offset
    super(`new DataView(#{buffer.to_n}, #{offset.to_n})`)
  else
    super(`new DataView(#{buffer.to_n})`)
  end

  @buffer = buffer
  @offset = offset
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer



10
11
12
# File 'opal/stdlib/buffer/view.rb', line 10

def buffer
  @buffer
end

#offsetObject (readonly)

Returns the value of attribute offset



10
11
12
# File 'opal/stdlib/buffer/view.rb', line 10

def offset
  @offset
end

Class Method Details

.supported?Boolean

Returns:



6
7
8
# File 'opal/stdlib/buffer/view.rb', line 6

def self.supported?
  not $$[:DataView].nil?
end

Instance Method Details

#get(offset, bits = 8, type = :unsigned, little = false) ⇒ Object Also known as: []



33
34
35
# File 'opal/stdlib/buffer/view.rb', line 33

def get(offset, bits = 8, type = :unsigned, little = false)
  `#@native["get" + #{Buffer.name_for bits, type}](offset, little)`
end

#get_float32(offset, little = false) ⇒ Object



63
# File 'opal/stdlib/buffer/view.rb', line 63

def get_float32(offset, little = false); `#@native.getFloat32(offset, little)`; end

#get_float64(offset, little = false) ⇒ Object



66
# File 'opal/stdlib/buffer/view.rb', line 66

def get_float64(offset, little = false); `#@native.getFloat64(offset, little)`; end

#get_int16(offset, little = false) ⇒ Object



51
# File 'opal/stdlib/buffer/view.rb', line 51

def get_int16(offset, little = false); `#@native.getInt16(offset, little)`; end

#get_int32(offset, little = false) ⇒ Object



57
# File 'opal/stdlib/buffer/view.rb', line 57

def get_int32(offset, little = false); `#@native.getInt32(offset, little)`; end

#get_int8(offset, little = false) ⇒ Object



45
# File 'opal/stdlib/buffer/view.rb', line 45

def get_int8(offset, little = false); `#@native.getInt8(offset, little)`; end

#get_uint16(offset, little = false) ⇒ Object



54
# File 'opal/stdlib/buffer/view.rb', line 54

def get_uint16(offset, little = false); `#@native.getUint16(offset, little)`; end

#get_uint32(offset, little = false) ⇒ Object



60
# File 'opal/stdlib/buffer/view.rb', line 60

def get_uint32(offset, little = false); `#@native.getUint32(offset, little)`; end

#get_uint8(offset, little = false) ⇒ Object



48
# File 'opal/stdlib/buffer/view.rb', line 48

def get_uint8(offset, little = false); `#@native.getUint8(offset, little)`; end

#lengthObject Also known as: size



27
28
29
# File 'opal/stdlib/buffer/view.rb', line 27

def length
  `#@native.byteLength`
end

#set(offset, value, bits = 8, type = :unsigned, little = false) ⇒ Object Also known as: []=



39
40
41
# File 'opal/stdlib/buffer/view.rb', line 39

def set(offset, value, bits = 8, type = :unsigned, little = false)
  `#@native["set" + #{Buffer.name_for bits, type}](offset, value, little)`
end

#set_float32(offset, value, little = false) ⇒ Object



64
# File 'opal/stdlib/buffer/view.rb', line 64

def set_float32(offset, value, little = false); `#@native.setFloat32(offset, value, little)`; end

#set_float64(offset, value, little = false) ⇒ Object



67
# File 'opal/stdlib/buffer/view.rb', line 67

def set_float64(offset, value, little = false); `#@native.setFloat64(offset, value, little)`; end

#set_int16(offset, value, little = false) ⇒ Object



52
# File 'opal/stdlib/buffer/view.rb', line 52

def set_int16(offset, value, little = false); `#@native.setInt16(offset, value, little)`; end

#set_int32(offset, value, little = false) ⇒ Object



58
# File 'opal/stdlib/buffer/view.rb', line 58

def set_int32(offset, value, little = false); `#@native.setInt32(offset, value, little)`; end

#set_int8(offset, value, little = false) ⇒ Object



46
# File 'opal/stdlib/buffer/view.rb', line 46

def set_int8(offset, value, little = false); `#@native.setInt8(offset, value, little)`; end

#set_uint16(offset, value, little = false) ⇒ Object



55
# File 'opal/stdlib/buffer/view.rb', line 55

def set_uint16(offset, value, little = false); `#@native.setUint16(offset, value, little)`; end

#set_uint32(offset, value, little = false) ⇒ Object



61
# File 'opal/stdlib/buffer/view.rb', line 61

def set_uint32(offset, value, little = false); `#@native.setUint32(offset, value, little)`; end

#set_uint8(offset, value, little = false) ⇒ Object



49
# File 'opal/stdlib/buffer/view.rb', line 49

def set_uint8(offset, value, little = false); `#@native.setUint8(offset, value, little)`; end