Class: Buffer::View

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Native::Wrapper

included, #to_n

Constructor Details

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

Returns a new instance of View



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

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



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

def buffer
  @buffer
end

#offsetObject (readonly)

Returns the value of attribute offset



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

def offset
  @offset
end

Class Method Details

.supported?Boolean

Returns:



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

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

Instance Method Details

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



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

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



92
93
94
# File 'opal/stdlib/buffer/view.rb', line 92

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

#get_float64(offset, little = false) ⇒ Object



100
101
102
# File 'opal/stdlib/buffer/view.rb', line 100

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

#get_int16(offset, little = false) ⇒ Object



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

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

#get_int32(offset, little = false) ⇒ Object



76
77
78
# File 'opal/stdlib/buffer/view.rb', line 76

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

#get_int8(offset, little = false) ⇒ Object



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

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

#get_uint16(offset, little = false) ⇒ Object



68
69
70
# File 'opal/stdlib/buffer/view.rb', line 68

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

#get_uint32(offset, little = false) ⇒ Object



84
85
86
# File 'opal/stdlib/buffer/view.rb', line 84

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

#get_uint8(offset, little = false) ⇒ Object



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

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

#lengthObject Also known as: size



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

def length
  `#{@native}.byteLength`
end

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



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

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



96
97
98
# File 'opal/stdlib/buffer/view.rb', line 96

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

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



104
105
106
# File 'opal/stdlib/buffer/view.rb', line 104

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

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



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

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

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



80
81
82
# File 'opal/stdlib/buffer/view.rb', line 80

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

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



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

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

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



72
73
74
# File 'opal/stdlib/buffer/view.rb', line 72

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

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



88
89
90
# File 'opal/stdlib/buffer/view.rb', line 88

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

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



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

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