Class: LibSL::FixedBlockCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/packet.rb

Direct Known Subclasses

VariableBlockCollection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, structure) ⇒ FixedBlockCollection



214
215
216
217
218
# File 'lib/packet.rb', line 214

def initialize(size, structure)
  @size = size
  @blocks = []
  @size.times{@blocks << Block.new(structure)}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



213
214
215
# File 'lib/packet.rb', line 213

def blocks
  @blocks
end

Instance Method Details

#[](index) ⇒ Object



224
225
226
227
# File 'lib/packet.rb', line 224

def [](index)
  throw "Index out of range: #{index} is not in [0, #{length - 1}]" if index < 0 or index >= length
  @blocks[index]
end

#decode(data) ⇒ Object



233
234
235
236
# File 'lib/packet.rb', line 233

def decode(data)
  @blocks.each{ |block| data = block.decode(data) }
  data
end

#each(&block) ⇒ Object



229
230
231
# File 'lib/packet.rb', line 229

def each(&block)
  @blocks.each{|block| yield block}
end

#encodeObject



238
239
240
241
242
# File 'lib/packet.rb', line 238

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

#lengthObject



220
221
222
# File 'lib/packet.rb', line 220

def length()
  @size
end