Class: WWMD::VSStubs::VSSparseArray

Inherits:
Object
  • Object
show all
Includes:
WWMD::VSStubHelpers
Defined in:
lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WWMD::VSStubHelpers

#opcode, #to_sym

Methods included from WWMD::ViewStateUtils

#deserialize_type, #dlog, #magic?, #next_type, #offset, #putd, #read, #read_7bit_encoded_int, #read_double, #read_int, #read_int32, #read_raw_byte, #read_short, #read_string, #serialize_type, #slog, #throw, #write_7bit_encoded_int, #write_double, #write_int, #write_int32, #write_short

Constructor Details

#initialize(typeref, typeval, size, elems) ⇒ VSSparseArray

Returns a new instance of VSSparseArray.



11
12
13
14
15
16
17
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 11

def initialize(typeref,typeval,size,elems)
  @typeref = typeref
  @typeval = typeval
  @size = size
  @elems = elems
  @value = []
end

Instance Attribute Details

#elemsObject (readonly)

Returns the value of attribute elems.



9
10
11
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 9

def elems
  @elems
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 8

def size
  @size
end

#typerefObject (readonly)

Returns the value of attribute typeref.



6
7
8
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 6

def typeref
  @typeref
end

#typevalObject (readonly)

Returns the value of attribute typeval.



7
8
9
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 7

def typeval
  @typeval
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 5

def value
  @value
end

Instance Method Details

#add(idx, obj) ⇒ Object



19
20
21
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 19

def add(idx,obj)
  @value[idx] = obj
end

#serializeObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 23

def serialize
  stack = super
  stack << self.write_7bit_encoded_int(self.size)
  stack << self.write_7bit_encoded_int(self.elems)                             
  self.value.each_index do |i|
    next if self.value[i].nil?
    stack << self.write_7bit_encoded_int(i)
    stack << self.value[i].serialize
  end
  return stack
end

#to_xmlObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wwmd/viewstate/vs_stubs/vs_sparse_array.rb', line 35

def to_xml
  xml = super
  siz = REXML::Element.new("Size")
  siz.add_text(self.size.to_s)
  ele = REXML::Element.new("Elements")
  ele.add_text(self.elems.to_s)
  xml.add_element(siz)
  xml.add_element(ele)
  self.value.each_index do |i|
    next if self.value[i].nil?
    pair = REXML::Element.new("Pair")
    idx = REXML::Element.new("Index")
    idx.add_text(i.to_s)
    val = REXML::Element.new("Value")
    val.add_element(value[i].to_xml)
    pair.add_element(idx)
    pair.add_element(val)
    xml.add_element(pair)
  end
  xml
end