class PacketGen::Packet
Public Instance Methods
to_h()
click to toggle source
# 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()
click to toggle source
# File lib/pcap2json/packetgen_extensions.rb, line 18 def to_json Oj.dump(self.to_h) end