uv-rays 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcf2dd4cbeb83a76c6f218cc4c0ccc55ed05d755
4
- data.tar.gz: 2f1e98b94414be0f86f22b5297b38e45c9cc8882
3
+ metadata.gz: 83d541d90fa45a28696168870b4c5933354ba968
4
+ data.tar.gz: 29b0fe26514eb737aa11b912e3549eb509a789b3
5
5
  SHA512:
6
- metadata.gz: cc24a2d715a2325b8f531bd4823cf73e7ed9e54dcb6ee31eeacc830b3af1df2cd70b4280e68409a61507e5fbfcbf6aa9576e9d59b56f9afe9f07939550759f78
7
- data.tar.gz: 3be2b91df14b7be0b7fbe7f2c50c08fbaf45ff56e586b50db736a87a12c02c411e27f21852ac2baa0aaee3e7df296cb03d981043c9f7178e6fd509dbd75b1a69
6
+ metadata.gz: 049c4c400a002bfa9c1829b1be76c7db3b77d6b7f1052b6327a0c0deab667b2cd654220bb440039af1c580ffde5e72cf79da7a4462e0099c50cbf02baa9c31b2
7
+ data.tar.gz: 0f13601f2a8e5f3892bd5632a234478bb12f6b3d368531c4512417fcdd5e5532c0ba315396ecc6ff29783e9723b1ddc29cd2e15314fb9ca43444035cb74ae0a8
@@ -19,7 +19,6 @@ module UV
19
19
  @verbose = options[:verbose] if @size_limit
20
20
  @encoding = options[:encoding] || DEFAULT_ENCODING
21
21
 
22
- raise ArgumentError, 'no indicator provided' unless @indicator
23
22
  raise ArgumentError, 'no callback provided' unless @callback
24
23
 
25
24
  reset
@@ -46,16 +45,23 @@ module UV
46
45
  loop do
47
46
  found = false
48
47
 
49
- check = @input.partition(@indicator)
50
- break unless check[1].length > 0
48
+ last = if @indicator
49
+ check = @input.partition(@indicator)
50
+ break unless check[1].length > 0
51
+
52
+ check[2]
53
+ else
54
+ @input
55
+ end
51
56
 
52
- last = check[2]
53
57
  result = @callback.call(last)
58
+
54
59
  if result
55
60
  found = true
56
61
 
57
62
  # Check for multi-byte indicator edge case
58
- if result.is_a? Fixnum
63
+ case result
64
+ when Integer, Fixnum
59
65
  entities << last[0...result]
60
66
  @input = last[result..-1]
61
67
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UV
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
@@ -104,4 +104,26 @@ describe UV::AbstractTokenizer do
104
104
  expect(result).to eq(['Star', '1234'])
105
105
  expect(@buffer.flush).to eq('56') # as we've indicated a message length of 4
106
106
  end
107
+
108
+ it "should work with messages that don't have an indicator" do
109
+ # i.e. there is a header that defines message length
110
+ msg1 = "\x0612345\x081234567\x031"
111
+
112
+ @buffer = UV::AbstractTokenizer.new({
113
+ callback: lambda { |data|
114
+ len = data.bytes[0]
115
+ if data.length >= len
116
+ len
117
+ else
118
+ false
119
+ end
120
+ },
121
+ size_limit: 10,
122
+ encoding: "ASCII-8BIT"
123
+ })
124
+
125
+ result = @buffer.extract(msg1)
126
+ expect(result).to eq(["\x0612345", "\x081234567"])
127
+ expect(@buffer.flush).to eq("\x031") # as we've indicated a message length of 3
128
+ end
107
129
  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: 2.0.1
4
+ version: 2.0.2
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-10-20 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libuv