Class: Packetman::Clause

Inherits:
Object
  • Object
show all
Includes:
ConfigMethods
Defined in:
lib/packetman/clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigMethods

#config, included, #protocols

Constructor Details

#initialize(search, mask, start_bit) ⇒ Clause

Returns a new instance of Clause.



7
8
9
10
11
# File 'lib/packetman/clause.rb', line 7

def initialize(search, mask, start_bit)
  self.search = search
  self.mask = mask
  self.start_bit = start_bit
end

Instance Attribute Details

#maskObject

Returns the value of attribute mask.



5
6
7
# File 'lib/packetman/clause.rb', line 5

def mask
  @mask
end

#searchObject

Returns the value of attribute search.



5
6
7
# File 'lib/packetman/clause.rb', line 5

def search
  @search
end

#start_bitObject

Returns the value of attribute start_bit.



5
6
7
# File 'lib/packetman/clause.rb', line 5

def start_bit
  @start_bit
end

Instance Method Details

#data_addressObject

Full address of the query data (eg. ‘tcp`)



23
24
25
# File 'lib/packetman/clause.rb', line 23

def data_address
  "#{config.transport}[#{start_byte}:#{num_bytes}]"
end

#num_bytesObject



18
19
20
# File 'lib/packetman/clause.rb', line 18

def num_bytes
  Filter.bit_length(search)/8
end

#start_byteObject

Address of first byte



14
15
16
# File 'lib/packetman/clause.rb', line 14

def start_byte
  [config.payload_query, (config.offset_bits + start_bit)/8].compact.join(' + ')
end

#to_sObject

The whole filter clause fully assembled



28
29
30
# File 'lib/packetman/clause.rb', line 28

def to_s
  "#{data_address} & #{mask} = #{search}"
end