Class: LibSL::VariableBlockCollection
- Inherits:
-
FixedBlockCollection
- Object
- FixedBlockCollection
- LibSL::VariableBlockCollection
- Defined in:
- lib/packet.rb
Instance Attribute Summary
Attributes inherited from FixedBlockCollection
Instance Method Summary collapse
- #add ⇒ Object
- #decode(data) ⇒ Object
- #encode ⇒ Object
-
#initialize(structure) ⇒ VariableBlockCollection
constructor
A new instance of VariableBlockCollection.
- #length ⇒ Object
Methods inherited from FixedBlockCollection
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
#add ⇒ Object
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 |
#encode ⇒ Object
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 |
#length ⇒ Object
251 252 253 |
# File 'lib/packet.rb', line 251 def length() @blocks.length end |