Sha256: cfd4c0f528bca9900a6d7c453393507f02b7781a0cb268670f15ebc63bf67d5f

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "bindata/base_primitive"

module BinData
  # 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 <tt>:length</tt> 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"
  #
  # == Parameters
  #
  # Skip objects accept all the params that BinData::BasePrimitive
  # does, as well as the following:
  #
  # <tt>:length</tt>:: The number of bytes to skip.
  #
  class Skip < BinData::BasePrimitive
    register(self.name, self)

    mandatory_parameter :length

    #---------------
    private

    def value_to_binary_string(val)
      len = eval_parameter(:length)
      "\000" * len
    end

    def read_and_return_value(io)
      len = eval_parameter(:length)
      io.seekbytes(len)
      ""
    end

    def sensible_default
      ""
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bindata-1.1.0 lib/bindata/skip.rb