module BinData

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, Choice].each { |traced| traced.turn_on_tracing }
  if block_given?
    begin
      block.call
    ensure
      [BasePrimitive, Choice].each { |traced| traced.turn_off_tracing }
      @tracer = nil
    end
  end
end