class BinaryParser::LoopList
Public Class Methods
new(definition, abstract_binary, parent_scope)
click to toggle source
# File lib/binary_parser/loop_list.rb, line 5 def initialize(definition, abstract_binary, parent_scope) list, rest_binary = [], abstract_binary while rest_binary.bit_length > 0 template = definition.klass.new(rest_binary, parent_scope) if template.structure_bit_length == 0 raise ParsingError, "0 bit-length repetition happens. This means infinite loop." end rest_binary = rest_binary.sub(:bit_index => template.structure_bit_length) list << template end @list = list end
Public Instance Methods
[](index)
click to toggle source
# File lib/binary_parser/loop_list.rb, line 22 def [](index) unless @list[index] raise BadManipulationError, "Index is out of bounds. List size is #{@list.size}." + "You accessed list[#{index}]." end return @list[index] end
content_description()
click to toggle source
String that describes this object.
# File lib/binary_parser/loop_list.rb, line 37 def content_description "list with #{size} elements" end
each(&block)
click to toggle source
# File lib/binary_parser/loop_list.rb, line 18 def each(&block) @list.each(&block) end
show(recursively=false, out=STDOUT, depth=0)
click to toggle source
Print all elements’ information. Args:
recursively => Whether print recursively or not. Default is false. out => Print target. Default is STDOUT.
# File lib/binary_parser/loop_list.rb, line 45 def show(recursively=false, out=STDOUT, depth=0) @list.each_with_index do |element, i| out.puts sprintf(" " * (depth * 2) + "%-5s::%20s Len: %s Cont: %s", "[#{i}]", element.class.name ? element.class.name.split("::").last : "AnonymouseTemplate", element.structure_bit_length, element.content_description) element.show(true, out, depth + 1) if recursively end end
size()
click to toggle source
# File lib/binary_parser/loop_list.rb, line 30 def size return @list.size end
Also aliased as: length