Module: PacketGen::PcapNG::Block
- Included in:
- EPB, IDB, SHB, SPB, UnknownBlock
- Defined in:
- lib/packetgen/pcapng/block.rb
Overview
Mixin module to declare some common methods for block classes.
Instance Method Summary collapse
-
#has_options? ⇒ Boolean
Has this block option?.
-
#pad_field(*fields) ⇒ void
Pad given field to 32 bit boundary, if needed.
-
#recalc_block_len ⇒ void
Calculate block length and update :block_len and block_len2 fields.
Instance Method Details
#has_options? ⇒ Boolean
Has this block option?
9 10 11 |
# File 'lib/packetgen/pcapng/block.rb', line 9 def self[:options].size > 0 end |
#pad_field(*fields) ⇒ void
This method returns an undefined value.
Pad given field to 32 bit boundary, if needed
23 24 25 26 27 28 29 |
# File 'lib/packetgen/pcapng/block.rb', line 23 def pad_field(*fields) fields.each do |field| unless self[field].size % 4 == 0 self[field] << "\x00" * (4 - (self[field].size % 4)) end end end |
#recalc_block_len ⇒ void
This method returns an undefined value.
Calculate block length and update :block_len and block_len2 fields
15 16 17 18 |
# File 'lib/packetgen/pcapng/block.rb', line 15 def recalc_block_len len = to_a.map(&:to_s).join.size self[:block_len].value = self[:block_len2].value = len end |