Module: BinData::CheckOrAdjustOffsetMixin

Included in:
Base
Defined in:
lib/bindata/offset.rb

Overview

Parameters

Parameters may be provided at initialisation to control the behaviour of an object. These parameters are:

:check_offset

Raise an error if the current IO offset doesn’t meet this criteria. A boolean return indicates success or failure. Any other return is compared to the current offset. The variable offset is made available to any lambda assigned to this parameter. This parameter is only checked before reading.

:adjust_offset

Ensures that the current IO offset is at this position before reading. This is like :check_offset, except that it will adjust the IO offset instead of raising an error.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



20
21
22
23
# File 'lib/bindata/offset.rb', line 20

def self.included(base) #:nodoc:
  base.optional_parameters :check_offset, :adjust_offset
  base.mutually_exclusive_parameters :check_offset, :adjust_offset
end

Instance Method Details

#do_read_with_adjust_offset(io) ⇒ Object

:nodoc:



34
35
36
37
# File 'lib/bindata/offset.rb', line 34

def do_read_with_adjust_offset(io) #:nodoc:
  adjust_offset(io)
  do_read_without_adjust_offset(io)
end

#do_read_with_check_offset(io) ⇒ Object

Ideally these two methods should be protected, but Ruby 1.9.2 requires them to be public. see redmine.ruby-lang.org/issues/show/2375



29
30
31
32
# File 'lib/bindata/offset.rb', line 29

def do_read_with_check_offset(io) #:nodoc:
  check_offset(io)
  do_read_without_check_offset(io)
end