module BinData

def const_missing_with_bits(name)

def const_missing_with_bits(name)
  name = name.to_s
  mappings = {
    /^Bit(\d+)$/ => :big,
    /^Bit(\d+)le$/ => :little
  }
  mappings.each_pair do |regex, endian|
    if regex =~ name
      nbits = $1.to_i
      return BitField.define_class(nbits, endian)
    end
  end
  const_missing_without_bits(name)
end

def const_missing_with_int(name)

def const_missing_with_int(name)
  name = name.to_s
  mappings = {
    /^Uint(\d+)be$/ => [:big, :unsigned],
    /^Uint(\d+)le$/ => [:little, :unsigned],
    /^Int(\d+)be$/ => [:big, :signed],
    /^Int(\d+)le$/ => [:little, :signed],
  }
  mappings.each_pair do |regex, args|
    if regex =~ name
      nbits = $1.to_i
      if (nbits % 8).zero?
        return Int.define_class(nbits, *args)
      end
    end
  end
  const_missing_without_int(name)
end

def trace_message(&block) #:nodoc:

:nodoc:
def trace_message(&block) #:nodoc:
  yield @tracer if @tracer
end

def trace_reading(io = STDERR, &block)

This is useful for debugging a BinData declaration.
If +block+ is given then the tracing only occurs for that block.
Turn on trace information when reading a BinData object.
def trace_reading(io = STDERR, &block)
  @tracer = Tracer.new(io)
  BasePrimitive.turn_on_tracing
  Choice.turn_on_tracing
  if block_given?
    begin
      block.call
    ensure
      BasePrimitive.turn_off_tracing
      Choice.turn_off_tracing
      @tracer = nil
    end
  end
end