class FormatParser::DPXParser::Binstr

A teeny-tiny rewording of depix (rubygems.org/gems/depix)

Constants

TO_LITTLE_ENDIAN

Public Class Methods

array(field_name, nested_struct_descriptor_or_symbol, n_items, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 46
def self.array(field_name, nested_struct_descriptor_or_symbol, n_items, **_kwargs)
  if nested_struct_descriptor_or_symbol.is_a?(Symbol)
    n_items.times do |i|
      public_send(nested_struct_descriptor_or_symbol, '%s_%d' % [field_name, i])
    end
  else
    n_items.times do |i|
      fields << ['%s_%d' % [field_name, i], nested_struct_descriptor_or_symbol]
    end
  end
end
blanking(field_name, length, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 42
def self.blanking(field_name, length, **_kwargs)
  fields << [field_name, Capture.new('x%d' % length, length)]
end
char(field_name, length, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 22
def self.char(field_name, length, **_kwargs)
  fields << [field_name, Capture.new('Z%d' % length, length)]
end
cleanup(v) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 62
def self.cleanup(v)
  case v
  when String
    v.scrub
  when Float
    v.nan? ? nil : v
  else
    v
  end
end
fields() click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 17
def self.fields
  @fields ||= []
  @fields
end
inner(field_name, nested_struct_descriptor, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 58
def self.inner(field_name, nested_struct_descriptor, **_kwargs)
  fields << [field_name, nested_struct_descriptor]
end
r32(field_name, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 38
def self.r32(field_name, **_kwargs)
  fields << [field_name, Capture.new('e', 4)]
end
read_and_unpack(io) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 73
def self.read_and_unpack(io)
  fields.each_with_object({}) do |(field_name, capture), h|
    maybe_value = cleanup(capture.read_and_unpack(io))
    h[field_name] = maybe_value unless maybe_value.nil?
  end
end
u16(field_name, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 30
def self.u16(field_name, **_kwargs)
  fields << [field_name, Capture.new('n', 2)]
end
u32(field_name, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 34
def self.u32(field_name, **_kwargs)
  fields << [field_name, Capture.new('N', 4)]
end
u8(field_name, **_kwargs) click to toggle source
# File lib/parsers/dpx_parser/dpx_structs.rb, line 26
def self.u8(field_name, **_kwargs)
  fields << [field_name, Capture.new('c', 1)]
end