Class: PacketViaDMEM::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/packet_via_dmem/packet.rb

Direct Known Subclasses

Received, Sent

Defined Under Namespace

Modules: Type Classes: NoPayload

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



5
6
7
# File 'lib/packet_via_dmem/packet.rb', line 5

def header
  @header
end

#originalObject (readonly)

Returns the value of attribute original.



5
6
7
# File 'lib/packet_via_dmem/packet.rb', line 5

def original
  @original
end

#packetObject (readonly)

Returns the value of attribute packet.



5
6
7
# File 'lib/packet_via_dmem/packet.rb', line 5

def packet
  @packet
end

#poppedObject (readonly)

Returns the value of attribute popped.



5
6
7
# File 'lib/packet_via_dmem/packet.rb', line 5

def popped
  @popped
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/packet_via_dmem/packet.rb', line 5

def type
  @type
end

Instance Method Details

#pop(bytes) ⇒ Object



7
8
9
# File 'lib/packet_via_dmem/packet.rb', line 7

def pop bytes
  @original[bytes..-1]
end

#pretty(packet) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/packet_via_dmem/packet.rb', line 23

def pretty packet
  offset = -16
  out    = ''
  packet.each_slice(16) do |slice|
    hex, str = [], []
    slice.each_slice(8) do |subslice|
      hex << subslice
      str << subslice.inject(' ') do |r, s|
        int = s.to_i(16)
        r + ((int > 31 and int < 127) ? int.chr : '.')
      end
    end
    hex << [] if not hex[1]
    hex.each do |h|
      (8-h.size).times { h << '  ' }
    end
    out << "%04x  %s  %s   %s \n" % [offset+=16, hex[0].join(' '), hex[1].to_a.join(' '), str.join('  ')]
  end
  out
end

#pretty_originalObject



19
20
21
# File 'lib/packet_via_dmem/packet.rb', line 19

def pretty_original
  pretty @original
end

#pretty_packetObject



15
16
17
# File 'lib/packet_via_dmem/packet.rb', line 15

def pretty_packet
  pretty @packet
end

#to_sObject



11
12
13
# File 'lib/packet_via_dmem/packet.rb', line 11

def to_s
  pretty_packet
end