Class: Pio::SetVlan

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pio/set_vlan.rb

Overview

An action to modify the VLAN related fields of a packet.

Direct Known Subclasses

SetVlanPriority, SetVlanVid

Class Method Summary collapse

Class Method Details

.def_format(field_name, action_type) ⇒ Object

rubocop:disable MethodLength



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pio/set_vlan.rb', line 10

def self.def_format(field_name, action_type)
  str = %(
    class Format < BinData::Record
      endian :big

      uint16 :type, value: #{action_type}
      uint16 :message_length, value: 8
      uint16 :#{field_name}
      uint16 :padding
      hide :padding
    end
  )
  module_eval str
  module_eval "def_delegators :@format, :#{field_name}"
end

.read(raw_data) ⇒ Object

rubocop:enable MethodLength



27
28
29
30
31
# File 'lib/pio/set_vlan.rb', line 27

def self.read(raw_data)
  set_vlan = allocate
  set_vlan.instance_variable_set :@format, const_get(:Format).read(raw_data)
  set_vlan
end