Class: Nibbler::Session
- Inherits:
-
Object
- Object
- Nibbler::Session
- Extended by:
- Forwardable
- Defined in:
- lib/nibbler/session.rb
Overview
A parser session
Holds on to data that is not relevant to the parser between calls. For instance, past messages, rejected bytes
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#rejected ⇒ Object
readonly
Returns the value of attribute rejected.
Instance Method Summary collapse
- #all_messages ⇒ Array<Object>
-
#buffer_s ⇒ String
(also: #buffer_hex)
The buffer as a single hex string.
-
#clear_buffer ⇒ Object
Clear the parser buffer.
-
#clear_messages ⇒ Object
Clear the message log.
-
#initialize(options = {}) ⇒ Session
constructor
A new instance of Session.
-
#parse(*args) ⇒ Array<Object>, Hash
Parse some input.
-
#use_timestamps ⇒ Object
Convert messages to hashes with timestamps.
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
25 26 27 28 29 30 |
# File 'lib/nibbler/session.rb', line 25 def initialize( = {}) @timestamps = [:timestamps] || false @callbacks, @processed, @rejected, @messages = [], [], [], [] @library = MessageLibrary.adapter([:message_lib]) @parser = Parser.new(@library) end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
12 13 14 |
# File 'lib/nibbler/session.rb', line 12 def @messages end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
12 13 14 |
# File 'lib/nibbler/session.rb', line 12 def processed @processed end |
#rejected ⇒ Object (readonly)
Returns the value of attribute rejected.
12 13 14 |
# File 'lib/nibbler/session.rb', line 12 def rejected @rejected end |
Instance Method Details
#all_messages ⇒ Array<Object>
33 34 35 |
# File 'lib/nibbler/session.rb', line 33 def @messages | @fragmented_messages end |
#buffer_s ⇒ String Also known as: buffer_hex
The buffer as a single hex string
39 40 41 |
# File 'lib/nibbler/session.rb', line 39 def buffer_s buffer.join end |
#clear_buffer ⇒ Object
Clear the parser buffer
45 46 47 |
# File 'lib/nibbler/session.rb', line 45 def clear_buffer buffer.clear end |
#clear_messages ⇒ Object
Clear the message log
50 51 52 |
# File 'lib/nibbler/session.rb', line 50 def @messages.clear end |
#parse(*args) ⇒ Array<Object>, Hash
Parse some input
72 73 74 75 76 77 78 79 80 |
# File 'lib/nibbler/session.rb', line 72 def parse(*args) = args.last.kind_of?(Hash) ? args.pop : {} = [:timestamp] if !.nil? result = process(args) log(result, ) end |
#use_timestamps ⇒ Object
Convert messages to hashes with timestamps
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nibbler/session.rb', line 55 def if !@timestamps @messages = @messages.map do || { :messages => , :timestamp => nil } end @timestamps = true end end |