Class: PacketGen::Header::Base::Binding Private

Inherits:
Object
  • Object
show all
Defined in:
lib/packetgen/header/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Simple class to handle a header association

Instance Method Summary collapse

Instance Method Details

#check?(fields) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check fields responds to binding

Parameters:

  • fields (BinStruct::Struct)

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/packetgen/header/base.rb', line 29

def check?(fields)
  case self[:value]
  when Proc
    self[:value].call(fields.send(self[:key]))
  else
    fields.send(self[:key]) == self[:value]
  end
end

#set(fields) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Set fields field to binding value

Parameters:

  • fields (BinStruct::Struct)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/packetgen/header/base.rb', line 41

def set(fields)
  case self[:value]
  when Proc
    fields.send(:"#{self[:key]}=", self[:value].call(nil))
  else
    attr = if self[:key].to_s.end_with?('?')
             self[:key].to_s[0..-2]
           else
             self[:key]
           end
    fields.send(:"#{attr}=", self[:value])
  end
end