Skip to content

Commit b289b95

Browse files
committed
Add session methods to output events
1 parent eee4b87 commit b289b95

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/nibbler/session.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,34 @@ def parse_string(*args, timestamp: Time.now.to_i)
3939
end
4040
alias parse_s parse_string
4141

42+
# Parse some string input. Can be single or multiple bytes. Returns an event struct
43+
# eg single '40'
44+
# eg multiple '4050'
45+
# @param [Array<Integer>] bytes
46+
# @param [Object] timestamp A timestamp to store with the messages that result
47+
# @return [Event]
48+
def parse_string_to_event(*args, timestamp: Time.now.to_i)
49+
integers = Util::Conversion.strings_to_numeric_bytes(*args)
50+
parse_to_event(*integers, timestamp: timestamp)
51+
end
52+
4253
# Parse the given integer bytes and add them to the buffer.
4354
# @param [Array<Integer>] bytes
4455
# @param [Object] timestamp A timestamp to store with the messages that result
4556
# @return [Array<Object>]
4657
def parse(*bytes, timestamp: Time.now.to_i)
58+
parse_to_event(*bytes, timestamp: timestamp).report.messages
59+
end
60+
61+
# Parse the given integer bytes, add them to the buffer and return an event struct
62+
# @param [Array<Integer>] bytes
63+
# @param [Object] timestamp A timestamp to store with the messages that result
64+
# @return [Event]
65+
def parse_to_event(*bytes, timestamp: Time.now.to_i)
4766
parser_report = @parser.process(*bytes)
48-
@events << Event.new(parser_report, timestamp)
49-
parser_report.messages
67+
event = Event.new(parser_report, timestamp)
68+
@events << event
69+
event
5070
end
5171
end
5272
end

spec/session_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
describe Nibbler::Session do
66
let!(:session) { Nibbler::Session.new }
77

8+
describe '#parse_string_to_event' do
9+
end
10+
11+
describe '#parse_to_event' do
12+
end
13+
814
describe '#parse_string' do
915
let(:returned_messages) { session.parse_s(*input) }
1016
let(:returned_message) { returned_messages.first }

0 commit comments

Comments
 (0)