Permalink
Browse files

Add decoding of basic.cancel.

  • Loading branch information...
1 parent 9b0063c commit 448486cd83921cfc8a4ee2b6b33be8891a7e5886 @eliaslevy eliaslevy committed May 18, 2012
Showing with 23 additions and 0 deletions.
  1. +15 −0 lib/amq/protocol/client.rb
  2. +8 −0 spec/amq/protocol/basic_spec.rb
View
15 lib/amq/protocol/client.rb
@@ -1613,6 +1613,21 @@ def self.encode(channel, consumer_tag, nowait)
buffer << [bit_buffer].pack(PACK_CHAR)
MethodFrame.new(buffer, channel)
end
+
+ # @return
+ def self.decode(data)
+ offset = 0
+ length = data[offset, 1].unpack(PACK_CHAR).first
+ offset += 1
+ consumer_tag = data[offset, length]
+ offset += length
+ self.new(consumer_tag)
+ end
+
+ attr_reader :consumer_tag
+ def initialize(consumer_tag)
+ @consumer_tag = consumer_tag
+ end
end
class CancelOk < Protocol::Method
View
8 spec/amq/protocol/basic_spec.rb
@@ -138,6 +138,14 @@ class Basic
method_frame.channel.should == 1
end
end
+
+ describe '.decode' do
+ subject do
+ CancelOk.decode("\x03foo\x01")
+ end
+
+ its(:consumer_tag) { should == 'foo' }
+ end
end
describe CancelOk do

0 comments on commit 448486c

Please sign in to comment.