lib/packetgen/pcapng/spb.rb in packetgen-2.6.0 vs lib/packetgen/pcapng/spb.rb in packetgen-2.7.0

- old
+ new

@@ -5,24 +5,22 @@ # frozen_string_literal: true module PacketGen module PcapNG - # {SPB} represents a Section Simple Packet Block (SPB) of a pcapng file. # # == Pcapng::SPB Definition # Int32 :type Default: 0x00000003 # Int32 :block_len # Int32 :orig_len # String :data # Int32 :block_len2 # @author Sylvain Daubert class SPB < Block - # Minimum SPB size - MIN_SIZE = 4*4 + MIN_SIZE = 4 * 4 # @return [:little, :big] attr_accessor :endian # @return [IPB] attr_accessor :interface @@ -49,37 +47,45 @@ set_endianness(options[:endian] || :little) recalc_block_len self.type = options[:type] || PcapNG::SPB_TYPE.to_i end - # Has this block option? + # Has this block options? # @return [false] - def has_options? + # @since 2.7.0 + def options? false end + # @deprecated Use {#options?} instead. + # @return [false] + def has_options? + Deprecation.deprecated(self.class, __method__, 'options?') + options? + end + # Reads a String or a IO to populate the object # @param [::String,IO] str_or_io # @return [self] def read(str_or_io) - if str_or_io.respond_to? :read - io = str_or_io - else - io = StringIO.new(force_binary(str_or_io.to_s)) - end + io = if str_or_io.respond_to? :read + str_or_io + else + StringIO.new(force_binary(str_or_io.to_s)) + end return self if io.eof? self[:type].read io.read(4) self[:block_len].read io.read(4) self[:orig_len].read io.read(4) # Take care of IDB snaplen # CAUTION: snaplen == 0 -> no capture limit - if interface and interface.snaplen.to_i > 0 - data_len = [self[:orig_len].to_i, interface.snaplen.to_i].min - else - data_len = self[:orig_len].to_i - end + data_len = if interface && (interface.snaplen.to_i > 0) + [self[:orig_len].to_i, interface.snaplen.to_i].min + else + self[:orig_len].to_i + end data_pad_len = (4 - (data_len % 4)) % 4 self[:data].read io.read(data_len) io.read data_pad_len self[:block_len2].read io.read(4) @@ -93,10 +99,8 @@ def to_s pad_field :data recalc_block_len super end - end - end end