Module: BinData

Defined in:
lib/bindata/io.rb,
lib/bindata/dsl.rb,
lib/bindata/int.rb,
lib/bindata/base.rb,
lib/bindata/bits.rb,
lib/bindata/lazy.rb,
lib/bindata/rest.rb,
lib/bindata/skip.rb,
lib/bindata/array.rb,
lib/bindata/float.rb,
lib/bindata/trace.rb,
lib/bindata/choice.rb,
lib/bindata/offset.rb,
lib/bindata/params.rb,
lib/bindata/record.rb,
lib/bindata/string.rb,
lib/bindata/struct.rb,
lib/bindata/stringz.rb,
lib/bindata/version.rb,
lib/bindata/registry.rb,
lib/bindata/sanitize.rb,
lib/bindata/alignment.rb,
lib/bindata/primitive.rb,
lib/bindata/deprecated.rb,
lib/bindata/base_primitive.rb,
lib/bindata/count_bytes_remaining.rb

Defined Under Namespace

Modules: AcceptedParametersMixin, BitAligned, BitField, CheckOrAdjustOffsetMixin, DSLMixin, FloatingPoint, Int Classes: Array, Base, BaseArgExtractor, BasePrimitive, Choice, CountBytesRemaining, DoubleBe, DoubleLe, FloatBe, FloatLe, IO, Int8, LazyEvaluator, Primitive, Record, RecordArgExtractor, Registry, Rest, ResumeByteAlignment, SanitizedBigEndian, SanitizedChoices, SanitizedField, SanitizedFields, SanitizedLittleEndian, SanitizedParameter, SanitizedParameters, SanitizedPrototype, Skip, String, Stringz, Struct, Tracer, Uint8, UnRegisteredTypeError, ValidityError

Constant Summary collapse

VERSION =
"1.5.0"
RegisteredClasses =

A singleton registry of all registered classes.

Registry.new

Class Method Summary collapse

Class Method Details

.const_missing_with_bits(name) ⇒ Object Also known as: const_missing



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bindata/bits.rb', line 69

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

.const_missing_with_int(name) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/bindata/int.rb', line 162

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

.trace_message {|@tracer| ... } ⇒ Object

:nodoc:

Yields:

  • (@tracer)


41
42
43
# File 'lib/bindata/trace.rb', line 41

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

.trace_reading(io = STDERR, &block) ⇒ Object

Turn on trace information when reading a BinData object. If block is given then the tracing only occurs for that block. This is useful for debugging a BinData declaration.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bindata/trace.rb', line 26

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