Class: BinData::Skip

Inherits:
BasePrimitive show all
Extended by:
DSLMixin
Defined in:
lib/bindata/skip.rb

Overview

Skip will skip over bytes from the input stream. If the stream is not seekable, then the bytes are consumed and discarded.

When writing, skip will write the appropriate number of zero bytes.

require 'bindata'

class A < BinData::Record
  skip length: 5
  string :a, read_length: 5
end

obj = A.read("abcdefghij")
obj.a #=> "fghij"

class B < BinData::Record
  skip do
    string read_length: 2, assert: 'ef'
  end
  string :s, read_length: 5
end

obj = B.read("abcdefghij")
obj.s #=> "efghi"

Parameters

Skip objects accept all the params that BinData::BasePrimitive does, as well as the following:

:length

The number of bytes to skip.

:to_abs_offset

Skips to the given absolute offset.

:until_valid

Skips until a given byte pattern is matched. This parameter contains a type that will raise a BinData::ValidityError unless an acceptable byte sequence is found. The type is represented by a Symbol, or if the type is to have params passed to it, then it should be provided as [type_symbol, hash_params].

Defined Under Namespace

Modules: SkipLengthPlugin, SkipToAbsOffsetPlugin, SkipUntilValidPlugin

Instance Attribute Summary

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods included from DSLMixin

dsl_parser, method_missing, to_ary, to_str

Methods inherited from BasePrimitive

#<=>, #assign, bit_aligned, #clear?, #do_num_bytes, #do_read, #do_read_with_hook, #do_write, #eql?, #hash, #initialize_instance, #method_missing, #respond_to_missing?, #snapshot, #value, #value=

Methods included from TraceHook

#turn_off_tracing, #turn_on_tracing

Methods inherited from Base

#==, #=~, #abs_offset, arg_processor, auto_call_delayed_io, bindata_name, #clear, #debug_name, #eval_parameter, #get_parameter, #has_parameter?, #initialize_instance, #initialize_with_warning, #inspect, #lazy_evaluator, #new, #num_bytes, #pretty_print, #read, read, register_subclasses, #rel_offset, #safe_respond_to?, #to_binary_s, #to_hex, #to_s, unregister_self, #write

Methods included from AcceptedParametersPlugin

#accepted_parameters, #default_parameters, #mandatory_parameters, #mutually_exclusive_parameters, #optional_parameters

Methods included from RegisterNamePlugin

included

Methods included from Framework

#assign, #bit_aligned?, #clear?, #debug_name_of, #offset_of, #snapshot

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BinData::BasePrimitive

Instance Method Details

#initialize_shared_instanceObject



56
57
58
59
60
61
# File 'lib/bindata/skip.rb', line 56

def initialize_shared_instance
  extend SkipLengthPlugin      if has_parameter?(:length)
  extend SkipToAbsOffsetPlugin if has_parameter?(:to_abs_offset)
  extend SkipUntilValidPlugin  if has_parameter?(:until_valid)
  super
end