Skip to content

Commit

Permalink
Merge pull request #34 from nviennot/master
Browse files Browse the repository at this point in the history
Fix framing issue in the encode_body() method
  • Loading branch information
michaelklishin committed Sep 17, 2013
2 parents 43a3c3c + dbedd03 commit b3a68ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/amq/protocol/client.rb
Expand Up @@ -177,7 +177,7 @@ def self.encode_body(body, channel, frame_size)
body.force_encoding("ASCII-8BIT") if RUBY_VERSION.to_f >= 1.9

array = Array.new
while body
while body && !body.empty?
payload, body = body[0, limit], body[limit, body.length - limit]
array << BodyFrame.new(payload, channel)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/amq/protocol/method_spec.rb
Expand Up @@ -34,6 +34,14 @@ module Protocol
body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
end
end

context 'when the body fits perfectly in a single frame' do
it 'encodes a body into a single BodyFrame' do
body_frames = Method.encode_body('*' * 131064, 1, 131072)
body_frames.first.payload.should == '*' * 131064
body_frames.should have(1).item
end
end
end
end
end
Expand Down

0 comments on commit b3a68ff

Please sign in to comment.