Class: LibSL::VariableBlockCollection

Inherits:
FixedBlockCollection show all
Defined in:
lib/packet.rb

Instance Attribute Summary

Attributes inherited from FixedBlockCollection

#blocks

Instance Method Summary collapse

Methods inherited from FixedBlockCollection

#[], #each

Constructor Details

#initialize(structure) ⇒ VariableBlockCollection

Returns a new instance of VariableBlockCollection.



246
247
248
249
# File 'lib/packet.rb', line 246

def initialize(structure)
  @structure = structure
  @blocks = []
end

Instance Method Details

#addObject



255
256
257
258
# File 'lib/packet.rb', line 255

def add()
  @blocks << Block.new(@structure)
  @blocks.last
end

#decode(data) ⇒ Object



260
261
262
263
264
# File 'lib/packet.rb', line 260

def decode(data)
  size, data = LLU8.decode(data)
  size.value.times{ data = add.decode(data) }
  data
end

#encodeObject



266
267
268
269
270
# File 'lib/packet.rb', line 266

def encode()
  data = LLU8.new(length).encode
  @blocks.each{ |block| data += block.encode }
  data
end

#lengthObject



251
252
253
# File 'lib/packet.rb', line 251

def length()
  @blocks.length
end