Permalink
Browse files

Support deeper nesting of multi bulks

  • Loading branch information...
1 parent b0a52ba commit 1ef107c01ad91dba003b4c4262109d87b40c19a5 @pietern pietern committed Dec 2, 2011
Showing with 13 additions and 5 deletions.
  1. +7 −4 lib/hiredis/ruby/reader.rb
  2. +5 −0 test/reader_test.rb
  3. +1 −1 vendor/hiredis
@@ -32,14 +32,17 @@ class Task
method_index[?*] = :process_multi_bulk_reply
METHOD_INDEX = method_index.freeze
- attr_accessor :parent, :child
+ attr_reader :parent
+ attr_reader :depth
attr_accessor :multi_bulk
def initialize(buffer, parent = nil, depth = 0)
- @buffer, @parent = buffer, parent
+ @buffer, @parent, @depth = buffer, parent, depth
+ end
- # Require 3 nested tasks
- @child = Task.new(@buffer, self, depth + 1) if depth < 2
+ # Note: task depth is not checked.
+ def child
+ @child ||= Task.new(@buffer, self, depth + 1)
end
def root
View
@@ -70,6 +70,11 @@ def test_nested_multi_bulk
@reader.feed("*2\r\n*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n$1\r\n!\r\n")
assert_equal [["hello", "world"], "!"], @reader.gets
end
+
+ def test_nested_multi_bulk_redux
+ @reader.feed("*2\r\n*2\r\n*1\r\n$5\r\nhello\r\n$5\r\nworld\r\n$1\r\n!\r\n")
+ assert_equal [[["hello"], "world"], "!"], @reader.gets
+ end
end
if defined?(Hiredis::Ruby::Reader)

0 comments on commit 1ef107c

Please sign in to comment.