class BinData::Skip

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 until_valid: [:string, {read_length: 2, assert: "ef"} ]
  string :b, read_length: 5
end

obj = B.read("abcdefghij")
obj.b #=> "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 untils 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].

Public Instance Methods

initialize_shared_instance() click to toggle source
# File lib/bindata/skip.rb, line 50
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

Private Instance Methods

read_and_return_value(io) click to toggle source
# File lib/bindata/skip.rb, line 69
def read_and_return_value(io)
  len = skip_length
  if len < 0
    raise ValidityError, "#{debug_name} attempted to seek backwards by #{len.abs} bytes"
  end

  io.seekbytes(len)
  ""
end
sensible_default() click to toggle source
# File lib/bindata/skip.rb, line 79
def sensible_default
  ""
end
value_to_binary_string(val) click to toggle source
# File lib/bindata/skip.rb, line 60
def value_to_binary_string(val)
  len = skip_length
  if len < 0
    raise ValidityError, "#{debug_name} attempted to seek backwards by #{len.abs} bytes"
  end

  "\000" * skip_length
end