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: []



30
31
32
# File 'opal/stdlib/buffer/view.rb', line 30

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



90
91
92
# File 'opal/stdlib/buffer/view.rb', line 90

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

#get_float64(offset, little = false) ⇒ Object



98
99
100
# File 'opal/stdlib/buffer/view.rb', line 98

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

#get_int16(offset, little = false) ⇒ Object



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

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

#get_int32(offset, little = false) ⇒ Object



74
75
76
# File 'opal/stdlib/buffer/view.rb', line 74

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

#get_int8(offset, little = false) ⇒ Object



42
43
44
# File 'opal/stdlib/buffer/view.rb', line 42

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

#get_uint16(offset, little = false) ⇒ Object



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

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

#get_uint32(offset, little = false) ⇒ Object



82
83
84
# File 'opal/stdlib/buffer/view.rb', line 82

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

#get_uint8(offset, little = false) ⇒ Object



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

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: []=



36
37
38
# File 'opal/stdlib/buffer/view.rb', line 36

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



94
95
96
# File 'opal/stdlib/buffer/view.rb', line 94

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

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



102
103
104
# File 'opal/stdlib/buffer/view.rb', line 102

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

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



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

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

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



78
79
80
# File 'opal/stdlib/buffer/view.rb', line 78

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

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



46
47
48
# 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



70
71
72
# File 'opal/stdlib/buffer/view.rb', line 70

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

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



86
87
88
# File 'opal/stdlib/buffer/view.rb', line 86

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

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



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

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