Module: BinData
- Defined in:
- lib/bindata.rb,
lib/bindata/io.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/params.rb,
lib/bindata/record.rb,
lib/bindata/string.rb,
lib/bindata/struct.rb,
lib/bindata/stringz.rb,
lib/bindata/wrapper.rb,
lib/bindata/registry.rb,
lib/bindata/sanitize.rb,
lib/bindata/primitive.rb,
lib/bindata/deprecated.rb,
lib/bindata/base_primitive.rb
Overview
BinData
A declarative way to read and write structured binary data.
A full reference manual is available online at bindata.rubyforge.org.
License
BinData is released under the same license as Ruby.
Copyright © 2007 - 2009 Dion Mendel.
Defined Under Namespace
Modules: BitField, FloatingPoint, Int Classes: AcceptedParameters, Array, Base, BasePrimitive, Choice, DoubleBe, DoubleLe, FloatBe, FloatLe, IO, Int8, LazyEvaluator, MultiValue, Primitive, Record, Registry, Rest, SanitizedChoices, SanitizedEndian, SanitizedField, SanitizedFields, SanitizedParameter, SanitizedParameters, SanitizedPrototype, Sanitizer, SingleValue, Skip, String, Stringz, Struct, Tracer, Uint8, UnknownTypeError, ValidityError, Wrapper
Constant Summary collapse
Class Method Summary collapse
- .const_missing_with_bits(name) ⇒ Object (also: const_missing)
- .const_missing_with_int(name) ⇒ Object
-
.trace_message {|@tracer| ... } ⇒ Object
:nodoc:.
-
.trace_reading(io = STDERR, &block) ⇒ Object
Turn on trace information when reading a BinData object.
Class Method Details
.const_missing_with_bits(name) ⇒ Object Also known as: const_missing
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bindata/bits.rb', line 68 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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/bindata/int.rb', line 189 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:
29 30 31 |
# File 'lib/bindata/trace.rb', line 29 def (&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.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bindata/trace.rb', line 18 def trace_reading(io = STDERR, &block) @tracer = Tracer.new(io) if block_given? begin block.call ensure @tracer = nil end end end |