Class: Pio::SetEthAddr

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

Overview

An action to modify the source/destination Ethernet address of a packet.

Direct Known Subclasses

SetEthDstAddr, SetEthSrcAddr

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mac_address) ⇒ SetEthAddr



38
39
40
# File 'lib/pio/set_eth_addr.rb', line 38

def initialize(mac_address)
  @format = self.class.const_get(:Format).new(mac_address: mac_address)
end

Class Method Details

.def_format(action_type) ⇒ Object

rubocop:disable MethodLength



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

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

      uint16 :type, value: #{action_type}
      uint16 :message_length, value: 16
      mac_address :mac_address
      uint48 :padding
      hide :padding
    end
  )
  module_eval str
end

.read(raw_data) ⇒ Object

rubocop:enable MethodLength



25
26
27
28
29
30
# File 'lib/pio/set_eth_addr.rb', line 25

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