lib/packetgen/pcapng/spb.rb in packetgen-3.3.3 vs lib/packetgen/pcapng/spb.rb in packetgen-4.0.0
- old
+ new
@@ -27,14 +27,14 @@
attr_accessor :interface
# @!attribute orig_len
# 32-bit original length
# @return [Integer]
- define_field_before :block_len2, :orig_len, Types::Int32, default: 0
+ define_attr_before :block_len2, :orig_len, BinStruct::Int32, default: 0
# @!attribute data
- # @return [Types::String]
- define_field_before :block_len2, :data, Types::String
+ # @return [BinStruct::String]
+ define_attr_before :block_len2, :data, BinStruct::String
# @param [Hash] options
# @option options [:little, :big] :endian set block endianness
# @option options [Integer] :type
# @option options [Integer] :block_len block total length
@@ -43,12 +43,10 @@
# @option options [::String] :data
# @option options [::String] :options
# @option options [Integer] :block_len2 block total length
def initialize(options={})
super
- endianness(options[:endian] || :little)
- recalc_block_len
self.type = options[:type] || PcapNG::SPB_TYPE.to_i
end
# Has this block options?
# @return [false]
@@ -62,25 +60,25 @@
# @return [self]
def read(str_or_io)
io = to_io(str_or_io)
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)
+ self[:type].read(io.read(4))
+ self[:block_len].read(io.read(4))
+ self[:orig_len].read(io.read(4))
data_len = compute_data_len
- self[:data].read io.read(data_len)
+ self[:data].read(io.read(data_len))
remove_padding(io, data_len)
read_blocklen2_and_check(io)
self.type ||= PcapNG::IDB_TYPE.to_i
self
end
# Return the object as a String
# @return [String]
def to_s
- pad_field :data
+ pad_field(:data)
recalc_block_len
super
end
private