Class: PacketGen::Packet
- Inherits:
-
Object
- Object
- PacketGen::Packet
- Defined in:
- lib/pcap2json/packetgen_extensions.rb
Instance Method Summary collapse
Instance Method Details
#to_h ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pcap2json/packetgen_extensions.rb', line 2 def to_h data = Hash.new data["time"] = Time.now.to_i self.headers.each do |header| data[header.protocol_name.downcase] = header.to_h rescue # => error header.fields.reject { |field| field == :body }.each do |field| data[field.to_s] = header.send(field) end end unless self.body.nil? data["payload"] = self.body.to_s.encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''}) end data end |
#to_json ⇒ Object
18 19 20 |
# File 'lib/pcap2json/packetgen_extensions.rb', line 18 def to_json Oj.dump(self.to_h) end |