Class: Mu::Pcap::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/diy/parser/mu/pcap/reader.rb,
lib/diy/parser/mu/pcap/reader/http_family.rb

Direct Known Subclasses

HttpFamily

Defined Under Namespace

Classes: HttpFamily

Constant Summary collapse

FAMILY_TO_READER =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pcap2scenarioObject

Returns the value of attribute pcap2scenario.



9
10
11
# File 'lib/diy/parser/mu/pcap/reader.rb', line 9

def pcap2scenario
  @pcap2scenario
end

Class Method Details

.reader(family) ⇒ Object

Returns a reader instance of specified family. Returns nil when family is :none.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/diy/parser/mu/pcap/reader.rb', line 14

def self.reader family
    if family == :none
        return nil
    end

    if klass = FAMILY_TO_READER[family]
        return klass.new
    end

    raise ArgumentError, "Unknown protocol family: '#{family}'"
end

Instance Method Details

#familyObject

Returns family name

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/diy/parser/mu/pcap/reader.rb', line 27

def family
    raise NotImplementedError
end

#read_message(bytes, state = nil) ⇒ Object

Returns next complete message from byte stream or nil.



42
43
44
# File 'lib/diy/parser/mu/pcap/reader.rb', line 42

def read_message bytes, state=nil
    read_message! bytes.dup, state
end

#read_message!(bytes, state = nil) ⇒ Object

Mutating form of read_message. Removes a complete message from input stream. Returns the message or nil if there. is not a complete message.



49
50
51
52
53
54
55
# File 'lib/diy/parser/mu/pcap/reader.rb', line 49

def read_message! bytes, state=nil
    begin
        do_read_message! bytes, state
    rescue
        nil
    end
end

#record_write(bytes, state = nil) ⇒ Object

Notify parser of bytes written. Parser may update state to serve as a hint for subsequent reads.



33
34
35
36
37
38
39
# File 'lib/diy/parser/mu/pcap/reader.rb', line 33

def record_write bytes, state=nil
    begin
        do_record_write bytes, state
    rescue
        nil
    end
end