uv-rays 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e980250a6d02103acb85079de12729af1c77cb5
4
- data.tar.gz: ebda36f5eec3a50be714255a5c08946faadee54c
3
+ metadata.gz: 4455f4c45f8835bff0c2dd2f0213d229d7d5a567
4
+ data.tar.gz: 9b575ec7380f6e3c525caa0f752327babb930a6f
5
5
  SHA512:
6
- metadata.gz: e64d927cb58e16370b425c29b23f8a13c045930a6a5ac2f0aeb372cbb6c45de2205267e6c979ce2b54f5ae440ba9b19a7a703cc3d1e664bb1bb7bcbc51f480b9
7
- data.tar.gz: bafad5da678f13d052d18978d8d058f8ac8cf770f6955056bc91a2fce042f6126a747c370613f75e417d9e16a7640b27d9d5aa0a9ce3ab6d4c7d5672a55842ed
6
+ metadata.gz: 65317d8a548b648e7ef33ffa2437116dcdcbe0407ab3317ec925ad2a48bba484c1dcdd35e56f5c893108ade3b671f92a68e60f4b86d9bd4d55a705425b237f25
7
+ data.tar.gz: cc6e8a3abf8c5aede9cf23aab253590d0c14a8a19f9672a787090853766f9bdd66527fb56c66272cc4935a14a99682a5600e137a588271e1082eb2714af86a87
@@ -39,47 +39,30 @@ module UV
39
39
  data.force_encoding(@encoding)
40
40
  @input << data
41
41
 
42
- messages = @input.split(@indicator, -1)
43
- if messages.length > 1
44
- messages.shift # the first item will always be junk
45
- last = messages.pop # the last item may require buffering
46
-
47
- entities = []
48
- messages.each do |msg|
49
- result = @callback.call(msg)
50
- entities << msg[0...result] if result
51
- end
42
+ entities = []
43
+
44
+ loop do
45
+ found = false
46
+
47
+ check = @input.partition(@indicator)
48
+ break unless check[1].length > 0
52
49
 
53
- # Check if buffering is required
50
+ last = check[2]
54
51
  result = @callback.call(last)
55
52
  if result
53
+ found = true
54
+
56
55
  # Check for multi-byte indicator edge case
57
56
  if result.is_a? Fixnum
58
57
  entities << last[0...result]
59
58
  @input = last[result..-1]
60
59
  else
61
- reset
62
60
  entities << last
61
+ reset
63
62
  end
64
- else
65
- # This will work with a regex
66
- index = if messages.last.nil?
67
- 0
68
- else
69
- # Possible that rindex will not find a match
70
- check = @input[0...-last.length].rindex(messages.last)
71
- if check.nil?
72
- 0
73
- else
74
- check + messages.last.length
75
- end
76
- end
77
- indicator_val = @input[index...-last.length]
78
- @input = indicator_val + last
79
63
  end
80
- else
81
- @input = messages.pop
82
- entities = messages
64
+
65
+ break if not found
83
66
  end
84
67
 
85
68
  # Check to see if the buffer has exceeded capacity, if we're imposing a limit
@@ -118,8 +101,7 @@ module UV
118
101
 
119
102
 
120
103
  def reset
121
- @input = ''
122
- @input.force_encoding(@encoding)
104
+ @input = ''.force_encoding(@encoding)
123
105
  end
124
106
  end
125
107
  end
@@ -1,3 +1,3 @@
1
1
  module UV
2
- VERSION = '1.3.5'
2
+ VERSION = '1.3.6'
3
3
  end
@@ -93,4 +93,15 @@ describe UV::AbstractTokenizer do
93
93
  result = @buffer.extract('bcd')
94
94
  expect(result).to eq(['abcd'])
95
95
  end
96
+
97
+ it "should work where the indicator is part of the message" do
98
+ # i.e. We are looking for \x02\x06\xLEN\x00\x00\x02\x06\x00\xEND
99
+ # Where the indicator may appear as part of the message body
100
+
101
+ msg1 = "StartStartStart123456"
102
+
103
+ result = @buffer.extract(msg1)
104
+ expect(result).to eq(['Star', '1234'])
105
+ expect(@buffer.flush).to eq('56') # as we've indicated a message length of 4
106
+ end
96
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uv-rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libuv